Class: Deas::Template
- Inherits:
-
Object
- Object
- Deas::Template
- Defined in:
- lib/deas/template.rb
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(sinatra_call, name, options = nil) ⇒ Template
constructor
A new instance of Template.
-
#render(&block) ⇒ Object
builds render-blocks like:.
Constructor Details
#initialize(sinatra_call, name, options = nil) ⇒ Template
Returns a new instance of Template.
9 10 11 12 13 14 15 16 |
# File 'lib/deas/template.rb', line 9 def initialize(sinatra_call, name, = nil) @sinatra_call, @name, @options = sinatra_call, name.to_sym, ( || {}) @options[:scope] = @sinatra_call.settings.deas_template_scope.new(@sinatra_call) (@options.delete(:layout) || @options.delete(:layouts) || []).tap do |l| @layouts = l.compact.map(&:to_sym) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/deas/template.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/deas/template.rb', line 7 def @options end |
Instance Method Details
#render(&block) ⇒ Object
builds render-blocks like:
erb :main_layout do
erb :second_layout do
erb :user_index
end
end
26 27 28 29 30 31 32 |
# File 'lib/deas/template.rb', line 26 def render(&block) template_names = [ @layouts, @name ].flatten.reverse top_render_proc = template_names.inject(block) do |render_proc, name| proc{ @sinatra_call.erb(name, @options, &render_proc) } end top_render_proc.call end |