Module: Sinatra::MultiRender

Defined in:
lib/sinatra/support/multirender.rb

Overview

Allows rendering from multiple engines or renderers.

Usage

require 'sinatra/support/multirender'

class Main < Sinatra::Base
  register Sinatra::MultiRender

  # These two settings are optional.
  set :multi_views,   [ './views', './skin/default' ]
  set :multi_engines, [ :erb, :haml ]

  get '/' do
    show :home
  end
end

Using #show will automatically find the appropriate template, trying the following variations:

./views/home.erb
./views/home.haml
./skin/default/home.erb
./skin/default/home.haml

Defined Under Namespace

Modules: Helpers

Class Method Summary (collapse)

Class Method Details

+ (Object) registered(app)



28
29
30
31
32
33
34
35
# File 'lib/sinatra/support/multirender.rb', line 28

def self.registered(app)
  views = app.views || './views'

  app.set :multi_engines, Tilt.mappings.keys  unless app.respond_to?(:template_engines)
  app.set :multi_views,   views               unless app.respond_to?(:multi_views)

  app.helpers Helpers
end