Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Converts mustache templates into a single javascript file
branch: master

This branch is 6 commits ahead of lowentropy:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib/guard
spec
.gitignore
Gemfile
Gemfile.lock
LICENSE
README.rdoc
Rakefile
VERSION
guard-mustachejs.gemspec

README.rdoc

Guard for MustacheJS templates

Guard::Mustachejs concatenates all your mustache templates into a single javascript file. Your templates are stored in a global object named 'mustache_templates' by default.

Install

First, install guard. Then, install the gem:

gem install guard-mustachejs

Or you can add it to your Gemfile:

gem 'guard-mustachejs'

To add the guard definition for mustachejs to your Guardfile, execute:

guard init mustachejs

Usage

By default, guard-mustachejs will look for mustache templates in app/mustache/*/.html. Let's say you have the following files:

app/mustache/home/banner.html
app/mustache/table/row.html

Guard will pull these files into a single javascript resource located at:

public/javascripts/mustache-templates.js

Assuming you have included mustache.js, you can then render your templates with:

Mustache.to_html(mustache_templates.home.banner, root)
Mustache.to_html(mustache_templates.table.row, root)

Guardfile and options

By default, guard-mustachejs will look for mustache templates in app/mustache/*/.html. The default guard clause looks like this:

guard 'mustachejs' do
  watch(%r{app/mustache/(.+)\.html})
end

You can change the output javascript file path and the name of the global variable used to store the templates. You can even have multiple template targets, like so:

guard 'mustachejs',
  :output => 'public/javascripts/js-templates.js',
  :variable => 'js_templates' do
  watch(%r{app/mustache/(.+)\.js})
end

guard 'mustachejs',
  :output => 'public/javascripts/html-templates.js',
  :variable => 'html_templates' do
  watch(%r{app/mustache/(.+)\.html})
end

Authors

Acknowledgement

Thanks to the Guard Team and to all the guard gem authors, especially Michael Kessler for his excellent guard-coffeescript gem, which was the inspiration for this one.

Something went wrong with that request. Please try again.