Class: Alula::Theme::View
- Inherits:
-
Object
- Object
- Alula::Theme::View
- Defined in:
- lib/alula/theme/view.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#initialize(opts) ⇒ View
constructor
A new instance of View.
- #render(content, &blk) ⇒ Object
Constructor Details
#initialize(opts) ⇒ View
Returns a new instance of View.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/alula/theme/view.rb', line 10 def initialize(opts) @theme = opts.delete(:theme) @name = opts.delete(:name) @file = opts.delete(:file) # Shortcuts... @context = @theme.context # Load our template @template = Tilt.new(@file, nil, @theme.(@file)) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/alula/theme/view.rb', line 8 def context @context end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
7 8 9 |
# File 'lib/alula/theme/view.rb', line 7 def layout @layout end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
6 7 8 |
# File 'lib/alula/theme/view.rb', line 6 def theme @theme end |
Instance Method Details
#render(content, &blk) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/alula/theme/view.rb', line 22 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 template @template.render(self.context, &blk) ensure _old_values.each do |key, value| self.context[key] = value end end end |