All Projects → soranoba → Bbmustache

soranoba / Bbmustache

Licence: mit
Binary pattern match Based Mustache template engine for Erlang/OTP.

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Bbmustache

django-mustache
Mustache (Pystache) template engine for Django 1.8 and newer, with support for Django context processors. Designed to support offline-capable web apps via progressive enhancement.
Stars: ✭ 20 (-85.82%)
Mutual labels:  template-engine, mustache
Spring Boot Email Tools
A set of services and tools for sending emails in a Spring Boot 1.5.x application using a Template Engine
Stars: ✭ 164 (+16.31%)
Mutual labels:  template-engine, mustache
morestachio
Lightweight, powerful, flavorful, template engine.
Stars: ✭ 45 (-68.09%)
Mutual labels:  template-engine, mustache
moustachu
Mustache templating for Nim
Stars: ✭ 58 (-58.87%)
Mutual labels:  template-engine, mustache
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (+129.08%)
Mutual labels:  template-engine, mustache
Handlebars.net
A real .NET Handlebars engine
Stars: ✭ 723 (+412.77%)
Mutual labels:  template-engine, mustache
Grmustache.swift
Flexible Mustache templates for Swift
Stars: ✭ 538 (+281.56%)
Mutual labels:  template-engine, mustache
Api2html
Using the data from your API, generate the HTML on the fly! Server-side rendering of the mustache templates
Stars: ✭ 97 (-31.21%)
Mutual labels:  template-engine, mustache
Dna.js
🧬 An uncomplicated user interface library for building data-driven semantic templates
Stars: ✭ 114 (-19.15%)
Mutual labels:  template-engine
Cost Analyzer Helm Chart
Kubecost helm chart
Stars: ✭ 126 (-10.64%)
Mutual labels:  mustache
Hero
A handy, fast and powerful go template engine.
Stars: ✭ 1,485 (+953.19%)
Mutual labels:  template-engine
Bem Xjst
bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server
Stars: ✭ 115 (-18.44%)
Mutual labels:  template-engine
Tempy
Python Object Oriented Html Templating System
Stars: ✭ 126 (-10.64%)
Mutual labels:  template-engine
Jsmart
jSmart is Smarty Javascript Template Engine, port of the PHP Smarty Template Engine
Stars: ✭ 111 (-21.28%)
Mutual labels:  template-engine
Yii2 Twig
Yii 2 Twig extension.
Stars: ✭ 130 (-7.8%)
Mutual labels:  template-engine
Eps
A templating engine for PowerShell
Stars: ✭ 108 (-23.4%)
Mutual labels:  template-engine
Helmchart
Helm chart for kubernetes deployments
Stars: ✭ 104 (-26.24%)
Mutual labels:  mustache
Thmsgbrt
My awesome README.md
Stars: ✭ 134 (-4.96%)
Mutual labels:  mustache
Charts
Helm chart repository
Stars: ✭ 128 (-9.22%)
Mutual labels:  mustache
Tera
A template engine for Rust based on Jinja2/Django
Stars: ✭ 1,873 (+1228.37%)
Mutual labels:  template-engine

bbmustache

Build Status hex.pm version

Binary pattern match Based Mustache template engine for Erlang/OTP.

Overview

  • Binary pattern match based mustache template engine for Erlang/OTP.
    • It means do not use regular expressions.
  • Support maps and associative arrays.
  • Officially support is OTP17 or later.

What is Mustache ?

A logic-less templates.

Usage

Quick start

$ git clone git://github.com/soranoba/bbmustache.git
$ cd bbmustache
$ make start
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:true]

Eshell V6.3  (abort with ^G)
1> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
<<"hoge">>
2> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
<<"hoge">>

Use as a library

Add the following settings.

%% rebar (rebar.config)

{deps,
  [
   {bbmustache, ".*", {git, "git://github.com/soranoba/bbmustache.git", {branch, "master"}}}
  ]}.

%% rebar3 (rebar.config)

{deps, [bbmustache]}.

How to use simple Mustache

Map

1> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
<<"hoge">>

