| Module | Sinatra::Renderer |
| In: |
lib/sinatra/context/renderer.rb
|
The magic or rendering happens here. This is included in Sinatra::EventContext on load.
These methods are the foundation for Sinatra::Erb and Sinatra::Haml and allow you to quickly create custom wrappers for your favorite rendering engines outside of erb and haml.
| DEFAULT_OPTIONS | = | { :views_directory => 'views', :layout => :layout |
Renders templates from a string or file and handles their layouts:
Example:
module MyRenderer
def my(template, options, &layout)
render(template, :my, options, &layout)
end
def render_my(template)
template.capitalize # It capitalizes templates!!!!! WOW!
end
end
Sinatra::EventContext.send :include, MyRenderer
get '/' do
my "something"
end
get_it '/' # => 'Something'
The second method is named render_extname. render will call this dynamicly
paramaters:
options:
# File lib/sinatra/context/renderer.rb, line 49
49: def render(template, renderer, options = {})
50: options = DEFAULT_OPTIONS.merge(options)
51:
52: layout = block_given? ? yield : Layouts[options[:layout]]
53:
54: result_method = 'render_%s' % renderer
55:
56: if layout
57: send(result_method, layout) { send(result_method, determine_template(template, renderer, options)) }
58: else
59: send(result_method, determine_template(template, renderer, options))
60: end
61: end