mkpage

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

README

This is prototypical at this stage...

mkpage

An experimental template engine with an embedded markdown processor. mkpage (pronounced "make page") is a simple command line tool which accepts key value pairs and applies them to a Golang text/template. The key side of a pair corresponds to the template keys in the template document (e.g. {{.pageContent}} is represented by the key pageContent). The value side of the pair can be a string, filename or URL for a data source. Here's a simple example of a form letter

    Date: {{.now}}

    Hello {{.name -}},
    
    Forecast:

    {{range .weather.data.text}}
       + {{ . }}
    {{end}}

    Thank you

    {{.signature}}

Render the template above (i.e. myformletter.template) would be accomplished from the following data sources--

  • "now" and "name" are strings
  • "weather" comes from a URL of JSON content
  • "signature" comes from a file in our local disc

That would be expressed on the command line as follows

    mkpage "now=string:$(date)" \
        "name=string:Little Frieda" \
        "weather=http://forecast.weather.gov/MapClick.php?lat=13.4712&lon=144.7496&FcstType=json" \
        signature=testdata/signature.txt \
        testdata/myformletter.template

Since we are leveraging Go's text/template the template itself can be more than a simple substitution.

Template blocks

The Go text templates support defining blocks and rendering them in conjuction with a main template. This is also supported by mkpage. For each template encountered on the command line it is added to an array of templates passed and parse by the text template package. This is then executed and output rendered by mkpage.

    mkpage "content=string:Hello World" testdata/page.tmpl testdata/header.tmpl testdata/footer.tmpl

Here is what page.tmpl would look like

    {{template "header" . }}

        {{.content}}

    {{template "footer" . }}

The header and footer are then defined in their own template files (though they also could be combined into one).

header.tmpl

    {{define "header"}}This is the document header{{end}}

footer.tmpl

    {{define "footer"}}This is the footer{{end}}

In this example the output would look like

    This is the document header

        Hello World

    This is the footer

Options

In additional to populating a template with values from data sources mkpage also includes the blackfriday markdown processor. Using the "-m" option any a filename referenced with the extension of ".md" will run through the markdown process for being put into the template. This allows you to easily generate pages and website from markdown files using simple templates.

  • -m, -markdown - use a markdown processor when reading ".md" files
  • -h, -help - get command line help
  • -v, -version - show mkpage version number
  • -l, -license - show mkpage license information

Documentation

Overview

mkpage is a thought experiment in a light weight template and markdown processor

@author R. S. Doiel, <rsdoiel@gmail.com>

Copyright (c) 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const (
	Version = "v0.0.3"
)

Variables

This section is empty.

Functions

func MakePage

func MakePage(wr io.Writer, tmpl *template.Template, keyValues map[string]string, useMarkdownProcessor bool) error

MakePage applies the provided data to the template provided and renders to writer and returns an error if something goes wrong

func ResolveData

func ResolveData(data map[string]string, useMarkdownProcessor bool) (map[string]interface{}, error)

ResolveData takes a data map and reads in the files and URL sources as needed turning the data into strings to be applied to the template.

Types

This section is empty.

Directories

Path Synopsis
cmds
mkpage
mkpage is a thought experiment in a light weight template and markdown processor @author R. S. Doiel, <rsdoiel@gmail.com> Copyright (c) 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.
mkpage is a thought experiment in a light weight template and markdown processor @author R. S. Doiel, <rsdoiel@gmail.com> Copyright (c) 2016, R. S. Doiel All rights not granted herein are expressly reserved by R. S. Doiel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL