- Notifications
You must be signed in to change notification settings - Fork8
Mustache support for Sinatra applications
License
MIT, MIT licenses found
Licenses found
mustache/mustache-sinatra
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Support for Mustache in your Sinatra app.
Add this line to your application's Gemfile:
gem'mustache-sinatra'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mustache-sinatra
require'mustache/sinatra'classHurl <Sinatra::BaseregisterMustache::Sinatraset: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'domustache:statsendend
As noted above, Mustache will look forHurl::Views::Index
whenmustache :index
is called.
If noViews::Stats
class exists Mustache will render the templatefile directly.
You can indeed use layouts with this library. Where you'd normally<%= yield %> you instead {{{yield}}} - the body of the subview isset to theyield
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 froma gem, you can hand themustache
helper a Mustache subclass directly:
# Assuming `class Omnigollum::Login < Mustache`get'/login'do@title="Log In"require'lib/omnigollum/views/login'mustacheOmnigollum::Loginend
- Fork it (https://github.com/[my-github-username]/mustache-sinatra/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
About
Mustache support for Sinatra applications