Git Product home page Git Product logo

groucho's Introduction

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.

groucho's People

Contributors

hanjos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.