SwafViews

SWAFViews is a template library dedicated to HTML generation. It depends only on EEx. It precompiles templates as functions for fast rendering and protects the rendered code from injection.

Version 0.2

Warning: version 0.2 breaks the compatibility with previous versions.

Version 0.1 was kind of dependant on Plug.Conn as one could pass the conn variables to a SWAFViews function and SWAFViews extracted the assigns and the params maps. In version 0.2, the only allowed parameter is a map. If you want to pass assigns, params or whatever else to the template, you need to build the struct "by hand" in the controller. For example:

def index(conn) do
  params =  conn.assigns
  |> Map.merge(%{params: conn.params})
  |> Map.merge(%{a: 4, b: 12}) # some additional parameters if needed

  conn
  |> Conn.put_resp_content_type("text/html")
  |> Conn.send_resp(200, Views.index(params))
end

will make the following assigns available in the template:

%{
  a: 4, 
  b: 12, 
  params: %{}, 
  request_id: "GKO9MAo0TLXg5Y8AAAsE"
}

Installation

The package is installed by adding swaf_views to your list of dependencies in mix.exs:

 defp deps do
    [
      # If you want to play with the source code and contribute
      # {:swaf_views, path: "../swaf_views"},
      {:swaf_views, "~> 0.2"}
    ]
  end

Documentation

For a complete documentation, please refer to the SWAFViews module documentation.

Todo: