stache v0.2.1 Stache

Mustache templates for Elixir.

Stache is a templating engine for compiling mustache templates into native Elixir functions. It fully supports the features of the Mustache spec, allowing you to easily use the logic-less mustache templates you know and love.

The API mirrors that of EEx.

See the mustache spec for information about the mustache templating system itself.

Summary

Functions

Compiles and renders the template filename with context

Compiles and renders the template string with context

Macros

Compiles file and defines an elixir function from it

Compiles template and defines an elixir function from it

Functions

eval_file(filename, context, partials \\ %{})

Compiles and renders the template filename with context.

eval_string(string, context, partials \\ %{})

Compiles and renders the template string with context.

Macros

function_from_file(kind, name, file)

Compiles file and defines an elixir function from it.

kind can be :def or :defp.

This defines a 2-arity function that takes both the context to render along with the set of partials, if any. Both must be a Map.

Examples

# hello.stache
{{hello}}, world!

# templates.ex
defmodule Templates do
  require Stache

  def foo, do: 1
  Stache.function_from_file(:def, :hello_world, "hello.stache")
end

# iex
Templates.hello_world %{hello: "Hello"} #=> "Hello, world!"
function_from_string(kind, name, template)

Compiles template and defines an elixir function from it.

kind can be :def or :defp.

This defines a 2-arity function that takes both the context to render along with the set of partials, if any. Both must be a Map.

Examples

# templates.ex
defmodule Templates do
  require Stache

  def foo, do: 1
  Stache.function_from_string(:def, :hello_world, "{{hello}}, world!")
end

# iex
Templates.hello_world %{hello: "Hello"} #=> "Hello, world!"