Class: Trekky::HamlSource
Instance Attribute Summary collapse
-
#regions ⇒ Object
readonly
Returns the value of attribute regions.
Attributes inherited from Source
#context, #errors, #output, #path
Instance Method Summary collapse
- #content_for(name, &block) ⇒ Object
-
#initialize(context, path) ⇒ HamlSource
constructor
A new instance of HamlSource.
- #partial(name) ⇒ Object
- #render(options = {}, &block) ⇒ Object
- #type ⇒ Object
Methods inherited from Source
#add_error, #clear_errors, #extension, #input, #render_error, #render_errors, #valid?
Constructor Details
#initialize(context, path) ⇒ HamlSource
Returns a new instance of HamlSource.
9 10 11 12 13 |
# File 'lib/trekky/haml_source.rb', line 9 def initialize(context, path) super @regions = {} @env = {} end |
Instance Attribute Details
#regions ⇒ Object (readonly)
Returns the value of attribute regions.
7 8 9 |
# File 'lib/trekky/haml_source.rb', line 7 def regions @regions end |
Instance Method Details
#content_for(name, &block) ⇒ Object
46 47 48 49 |
# File 'lib/trekky/haml_source.rb', line 46 def content_for(name, &block) return unless block_given? regions[name] = capture_haml(&block) end |
#partial(name) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/trekky/haml_source.rb', line 37 def partial(name) source = context.find_partial(name) if source source.render(layout: false) else STDERR.puts "[ERROR] Can't find partial: #{name}" end end |
#render(options = {}, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/trekky/haml_source.rb', line 15 def render( = {}, &block) clear_errors @output = if block_given? || [:layout] == false render_input(&block) else buffer = render_input if layout layout.render do |name| if region.nil? buffer elsif regions.has_key?(name) regions[name] end end else buffer end end rescue Exception => error add_error error end |
#type ⇒ Object
51 52 53 |
# File 'lib/trekky/haml_source.rb', line 51 def type :haml end |