- Notifications
You must be signed in to change notification settings - Fork8
fenekku/moustachu
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Moustachu is a(N im)plementation ofMustache (get it?). Mustache is "logic-less templating".
In code
import moustachuvar tmplate="""Hello {{name}}You have just won {{value}} dollars!{{#in_ca}}Well, {{taxed_value}} dollars, after taxes.{{/in_ca}}"""var c :Context=newContext()c["name"]="Chris"c["value"]=10000c["taxed_value"]=10000- (10000*0.4)c["in_ca"]=trueechorender(tmplate, c)
For other mustache examples look at thespecs directory. For other moustachu-specific examples see thetests folder.
For the formal description of the mustache format, please visitmustache(5). Ignore the sections on "lambdas" and "set delimeters".
Not mentioned in the formal description (but mentioned in the spec code), the spec also supports using a dot. as an "implicit iterator" for arrays containing unnamed items. For example, a sequence of strings or integers would use an implicit iterator:
import moustachuvar c :Context=newContext()c["zoo_name"]="Anytown"c["animals"]=@["lions","tigers","bears"]var tmplate="""Animals at the {{zoo_name}} Zoo:{{#animals}}* {{.}}{{/animals}}"""echorender(tmplate, c)
On the command line
$ moustachu <context>.json <template>.moustache$ moustachu <context>.json <template>.moustache --file=<output>The first version will print to stdout and the second will generate a file.
Moustachu supports the specs found in its specs directory:
- comments
- interpolation
- inverted
- partials
- sections
The recommended way to install moustachu is throughnimble:
Installnimble. Then do:
$ nimble install moustachuThis will install the latest tagged version of moustachu.
The moustachu package includes the moustachu binary to use on the command line and the moustachu library to use in your code.
- Make the interfaces with the data structures as dynamic-like as possible
- No lambdas, nor set delimiters. At least for now. Let's keep it simple please.
- Test in context. Tests are run on the installed package because thatis what people get.
Get the source code:
$ git clone https://github.com/fenekku/moustachu.git$ cd moustachu# make your changes ...# test$ nimble tests# run benchmarks$ nimble benchmarksThis will test against the selected specs copied frommustache/spec
- Use to see what else to do/fix
About
Mustache templating for Nim
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors5
Uh oh!
There was an error while loading.Please reload this page.
