jigplate

Created: 2012-03-22 04:40
Updated: 2014-09-16 22:25
License: mit

README.markdown

Jigplate - Logicless, Language-Agnostic, Pattern-Matching Templates

Usage

jigplate template [template ...]

Jigplate takes data from stdin in the form of JSON values and template files as arguments.

Examples

Object

Objects will match the first template that has slots for each of its keys.

Data

{"name": "hi", "title": "Welcome"}

Templates

article-item.html
<li><a href="/article/{name}">{title}</a></li>

Command

$ echo '{"name": "hi", "title": "Welcome"}' | jigplate template/article-item.html

Result

<li><a href="/article/hi">Welcome</a></li>

Array

Arrays will concatenate their contents.

Data

[{"name": "hi",    "title": "Welcome"},
 {"name": "intro", "title": "Introduction"}]

Templates

article-item.html
<li><a href="/article/{name}">{title}</a></li>

Command

$ echo '[{"name": "hi", "title": "Welcome"}, {"name": "intro", "title": "Introduction"}]' | jigplate template/article-item.html

Result

<li><a href="/article/hi">Welcome</a></li>
<li><a href="/article/intro">Introduction</a></li>

Nesting

Nesting is done in the data, not in the templates.

Data

{"articles": [{"name": "hi",    "title": "Welcome"},
              {"name": "intro", "title": "Introduction"}]}

Templates

article-item.html
<li><a href="/article/{name}">{title}</a></li>
page.html
<h2>Articles</h2>
<ul>
  {articles}
</ul>

Command

$ echo '{"articles": [{"name": "hi", "title": "Welcome"}, {"name": "intro", "title": "Introduction"}]}' | jigplate template/article-item.html template/page.html

Result

<h2>Articles</h2>
<ul>
  <li><a href="/article/hi">Welcome</a></li>
  <li><a href="/article/intro">Introduction</a></li>
</ul>

Building

I build jigplate with Nix to try to ensure reproducible builds:

nix-build dev.nix

default.nix is for inclusion in a top-level file (such as all-packages.nix). dev.nix builds jigplate with a fixed version of nixpkgs, providing stability at the cost of inflating the nix store.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more