hanjos / groucho

Mustache implementation for Lua using LPeg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Groucho

Groucho is a Lua implementation of mustache, a logic-less templating language, using LPeg (well, re actually) for the dirty work.

For more information about mustache, check out the mustache project page or the mustache manual.

Documentation

There are comments in the code, if that's what you're asking :)

No, they're not LuaDoc-compatible (don't let the --- comments fool you :P). I haven't decided which documentation generator to use yet. LuaDoc doesn't render the docs the way I like, and I don't know what else is out there, so I made my own markup for now.

Testing

telescope looked nice, so I converted the mustache specs to telescope tests. tsc is expected to be called from the test directory.

Usage

The comment on the render function should tell you the nitty-gritty, but for the TL;DR crowd:

groucho exports a function render, which takes a template (a string) and a context (a table), as in the example below:

local result = groucho.render(
  'lorem ipsum {{fill}} yadda yadda {{{yadda}}}{{&nonexistent}}',          -- the template
  { fill = '<forgot what should go here>', yadda = '<random key mash>' })   -- the context

Optionally, it may take a configuration table as an extra parameter:

local result = groucho.render(
  'lorem ipsum {{fill}} yadda yadda {{{yadda}}}{{&nonexistent}}',  -- the template
  { fill = '<forgot what should go here>', 
    yadda = '<random key mash>' },         -- the context
  { template_path = '../',
    template_extension = 'mustache' })     -- the configuration table

The result is the template with its variables resolved against the context.

groucho also exports the re grammar (called grammar, appropriately enough), which has some hooks which need to be filled for the pattern to be constructed. They are also comment-documented.

To do

  • Set delimiters
  • What to do with the documentation?

Why?

To be honest, I just wanted an excuse to fool around with re :)

License

See the LICENSE file.

About

Mustache implementation for Lua using LPeg

License:MIT License


Languages

Language:Lua 100.0%