2> Template1 = bbmustache:parse_binary(<<"{{name}}">>).
...
3> bbmustache:compile(Template1, #{"name" => "hoge"}).
<<"hoge">>

4> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>).
...
5> bbmustache:compile(Template2, #{"name" => "hoge"}).
<<"hoge">>

Associative array

1> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
<<"hoge">>

2> Template1 = bbmustache:parse_binary(<<"{{name}}">>).
...
3> bbmustache:compile(Template1, [{"name", "hoge"}]).
<<"hoge">>

4> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>).
...
5> bbmustache:compile(Template2, [{"name", "hoge"}]).
<<"hoge">>

Use as a command-line tool

make escriptize
echo '{"name", "hoge"}.' > vars.config
echo '{{name}}' > template.mustache
./bbmustache -d vars.config template.mustache
hoge

Data files (-d) support a single assoc list, a single map, and consult format.
Note: the behind term has a high priority in all cases. it is a result of supporting to allow for embedding relative file paths as in config.

More information

  • For the alias of mustache, Please refer to ManPage and Specification
  • For the options of this library, please see doc
  • For the functions supported by this library, please see here

FAQ

Avoid http escaping

%% Please use `{{{tag}}}`
1> bbmustache:render(<<"<h1>{{{title}}}</h1>">>, #{"title" => "I like Erlang & mustache"}).
<<"<h1>I like Erlang & mustache</h1>">>

%% If you should not want to use `{{{tag}}}`, escape_fun can be use.
1> bbmustache:render(<<"<h1>{{title}}</h1>">>, #{"title" => "I like Erlang & mustache"}, [{escape_fun, fun(X) -> X end}]).
<<"<h1>I like Erlang & mustache</h1>">>

Already used { and } for other uses (like escript)

1> io:format(bbmustache:render(<<"
1> {{=<< >>=}}
1> {deps, [
1>   <<#deps>>
1>   {<<name>>, \"<<version>>\"}<<^last?>>,<</last?>>
1>   <</deps>>
1> ]}.
1> ">>, #{"deps" => [
1>   #{"name" => "bbmustache", "version" => "1.6.0"},
1>   #{"name" => "jsone", "version" => "1.4.6", "last?" => true}
1> ]})).

{deps, [
  {bbmustache, "1.6.0"},
  {jsone, "1.4.6"}
]}.
ok

Want to use something other than string for key

1> bbmustache:render(<<"<h1>{{{title}}}</h1>">>, #{title => "I like Erlang & mustache"}, [{key_type, atom}]).
<<"<h1>I like Erlang & mustache</h1>">>

2> bbmustache:render(<<"<h1>{{{title}}}</h1>">>, #{<<"title">> => "I like Erlang & mustache"}, [{key_type, binary}]).
<<"<h1>I like Erlang & mustache</h1>">>

Want to provide a custom serializer for Erlang Terms

1> bbmustache:render(<<"<h1>{{title}}</h1>">>, #{title => "I like Erlang & mustache"}, [{key_type, atom}, {value_serializer, fun(X) -> X end}]).
<<"<h1>I like Erlang &amp; mustache</h1>">>

2> bbmustache:render(<<"<h1>{{{title}}}</h1>">>, #{<<"title">> => "I like Erlang & mustache"}, [{key_type, binary}, {value_serializer, fun(X) -> <<"replaced">> end}]).
<<"<h1>replaced</h1>">>

3> bbmustache:render(<<"<h1>{{{title}}}</h1>">>, #{<<"title">> => #{<<"nested">> => <<"value">>}}, [{key_type, binary}, {value_serializer, fun(X) -> jsone:encode(X) end}]).
<<"<h1>{\"nested\": \"value\"}</h1>">>

4> bbmustache:render(<<"<h1>{{title}}</h1>">>, #{<<"title">> => #{<<"nested">> => <<"value">>}}, [{key_type, binary}, {value_serializer, fun(X) -> jsone:encode(X) end}]).
<<"<h1>{&quot;nested&quot;:&quot;value&quot;}</h1>">>

Attention

  • Lambda expression is included wasted processing.
    • Because it is optimized to parse_binary/1 + compile/2.

Comparison with other libraries

Benchmarks and check the reference implementation

Contribute

Pull request is welcome =D

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].