├── templates ├── nolayout.mustache ├── partial.mustache ├── other.mustache ├── index.mustache └── layout.mustache ├── config.ru ├── Gemfile ├── views ├── index.rb ├── layout.rb └── other.rb ├── Gemfile.lock ├── README.md └── app.rb /templates/nolayout.mustache: -------------------------------------------------------------------------------- 1 | This page has no layout. -------------------------------------------------------------------------------- /templates/partial.mustache: -------------------------------------------------------------------------------- 1 | It's just me. A partial. -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | require 'app' 2 | 3 | use Rack::ShowExceptions 4 | 5 | run App.new -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | 3 | gem "mustache" 4 | gem "sinatra" 5 | gem "shotgun" 6 | -------------------------------------------------------------------------------- /templates/other.mustache: -------------------------------------------------------------------------------- 1 | 4 | 5 |
{{ascii_art}}
6 | 7 | Home 8 | -------------------------------------------------------------------------------- /views/index.rb: -------------------------------------------------------------------------------- 1 | class App 2 | module Views 3 | class Index < Layout 4 | def content 5 | "Welcome! Mustache lives." 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /views/layout.rb: -------------------------------------------------------------------------------- 1 | class App 2 | module Views 3 | class Layout < Mustache 4 | def title 5 | @title || "Trust the Stache" 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /templates/index.mustache: -------------------------------------------------------------------------------- 1 |

{{title}}

2 | 3 |

{{content}}

