mandira

package module
v0.0.0-...-56c8423 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2014 License: MIT Imports: 13 Imported by: 7

README

મંદિર Mandira

Build Status Godoc license

Mandira is a language agnostic logic-light templating system desigend to be usable on server and client side applications. Mandira strives to be easy to learn, easy to implement, efficient to render, comfortable for designers, tollerable for developers, suitable for non-HTML documents, as flexible as necessary (but no more so), and consistent in style and rendering.

It is heavily influenced by Mustache, Tempo, Django Templates and Jinja2

Mandira templates should look familiar to users of other templates. It is called "logic-light" because it allows some forms of conditional logic while avoiding the complexity of more sophisticated features. It strives for both simplicity and ergonomics, but makes concessions to each where appropriate.

Sample

A simple Mandira template:

{{#greetings}}
  {{?if greeting|len > 4}}
    {{greeting}}
  {{?else}}
    {{greeting}}, {{name}} ({{age}})
  {{/if}}
{{/greetings}}

Given the following context:

{
  "name": "Jason",
  "greetings": [
    {"greeting": "Hello"},
    {"greeting": "Hi"}
  ],
  "age": 30
}

Will produce the following:

Hello
Hi, Jason (30)

Status

Currently, Mandira has a specification and a beta quality reference implementation in Go. It is currently the template language in use on my personal website. I intend to get feedback on it and live with it a while and see what works and what doesn't.

If you are interested in this language and the ideas behind it, read my Logic-less Template Redux blog post or ping @jmoiron on twitter. The name Mandira is sanskrit for "Temple", and the script used in the title is Mandira in Gujarati.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFilter

func AddFilter(filter interface{}, name ...string)

func BoolEval

func BoolEval(oper string, lhs, rhs interface{}, contexts []interface{}) bool

func CompEval

func CompEval(oper string, lhs, rhs interface{}, contexts []interface{}) bool

func Date

func Date(arg interface{}, format string) interface{}

func DivisibleBy

func DivisibleBy(base_, by_ interface{}) bool

func Eval

func Eval(expr interface{}, contexts []interface{}) (interface{}, error)

run eval for something which is a cond or a conditional

func Format

func Format(arg interface{}, format string) interface{}

func GetFilter

func GetFilter(name string) interface{}

Return a filter (or nil)

func Index

func Index(arg interface{}, idx_ interface{}) interface{}

Return the index of the argument at arg I

func IsTemplate

func IsTemplate(path string) bool

func Join

func Join(arg interface{}, joiner string) string

func Len

func Len(arg interface{}) int

Return the length of the argument, or 0 if that is not a valid action

func Render

func Render(data string, context ...interface{}) string

func RenderFile

func RenderFile(filename string, context ...interface{}) string

func RenderFileInLayout

func RenderFileInLayout(filename string, layoutFile string, context ...interface{}) string

func RenderInLayout

func RenderInLayout(data string, layoutData string, context ...interface{}) string

Types

type Loader

type Loader struct {
	Path    string
	Preload bool
	Loaded  bool
	// contains filtered or unexported fields
}

func NewLoader

func NewLoader(path string, preload bool) *Loader

func (*Loader) Add

func (l *Loader) Add(path string, template *Template)

If you want to add a template sourced from elsewhere to the loader, you can do it here and continue to use the loader.

func (*Loader) Cache

func (l *Loader) Cache() map[string]*Template

Return the internal cache

func (*Loader) Get

func (l *Loader) Get(path string) (*Template, error)

func (*Loader) MustGet

func (l *Loader) MustGet(path string) *Template

func (*Loader) Refresh

func (l *Loader) Refresh() error

type Template

type Template struct {
	// contains filtered or unexported fields
}

func ParseFile

func ParseFile(filename string) (*Template, error)

func ParseString

func ParseString(data string) (*Template, error)

func (*Template) Render

func (tmpl *Template) Render(context ...interface{}) string

func (*Template) RenderInLayout

func (tmpl *Template) RenderInLayout(layout *Template, context ...interface{}) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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