Class: Alula::Theme::View

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/theme/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.options(@file))
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/alula/theme/view.rb', line 8

def context
  @context
end

#layoutObject (readonly)

Returns the value of attribute layout.



7
8
9
# File 'lib/alula/theme/view.rb', line 7

def layout
  @layout
end

#themeObject (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