Class: Alula::Theme::Layout
- Inherits:
-
Object
- Object
- Alula::Theme::Layout
- Defined in:
- lib/alula/theme/layout.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Layout
constructor
A new instance of Layout.
- #render(content, &blk) ⇒ Object
- #view(name) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Layout
Returns a new instance of Layout.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/alula/theme/layout.rb', line 12 def initialize(opts) @theme = opts.delete(:theme) @name = opts.delete(:name) @file = opts.delete(:file) @views = {} @context = @theme.context @template = Tilt.new(@file, nil, @theme.(@file)) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
10 11 12 |
# File 'lib/alula/theme/layout.rb', line 10 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/alula/theme/layout.rb', line 9 def name @name end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
8 9 10 |
# File 'lib/alula/theme/layout.rb', line 8 def theme @theme end |
Instance Method Details
#render(content, &blk) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/alula/theme/layout.rb', line 34 def render(content, &blk) _old_values = {} # Set up context, make sure we don't change anything begin content.each do |key, value| _old_values[key] = self.context[key] self.context[key] = value end # Render using our layout template @template.render(self.context, &blk) ensure _old_values.each do |key, value| self.context[key] = value end end end |