Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mustache templating for Nim

NotificationsYou must be signed in to change notification settings

fenekku/moustachu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Moustachu is a(N im)plementation ofMustache (get it?). Mustache is "logic-less templating".

Usage

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.

Compliance

Moustachu supports the specs found in its specs directory:

  • comments
  • interpolation
  • inverted
  • partials
  • sections

Installation

The recommended way to install moustachu is throughnimble:

Installnimble. Then do:

$ nimble install moustachu

This 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.

Design

  • 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.

Develop and Test

Get the source code:

$ git clone https://github.com/fenekku/moustachu.git$ cd moustachu# make your changes ...# test$ nimble tests# run benchmarks$ nimble benchmarks

This will test against the selected specs copied frommustache/spec

TODO

  • Use to see what else to do/fix

About

Mustache templating for Nim

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp