Class: Stellar::Erb::View

Inherits:
Object
  • Object
show all
Defined in:
lib/stellar/erb/view.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path, locals = {}) ⇒ View

Returns a new instance of View.



8
9
10
11
12
13
14
# File 'lib/stellar/erb/view.rb', line 8

def initialize(template_path, locals = {})
  @template_path = template_path
  if @template_path
    @template_content = File.read(template_path)
  end
  @locals = locals
end

Instance Attribute Details

#localsObject

Returns the value of attribute locals.



6
7
8
# File 'lib/stellar/erb/view.rb', line 6

def locals
  @locals
end

#template_contentObject

Returns the value of attribute template_content.



6
7
8
# File 'lib/stellar/erb/view.rb', line 6

def template_content
  @template_content
end

#template_pathObject

Returns the value of attribute template_path.



6
7
8
# File 'lib/stellar/erb/view.rb', line 6

def template_path
  @template_path
end

Class Method Details

.render(template_path, locals = {}) ⇒ Object



24
25
26
# File 'lib/stellar/erb/view.rb', line 24

def self.render(template_path, locals = {})
  new(template_path, locals).render
end

Instance Method Details

#render(additional_locals = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/stellar/erb/view.rb', line 16

def render(additional_locals = {})
  all_locals = locals.merge(additional_locals)
  erb = ::ERB.new(template_content)
  erb.result_with_hash(all_locals)
rescue StandardError => e
  handle_error(e)
end