Solid (solid v1.0.0-rc.0)

View Source

Solid is an implementation in Elixir of the Liquid template language with strict parsing.

Summary

Functions

It generates the compiled template

It generates the compiled template

It renders the compiled template using a map with initial vars

It renders the compiled template using a map with vars

Types

Functions

parse(text, opts \\ [])

@spec parse(
  binary(),
  keyword()
) :: {:ok, Solid.Template.t()} | {:error, Solid.TemplateError.t()}

It generates the compiled template

This function returns {:ok, template} if successfully parses the template, {:error, template_error} otherwise

Options

  • tags - Override tags allowed during compilation. See Solid.Tag.default_tags/0 for more information on the default set of tags

parse!(text, opts \\ [])

It generates the compiled template

This function returns the compiled template or raises an error. Same options as parse/2

render(template_or_text, values, options \\ [])

@spec render(Solid.Template.t(), map(), keyword()) ::
  {:ok, result :: iolist(), errors()}
  | {:error, errors(), partial_result :: iolist()}
@spec render(Solid.Parser.parse_tree(), Solid.Context.t(), keyword()) ::
  {iolist(), Solid.Context.t()}

It renders the compiled template using a map with initial vars

Options

  • file_system: a tuple of {FileSystemModule, options}. If this option is not specified, Solid uses Solid.BlankFileSystem which returns an error when the render tag is used. Solid.LocalFileSystem can be used or a custom module may be implemented. See Solid.FileSystem for more details.

  • custom_filters: a module name where additional filters are defined. The base filters (those from Solid.StandardFilter) still can be used, however, custom filters always take precedence.

  • strict_variables: if true, it collects an error when a variable is referenced in the template, but not given in the map

  • strict_filters: if true, it collects an error when a filter is referenced in the template, but not built-in or provided via custom_filters

  • matcher_module: a module to replace Solid.Matcher when resolving variables.

Example

fs = Solid.LocalFileSystem.new("/path/to/template/dir/") Solid.render(template, vars, [file_system: {Solid.LocalFileSystem, fs}])

render!(template, hash, options \\ [])

@spec render!(Solid.Template.t(), map(), keyword()) :: iolist() | no_return()

It renders the compiled template using a map with vars

Same options as render/3