Class: HamlSupport::Helper
- Inherits:
-
Object
- Object
- HamlSupport::Helper
- Defined in:
- lib/calatrava/tasks/haml.rb
Instance Attribute Summary collapse
-
#page_name ⇒ Object
readonly
Returns the value of attribute page_name.
Instance Method Summary collapse
- #content_for(named_chunk) ⇒ Object
-
#initialize(page_path = nil) ⇒ Helper
constructor
A new instance of Helper.
- #layout_with(layout_name, content_blocks = {}) ⇒ Object
- #render_page(locals = {}) ⇒ Object
- #render_partial(partial_name, locals = {}) ⇒ Object
Constructor Details
#initialize(page_path = nil) ⇒ Helper
Returns a new instance of Helper.
9 10 11 12 |
# File 'lib/calatrava/tasks/haml.rb', line 9 def initialize(page_path = nil) @page_path = page_path @page_name = File.basename(@page_path, '.haml') if @page_path end |
Instance Attribute Details
#page_name ⇒ Object (readonly)
Returns the value of attribute page_name.
7 8 9 |
# File 'lib/calatrava/tasks/haml.rb', line 7 def page_name @page_name end |
Instance Method Details
#content_for(named_chunk) ⇒ Object
14 15 16 17 |
# File 'lib/calatrava/tasks/haml.rb', line 14 def content_for(named_chunk) chunk = @chunks[named_chunk] (chunk && chunk.call) || "" end |
#layout_with(layout_name, content_blocks = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/calatrava/tasks/haml.rb', line 19 def layout_with(layout_name, content_blocks = {}) @chunks = content_blocks layout_template = IO.read(File.join(SHELL_LAYOUTS_DIR, "#{layout_name}.haml")) Haml::Engine.new(layout_template).render(self, {}) end |
#render_page(locals = {}) ⇒ Object
31 32 33 34 |
# File 'lib/calatrava/tasks/haml.rb', line 31 def render_page(locals = {}) page_template = IO.read(@page_path) Haml::Engine.new(page_template).render(self, locals) end |
#render_partial(partial_name, locals = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/calatrava/tasks/haml.rb', line 25 def render_partial(partial_name, locals = {}) partial_name = "#{partial_name}.haml" unless partial_name =~ /haml$/ partial_template = IO.read partial_name Haml::Engine.new(partial_template).render(self, locals) end |