Slime

screenshot of Slime

Minimalistic HTML templates for Elixir, inspired by Slim.

Overview

Slime is an Elixir library for rendering Slim-like templates as HTML. It provides a refreshing way to slim down your markup in Elixir. With Slime, you can easily convert complex markup into a more concise and readable format. It offers various features such as reference attributes, Elixir code evaluation, comments, conditionals, doctype shortcuts, iteration, embedded engines, precompilation, and more. Slime aims for feature parity with the original Ruby Slim implementation, but deviates in some respects to stay true to Elixir.

Features

  • Reference Attributes: Assign attributes in a similar fashion to regular HTML, with support for Elixir expressions as attribute values using the interpolation syntax.
  • Code Evaluation: Write Elixir code inline using - for expression evaluation and = for expression evaluation and value insertion into the template.
  • Comments: Comment out lines using the / character, and insert HTML <!-- --> comments using /!.
  • Conditionals: Utilize regular Elixir flow control, such as the if expression, for conditional rendering in templates.
  • Doctype Shortcuts: Use shortcuts for common doctypes to quickly set the doctype in your templates.
  • Iteration: Utilize Elixir's collection manipulation expressions to iterate over collections in your templates.
  • Embedded Engines: Define your own embedded engine in the Slime application config, allowing for custom template rendering.
  • Precompilation: Compile templates into module functions, similar to EEx templates, using the provided functions Slime.function_from_file/5 and Slime.function_from_string/5.