0.01
No commit activity in last 3 years
There's a lot of open issues
No release in over a year
Mustache support for Sinatra applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.0
~> 0.6
~> 3.0
~> 1.4

Runtime

~> 1.0
 Project Readme

Mustache::Sinatra

Build Status

Support for Mustache in your Sinatra app.

Installation

Add this line to your application's Gemfile:

gem 'mustache-sinatra'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mustache-sinatra

Usage

require 'mustache/sinatra'

class Hurl < Sinatra::Base
  register Mustache::Sinatra

  set :mustache, {
    # Should be the path to your .mustache template files.
    :templates => "path/to/mustache/templates",

    # Should be the path to your .rb Mustache view files.
    :views => "path/to/mustache/views",

    # This tells Mustache where to look for the Views module,
    # under which your View classes should live. By default it's
    # the class of your app - in this case `Hurl`. That is, for an :index
    # view Mustache will expect Hurl::Views::Index by default.
    # If our Sinatra::Base subclass was instead Hurl::App,
    # we'd want to do `set :namespace, Hurl::App`
    :namespace => Hurl
  }

  get '/stats' do
    mustache :stats
  end
end

As noted above, Mustache will look for Hurl::Views::Index when mustache :index is called.

If no Views::Stats class exists Mustache will render the template file directly.

You can indeed use layouts with this library. Where you'd normally <%= yield %> you instead {{{yield}}} - the body of the subview is set to the yield variable and made available to you.

If you don't want the Sinatra extension to look up your view class, maybe because you've already loaded it or you're pulling it in from a gem, you can hand the mustache helper a Mustache subclass directly:

# Assuming `class Omnigollum::Login < Mustache`
get '/login' do
  @title = "Log In"
  require 'lib/omnigollum/views/login'
  mustache Omnigollum::Login
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/mustache-sinatra/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request