Hogan_assets

screenshot of Hogan_assets

Compiles your mustache templates with hogan.js on sprockets and the Rails asset pipeline.

Overview

HoganAssets is a gem that compiles mustache templates using hogan.js on sprockets and the Rails asset pipeline. Hogan.js is a templating engine developed at Twitter that follows the mustache spec and compiles the templates to JavaScript. This gem allows for server-side compilation of mustache templates using the asset pipeline/sprockets.

Features

  • Mustache templating engine compatibility
  • Compilation of mustache templates to JavaScript
  • Integration with Rails asset pipeline/sprockets

Installation with Rails 3.1+

  1. Add the following line to your Gemfile as part of the assets group:
gem 'hogan_assets'
  1. Run the following command:
bundle install
  1. Require hogan.js in your JavaScript manifest file (e.g. application.js):
//= require hogan.js
  1. Place your .mustache templates with your other JavaScript assets (usually in app/assets/javascripts/templates folder).
  2. Require your templates using require_tree in your JavaScript manifest file:
//= require_tree ./templates

Note: Templates are named based on their sub-path from the manifest file. For example, if your template is located at app/assets/javascripts/templates/pages/person.mustache, it will be named templates/pages/person.

Installation with sprockets

  1. Add the following line to your Gemfile:
gem 'hogan_assets'
  1. Run the following command:
bundle install
  1. Require hogan.js in your JavaScript code.
  2. Utilize hogan.js for compiling your mustache templates.

Hamstache

Hamstache is a combination of haml and mustache. To use hamstache, follow these additional steps:

  1. Add the following line to your Gemfile:
gem 'hamstache'
  1. Run the following command:
bundle install
  1. Configure hamstache compilation using Haml options.

Slimstache

Slimstache is a combination of slim and mustache. To use slimstache, follow these additional steps:

  1. Add the following line to your Gemfile:
gem 'slimstache'
  1. Run the following command:
bundle install
  1. Configure slimstache compilation using Slim options.

Summary

HoganAssets is a gem that allows for the compilation of mustache templates using hogan.js on sprockets and the Rails asset pipeline. It provides compatibility with mustache templating as well as integration with the asset pipeline/sprockets. Other combinations such as hamstache (haml + mustache) and slimstache (slim + mustache) are also supported.