Class: Brite::Layout
Overview
Layout class
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
-
#initialize(site, file) ⇒ Layout
constructor
A new instance of Layout.
-
#render(model, &content) ⇒ Object
Render layout.
Methods inherited from Model
#[], #[]=, #config, #method_missing, #part, #rendering_fields, #to_binding, #to_h, #update
Constructor Details
#initialize(site, file) ⇒ Layout
Returns a new instance of Layout.
9 10 11 12 13 14 15 |
# File 'lib/brite/layout.rb', line 9 def initialize(site, file) @site = site @file = file @name = file.chomp('.layout') @path = File.(file) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Brite::Model
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
21 22 23 |
# File 'lib/brite/layout.rb', line 21 def file @file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/brite/layout.rb', line 24 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
27 28 29 |
# File 'lib/brite/layout.rb', line 27 def path @path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
18 19 20 |
# File 'lib/brite/layout.rb', line 18 def site @site end |
Instance Method Details
#render(model, &content) ⇒ Object
Render layout.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/brite/layout.rb', line 32 def render(model, &content) template = Neapolitan.file(path, :stencil=>site.config.stencil) # update the model's metadata #model.update(template.metadata) result = template.render(model, &content).to_s layout_name = template.['layout'] if layout_name layout = site.lookup_layout(layout_name) raise "No such layout -- #{layout}" unless layout result = layout.render(model){ result } end result.to_s end |