The template that every language converts to and from: each language's parser reads its
source into a Braces.IR, and each language's printer writes one out, so
Braces.convert/2 converts from any language to any other.
It holds what the languages have between them: output, conditions, loops, context changes,
variables, and expressions of paths, literals, operators and filters. A printer writes what
its language can say the same way, and gives a Braces.ConversionError for what it can't.
The template
body: the statements.language: the language it was read from, such as:handlebarsor:jinja, whose rules for writing values a printer follows where it can.truth: which values the template's conditions take as false (seetruth/0). Every condition,not,and,or,{% for %}…{% else %}and falsydefaultof the template uses it, so a printer for a language that decides otherwise writes the test out.
Statements
{:text, text}: text, written as it is.{:output, expression, escape?}: a value, HTML-escaped whenescape?is true.{:if, [{condition, body}], else_body}: the body of the first condition that's true, orelse_body, which may benil.{:for, list, bind, body, else_body, context?}: the body once for each element oflist, orelse_bodywhen there are none.bindnames the element,{:item, name}, or the key or index and the element,{:pair, key, value}, or isnil. Whencontext?is true, the element becomes the context, as in Handlebars'#eachand Go'srange; when false, the context stays, as in Jinja and Liquid.{:with, value, bind, body, else_body, context?}: whenvalueis true, the body, withvaluenamedbindunless it'snil, and as the context whencontext?is true; otherwiseelse_body.{:section, value, inverted?, body}: a Mustache section: the body once for each element of a list, once with a true value as the context, or, inverted, once when it's false.{:assign, name, expression}and{:capture, name, body}: set a variable.:breakand:continue, in a loop.{:let, [{name, value}], body}:bodywith variables set to the values, which have what they had before after it, as Jinja's and Django's{% with %}.{:macro, name, params, body}: defines the macroname, whoseparamsare[{name, default}], withnilfor no default. It's called with:macro_call.{:block, name, body}: a layout's block, which a template that extends the layout replaces with its own block of that name, orbody.nameisnilfor the block a template's content outside its blocks goes in, as LiquidJS's{% block %}and Handlebars'{{> @partial-block}}.:super, in a block: the block it replaces.{:extends, name, body, rest}: the layoutnamenames, with the blocks ofbodyin place of its own.restsays whatbodyhas outside its blocks is::ignored, but for the variables it sets, as in Jinja, or the layout's:blockwith no name.{:include, name, bindings, scope}: the templatenamenames, withbindings,[{name, expression}], set for it.scopesays what it sees and sets::context, the including template's variables, setting its own, as Jinja's include;:shared, setting them for the including template too, as Liquid's include; or:isolated, only its bindings, as Liquid's render.{:at, %{line: line, column: column}, statement}: where a statement is in the source, for errors.
Expressions
{:literal, value}: a string, number, boolean ornil.{:path, base, segments}: a value read frombasethroughsegments, each a string or an expression.baseis:this, the context;{:up, n}, the contextnchanges out;:root, the template's data;{:local, name}, a variable; or:search, the first context out from this one that has the first segment, as Mustache looks names up.{:get, value, segments}: a value read throughsegmentsfrom the value of an expression, as{'a': x}.aand(a ~ b).c.{:data, name}: a Handlebars data variable,@name.{:loop, field, up}: a loop's:index0,:index(from 1),:revindex0,:revindex(from 1),:first,:last,:lengthor:key, of the loopuploops out.{:not, value},{:and, a, b},{:or, a, b}: by the template'struth, as Python's, giving one of the values forandandor.{:default, value, fallback, mode}:fallbackwhenvalueis:missing(nil), or:falsy(false by the template'struth), or:empty(nil,false,"",[]or%{}).{:call, name, arguments, keyword_arguments}: a filter, function or operator, by its name inBraces.Filters:{{ a + b }}is{:call, "add", [a, b], []}."range"is Python's range, which stops before its end, and"liquid_range"Liquid's, which ends with it.{:cond, test, a, b}:awhentestis true, otherwiseb.{:list, items}and{:map, [{key, value}]}: a list and a map of expressions.{:macro_call, name, arguments, keyword_arguments, caller}: what the macronamewrites, as safe HTML.callerisnil, or{params, body}, the body that the macro writes for{:caller, arguments}, with its params set from those arguments.
Summary
Functions
Whether value is true by truth.
Types
@type truth() :: :handlebars | :python | :javascript | :php | :liquid | :mustache
Which values a language takes as false:
:handlebars:nil,false,0,""and[].:python: those and%{}, as Jinja, Django, Tera and Go.:javascript:nil,false,0and"", as Nunjucks.:php:nil,false,0,"","0",[]and%{}, as Twig.:liquid:nilandfalse.:mustache:nil,falseand[].