Solid (solid v0.15.2) View Source

Main module to interact with Solid

Link to this section Summary

Functions

It generates the compiled template

It generates the compiled template

It renders the compiled template using a map with vars

It renders the compiled template using a map with vars See render/3 for more details

Link to this section Types

Specs

errors() ::
  %Solid.UndefinedVariableError{__exception__: true, variable: term()}
  | %Solid.UndefinedFilterError{__exception__: true, filter: term()}

Link to this section Functions

Specs

parse(String.t(), Keyword.t()) ::
  {:ok, %Solid.Template{parsed_template: term()}}
  | {:error,
     %Solid.TemplateError{
       __exception__: true,
       header: term(),
       line: term(),
       message: term(),
       reason: term()
     }}

It generates the compiled template

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

Options

  • parser - a custom parser module can be passed. See Solid.Tag for more information
Link to this function

parse!(text, opts \\ [])

View Source

Specs

It generates the compiled template

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

Link to this function

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

View Source

Specs

render(%Solid.Template{parsed_template: term()}, map(), Keyword.t()) ::
  {:ok, iolist()} | {:error, [errors()], iolist()}
render(
  list(),
  %Solid.Context{
    counter_vars: term(),
    cycle_state: term(),
    errors: term(),
    iteration_vars: term(),
    vars: term()
  },
  Keyword.t()
) ::
  {iolist(),
   %Solid.Context{
     counter_vars: term(),
     cycle_state: term(),
     errors: term(),
     iteration_vars: term(),
     vars: term()
   }}

It renders the compiled template using a map with vars

Options

  • file_system: a tuple of {FileSystemModule, options}. If this option is not specified, Solid uses Solid.BlankFileSystem which raises 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 (thos from Solid.Filter) still can be used, however, custom filters always take precedence.

Example

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

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

View Source

Specs

render!(Solid.Template.t(), map(), Keyword.t()) :: iolist()

It renders the compiled template using a map with vars See render/3 for more details

It returns the rendered template or it raises an exception with the accumulated errors and a partial result