Sinatra classic top-level style example also working fine

28 views
Skip to first unread message

Bert Fitié

unread,
Dec 11, 2009, 3:27:43 AM12/11/09
to Mustache
This is just to document that mustache is also working fine in a
classic top-level style Sinatra application. Compared with the
existing modular style example there are 3 small differences:

1. calling the app with "run Sinatra::Application"
2. "register Mustache::Sinatra" is not needed
3. view classes are not, for example, named "App::Views::Home" but
just "Home"

----- config.ru -----
require 'simple'
run Sinatra::Application

----- simple.rb -----
require 'rubygems'
require 'sinatra'
require 'mustache/sinatra'
set :views, 'templates/'
set :mustaches, 'views/'
get '/' do
mustache :home
end

----- templates/home.mustache -----
<p>This is a nice quotation: "{{content}}"</p>

----- views/home.rb -----
class Home < Mustache
def content
"Hello beautiful world!"
end
end

Starting the app with "shotgun config.ru" enables nice application
reloading after changing
either 1. the top-level app file, e.g. simple.rb, or 2. a template
file or 3. a view ruby file

-- Bert

alfarid23

unread,
Jan 13, 2010, 7:20:57 AM1/13/10
to Mustache
Thank you! It works indeed.

I could not figure out how to make Sinatra / Mustache combo work with
shotgun, this helped so much!

Reply all
Reply to author
Forward
0 new messages