Liquid templates, rendered as Liquid renders them.
iex> Braces.Liquid.render_to_string("Hi {{ name | upcase }}!", %{"name" => "<ada>"})
{:ok, "Hi <ADA>!"}
iex> Braces.Liquid.render_to_string("{% for p in people reversed %}{{ forloop.index }}. {{ p.name | default: 'someone' }} {% endfor %}", %{"people" => [%{"name" => "ada"}, %{}]})
{:ok, "1. someone 2. ada "}Rendering
render/3 renders a template with its data. compile/2 compiles one to render many times,
and the ~LIQUID sigil compiles it with your code, so a template that can't be rendered is
a CompileError at its line:
import Braces.Liquid, only: :sigils
Braces.render(~LIQUID"Hi {{ name }}", data)Braces.Liquid.Phoenix.Engine renders .liquid files in Phoenix. Braces.convert/2
converts Liquid to and from the other languages.
What renders
- Values:
{{ user.name }},{{ user["first name"] }},{{ items[0] }},{{ items.size }},.first,.lastand.length, a string's characters,{{ s[0] }}, with filters:{{ name | upcase }},{{ price | times: 2 }},{{ name | default: "friend" }}. {% if %},{% elsif %},{% else %}and{% unless %}, with==,!=,<>,<,>,<=,>=,contains,andandor, grouped from the right as Liquid groups them, and comparisons withemptyandblank.{% case %}with{% when a, b or c %}and{% else %}, rendering eachwhenthat matches, as LiquidJS does.{% for item in items %}with{% else %},reversed,limit:,offset:andoffset: continue, over a list or a range,(1..5);forloop.index,index0,rindex,rindex0,first,last,lengthandparentloop;{% break %}and{% continue %}.{% tablerow %}withcols:,limit:andoffset:, andtablerowloop;{% cycle %}, with or without a group;{% increment %}and{% decrement %}.{% assign %},{% capture %}and{% echo %}, and{% liquid %}, a tag per line.{% raw %},{% comment %},{% # inline comments %}and{% doc %}, and whitespace control,{{-and-%}.{% layout "base" %}and{% block %}, with{{ block.super }}, and{% include "card" %}and{% render "card", key: value %}, from the templates given astemplates:. See Layouts and includes.
Filters are LiquidJS's standard filters, Jekyll's among them: where, map and sort by a
key path, "a.b" or 'a["b c"]'; where_exp, reject_exp, find_exp, find_index_exp,
has_exp and group_by_exp, whose expression in a string is read with the template;
slugify, number_of_words with "cjk", date_to_xmlschema, date_to_rfc822,
date_to_string, date_to_long_string and sample. Give helpers: for others. A filter
Braces doesn't know gives its input, as in LiquidJS. Only nil and false are false, and
values are compared and written as LiquidJS does, as JavaScript would. date writes times
in UTC, at an offset given in minutes, or in a time zone named, "America/New_York", when
Elixir has a time zone database, such as tzdata's, configured.
Values are HTML-escaped, where Liquid writes them as they are, except those written with
escape or escape_once, and the markup a capture holds. Pass escape: false to write
them as Liquid does.
ifchanged, render … for, filters' named arguments other than default's allow_false,
and a template named by a variable are a Braces.ConversionError with the line and column.
Converting to another language, cycle, increment, decrement, tablerow, break,
continue and the filters of an expression are a Braces.ConversionError, as other
languages have nothing like them.
Summary
Rendering
Compiles Liquid into a Braces.Template for render/3, or gives the error that
convert/2 gives.
Like compile/2, raising the error.
Renders Liquid, or a Braces.Template of it, with data, to iodata.
Like render/3, giving a string.
The ~LIQUID sigil: Liquid compiled with your code into a Braces.Template, so a
template that doesn't convert is a CompileError at its line. Import it with
import Braces.Liquid, only: :sigils.
Converting
Converts Liquid to Handlebars source, or gives a Braces.ConversionError with the line
and column of what can't be converted. Takes escape: false to write values without HTML
escaping, as Liquid does.
Like convert/2, raising Braces.ConversionError.
Writes a Braces.IR as Liquid, or gives a Braces.ConversionError for what Liquid can't
say, such as helpers with no Liquid filter.
Reads Liquid into a Braces.IR, for Braces.convert/2: values are HTML-escaped unless
escape: false is given. Filters become Braces.Filters calls.
Rendering
@spec compile(String.t(), keyword()) :: {:ok, Braces.Template.t()} | {:error, Exception.t()}
Compiles Liquid into a Braces.Template for render/3, or gives the error that
convert/2 gives.
escape: falsewrites values without HTML escaping.templates:the templates it extends or includes, by name: a map of names to Liquid source orBraces.Templates, or a function of a name giving{:ok, template}or:error. They're compiled into it.
@spec compile!(String.t(), keyword()) :: Braces.Template.t()
Like compile/2, raising the error.
@spec render(String.t() | Braces.Template.t(), term(), keyword()) :: {:ok, iodata()} | {:error, Exception.t()}
Renders Liquid, or a Braces.Template of it, with data, to iodata.
Takes helpers:, functions for filters Braces doesn't have, as modules that use
Braces.Handlebars.Helpers, and, with source, escape: and templates:, as
compile/2 does.
@spec render_to_string(String.t() | Braces.Template.t(), term(), keyword()) :: {:ok, String.t()} | {:error, Exception.t()}
Like render/3, giving a string.
The ~LIQUID sigil: Liquid compiled with your code into a Braces.Template, so a
template that doesn't convert is a CompileError at its line. Import it with
import Braces.Liquid, only: :sigils.
Converting
Converts Liquid to Handlebars source, or gives a Braces.ConversionError with the line
and column of what can't be converted. Takes escape: false to write values without HTML
escaping, as Liquid does.
Like convert/2, raising Braces.ConversionError.
Writes a Braces.IR as Liquid, or gives a Braces.ConversionError for what Liquid can't
say, such as helpers with no Liquid filter.
Reads Liquid into a Braces.IR, for Braces.convert/2: values are HTML-escaped unless
escape: false is given. Filters become Braces.Filters calls.