Skip to content

Library to render dynamic content templates. Written in V. Syntax similar to mustache.

License

Notifications You must be signed in to change notification settings

pastilhas/wustache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wustache

is a lightweight and efficient templating engine written in V. It provides a fast way to render templates with dynamic content. Simple as 1, 2, 3 — (1) load the template, (2) write the context as JSON, and (3) execute render. It is safe by default, but you can make it less picky.

Features

  • Simple to use API, lightweight and fast;
  • Variables — with HTML escaping by default;
  • Conditional sections;
  • Nested context and iteration over arrays;
  • Error handling.

Installation

Install the V language and run v install pastilhas.wustache

Usage

template := '{{greet}}, {{name}}. {{#admin}}You are admin.{{/admin}}'
obj := '{ "greet": "Hello", "name": "John", "admin": true }'

res := render(template, obj)!
println(res) // 'Hello, John. You are admin.'

Interpolation

Hello, {{name}}.

Welcome, {{user.name}}. You have {{user.unread}} messages.

<div id="login_form">
  {{&login_form}}
</div>

Sections

{{#never_true}} This will never be seen! {{/never_true}}

{{#is_logged}} Welcome back! {{/is_logged}}

{{#items}}
  {{$.name}}: {{$.price}}
{{/items}}

Repeats content {0, 1, n} times

  • 0, if falsy value — false, empty string, 'false', '0', '0.0', empty array, empty map;
  • 1, if truthy value — true, non-empty string, non-empty map;
  • n, for n-sized array — each iteration, the value is mapped to $

Inverted

{{^is_logged}}
  {{&login_form}}
{{/is_logged}}
{{#is_logged}}
  Hello, {{user.name}}!
{{/is_logged}}

Repeats content {0, 1} times — 0, if truthy, else 1;

Mustache compatibility

Planned

  • Variables
  • Dotted names
  • Implicit iterator (with modifications)
  • Sections
  • Inverted sections
  • Partials
  • Set delimiter

Not planned

  • Lambdas
  • Comments
  • Dynamic partials
  • Blocks
  • Parents
  • Dynamic parents

License

wustache is released under the MIT License. See the LICENSE file for details.

About

Library to render dynamic content templates. Written in V. Syntax similar to mustache.

Topics

Resources

License

Stars

Watchers

Forks

Languages