4 | 5 | 13 | 14 | {{> partial}} -------------------------------------------------------------------------------- /templates/layout.mustache: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{title}} 6 | 7 | 11 | 12 | 13 |
14 | {{{yield}}} 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | mustache (0.99.4) 5 | rack (1.2.2) 6 | shotgun (0.9) 7 | rack (>= 1.0) 8 | sinatra (1.2.6) 9 | rack (~> 1.1) 10 | tilt (>= 1.2.2, < 2.0) 11 | tilt (1.3) 12 | 13 | PLATFORMS 14 | ruby 15 | 16 | DEPENDENCIES 17 | mustache 18 | shotgun 19 | sinatra 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A Mustache Sinatra Example 2 | ========================== 3 | 4 | Get started: 5 | 6 | $ git clone http://github.com/defunkt/mustache-sinatra-example 7 | $ cd mustache-sinatra-example 8 | $ gem install bundler 9 | $ bundle install 10 | $ bundle exec shotgun -O config.ru 11 | 12 | Or browser to by hand. 13 | 14 | Note that we use a `templates` and a `views` directory. *You don't 15 | have to.* By default the views and templates will live in the `views` 16 | directory together. 17 | 18 | Enjoy. 19 | 20 | -------------------------------------------------------------------------------- /app.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra/base' 2 | require 'mustache/sinatra' 3 | 4 | class App < Sinatra::Base 5 | register Mustache::Sinatra 6 | require 'views/layout' 7 | 8 | set :mustache, { 9 | :views => 'views/', 10 | :templates => 'templates/' 11 | } 12 | 13 | get '/' do 14 | @title = "Mustache + Sinatra = Wonder" 15 | mustache :index 16 | end 17 | 18 | get '/other' do 19 | mustache :other 20 | end 21 | 22 | get '/nolayout' do 23 | content_type 'text/plain' 24 | mustache :nolayout, :layout => false 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /views/other.rb: -------------------------------------------------------------------------------- 1 | class App 2 | module Views 3 | class Other < Mustache 4 | def ascii_art 5 | <<-end_art 6 | .................... 7 | .................... 8 | .............:~I7777777777+. .,I7777777777I:. 9 | .............778OOOOOOOOO88= ..IOOOOOOOOOOOO++ 10 | .............77OOOOOOOOOOOOO,, ~=8OOOOOOOOOOO8++ 11 | .............778OOOOOOOOOOOOII.. .ZZOOOOOOOOOOOOO++ 12 | .............77OOOOOOOOOOOOOO8$. .:O8OOOOOOOOOOOOO8++ 13 | .77OOOOOOOOOOOOO88O+. ..788OOOOOOOOOOOOO8++....... 14 | .778OOOOOOOOOOOOOO8O, .=OOOOOOOOOOOOOOOO8++....... 15 | .77OOOOOOOOOOOOOOOOO7. .,ZOOOOOOOOOOOOOOOOO++....... 16 | .77OOOOOOOOOOOOOOOOOOZ$.. :OZOOOOOOOOOOOOOOOOOO++....... 17 | .778OOOOOOOOOOOOOOOOOOO?.... .$OOOOOOOOOOOOOOOOOOOO++....... 18 | .77OOOOOOOOOOOOOOOOOOOOO: ...=O8OOOOOOOOOOOOOOOOOO8++....... 19 | .77OOOOOOOO8OOOOOOOOOOOO$...,OOOOOOOOOOO8OOOOOOOOO8++....... 20 | .778OOOOOOO8OO:OOOOOOOOOOO==OOOOOOOOOOZ:OOOOOOOOOO8++....... 21 | .778OOOOOOOOO8.IOOOOOOOO8O8OOOOOOOOOOO=:O8OOOOOOOO8++....... 22 | .778OOOOOOOOO8.:OOOOOOOOOOOOOOOOOOOO$$.:OOOOOOOOOOO++....... 23 | .77OOOOOOOOOO8..??OOOOOOOOOOOOOOOOOO~:.:OOOOOOOOOO8++....... 24 | .77OOOOOOOOOO8....+OOOOOOOOOOOOOOOO:...:OOOOOOOOOO8++....... 25 | .77OOOOOOOOOO8.....OOOOOOOOOOOOOOOI....:O8OOOOOOOOO++....... 26 | .778OOOOOOOOO8.....=OOOOOOOOOOOOOO:. :OOOOOOOOOO8++ 27 | .77OOOOOOOOOO8......$88OOOOOOOOO8I :O8OOOOOOOO8++ 28 | .778OOOOOOOOO8.......$$OOOOOOOO??. :OOOOOOOOOOO++ 29 | .77OOOOOOOOOO8...... ~:OOOOOOOO,, :OOOOOOOOOOO++ 30 | .77O8OOOOOOOO8.........7O8OOOO+. :OOOOOOOOOO8++ 31 | .~~7777777777+.........,77777I. .... .?7777777777:, 32 | . . ......=$OOOOOOO$=....~?7$$$$77+, .. . 33 | ....,7OOOOOOOOO8O=..=OOO88O88OOZ:... 34 | ..:ZZOOOOOOOOOOOOZ,,OOOOOOOOOOO8O=+. 35 | ...=8OOOOOOOOOOOOOOO++OOOOOOOOOOOOOOOI,.. 36 | .,$$8OOOOOOOOOOOOOOOOO$$OOOOOOOOOOOOOOOO8O== 37 | ..~O8OOOOOOOOOOOOOOOOO8O$$OOOOOOOOOOOOOOOOOOOO?.. 38 | ...?OOOOOOOOOOOOOOOOOOOOOO++OOOOOOOOOOOOOOOOOOOOO$,.. 39 | ...,$$OOOOOOOOOOOOOOOOOOOO887:,OOOOOOOOOOOOOOOOOOOOOOO~=.. 40 | :77III7$O8O8OOOOOOOOOOOOOOOOOOOO87,....+8OOOOOOOOOOOOOOOOOOOOOO8OI======+. 41 | .$$8OOOOOOOOOOOOOOOOOOOOOOOO8OO++..... .~ZZOOOOOOOOOOOOOOOOOOOOOOOOOOOO$7. 42 | ,,$8OOOOOOOOOOOOOOOOOO8O888O$: ...... ,,I8888OOOOOOOOOOOOOOOOOO88O8$,, 43 | .=$OOOOOOOOO8OOOO8O88OZ7I~......... ..~IOZOO8OOOOOOOOO8O88O8O8O?. 44 | ...,,,,,.................... ..,~======~~,. 45 | .................... 46 | end_art 47 | end 48 | end 49 | end 50 | end 51 | --------------------------------------------------------------------------------