Module: Minimal::Template::Base
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
40
41
42
43
44
|
# File 'lib/minimal/template.rb', line 40
def method_missing(method, *args, &block)
return locals[method] if locals.key?(method)
return call_view(method, *args, &block) if view.respond_to?(method)
super
end
|
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
11
12
13
|
# File 'lib/minimal/template.rb', line 11
def block
@block
end
|
#locals ⇒ Object
Returns the value of attribute locals.
11
12
13
|
# File 'lib/minimal/template.rb', line 11
def locals
@locals
end
|
#view ⇒ Object
Returns the value of attribute view.
11
12
13
|
# File 'lib/minimal/template.rb', line 11
def view
@view
end
|
Instance Method Details
#<<(output) ⇒ Object
Also known as:
output
29
30
31
|
# File 'lib/minimal/template.rb', line 29
def <<(output)
view.output_buffer << output << "\n".html_safe
end
|
#_render(locals = nil, format = :html, &block) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/minimal/template.rb', line 18
def _render(locals = nil, format = :html, &block)
@locals = locals || {}
self.block = lambda { |*args| self << block.call(*args) }
send(:"to_#{format}", &self.block)
view.output_buffer
end
|
#initialize(view = nil) ⇒ Object
13
14
15
16
|
# File 'lib/minimal/template.rb', line 13
def initialize(view = nil)
@view, @locals, @_auto_buffer = view, {}, {}
view.assigns.each { |name, value| instance_variable_set(:"@#{name}", value) } if view
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
34
35
36
|
# File 'lib/minimal/template.rb', line 34
def respond_to?(method, include_private = false)
view.respond_to?(method) || locals.key?(method) || view.instance_variable_defined?("@#{method}") || super
end
|