templar

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 11 Imported by: 0

README

Templar

Templar Command Line Tool v2.1.0
Templar Library v0.2.1

Command line templating system written in Go. Though the initial idea was written in BASH. And that was cool; but that version had serious limitations as well. Go to the rescue!

Features

  • Mustache template system
  • POSIX style variable exansion of $VAR and ${VAR} type references in template via the prior Bash based system. See extra/templar.bash.
  • Multiple data sources available and planned
    • System environment variables
    • .env file variables
      • Automatic loading of local .env file variables
      • Option to exclude automatic loading of a local .env file
    • INI file data
    • JSON file data
    • YAML file data
    • TOML file data
    • XML file data?
    • CSV file data?
    • SQLite database query?

Usage

$ templar template.mustache
The contents of the template with {{placeholders}}
populated from the system environment and (if present)
the environment settings of a .env file.

Example

INI Files
  • Global variables are treated like normal ENV file variables.

  • Whitespace before and after keys and values is ignored.

  • Quoted values have their quotes removed but leading and trailing whitespace is preserved within the bounds of the quotes. Whitespace outside the quotes is ignored.

  • You can separate key and value with a equal sign (standard) or a colon (used in some implementations).

  • Global and DEFAULT section key/value pairs can be accessed directly {{key}} or via {{DEFAULT.key}} references.

  • To access section variables within a template the section is prepended to the sections keys. Example:

    [MySection]
    key = value
    

    can be accessed in a template as {{MySection.key}}. Sections and keys are case sensitive. Though that is counter to the spec it is the norm on POSIX systems.

Installation

  1. Download a release from https://github.com/runeimp/templar/releases and copy the binary to a directory in your PATH

Test Suite

Test uses Go's normal unit testing tools at this time.

Test Coverage: 78.1%

It was 83.9% but I added more stuff to test. 👼

ToDo

  • Add MVVM features so that the data input can processed into a ViewModel to limit or manipulate the input in simple ways for the View (template)
  • Complete the data input options
  • Optimize the data processing. Make it more memory friendly on constrained systems and allow for say referencing (for instance) a terabyte sized CSV file for data input.

Documentation

Index

Constants

View Source
const (
	// Name denotes the library name
	Name = "Templar"

	// Version denotes the library version
	Version = "0.2.0"
)

* LIB CONSTANTS

View Source
const (
	DebugOff   = 0
	DebugError = 1
	DebugWarn  = 2
	DebugInfo  = 3
	DebugLog   = 4
)

* CONSTANTS

Variables

View Source
var Data struct {
	INIFile  []string
	JSONFile []string
	Template string
}

Data is a collection for all external data

View Source
var (
	Debug = DebugWarn
)

* VARIABLES

Functions

func InitData

func InitData(checkDotEnv bool, files ...string) (err error)

InitData initializes the template environment with external data

func ParseENV added in v0.2.0

func ParseENV(file string) (err error)

ParseENV loads ENV file data into the dataProvider

func ParseINI

func ParseINI(file string) (err error)

ParseINI loads INI file data into the dataProvider

func ParseJSON

func ParseJSON(file string) (err error)

ParseJSON loads JSON file data into the dataProvider

func ParseTOML added in v0.2.0

func ParseTOML(file string) (err error)

ParseTOML loads TOML file data into the dataProvider

func ParseYAML added in v0.2.0

func ParseYAML(file string) (err error)

ParseYAML loads YAML file data into the dataProvider

func Reinitialize

func Reinitialize(debug int)

Reinitialize resets the dataProvider

func Render

func Render(template string) (output string, err error)

Render handles template rendering

func RenderToFile

func RenderToFile(filename, template string) (output string, err error)

RenderToFile handles rendering templates to file

Types

This section is empty.

Directories

Path Synopsis
cmd
templar
PACKAGE
PACKAGE

Jump to

Keyboard shortcuts

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