Class: Stellar::Erb::View
- Inherits:
-
Object
- Object
- Stellar::Erb::View
- Defined in:
- lib/stellar/erb/view.rb
Instance Attribute Summary collapse
-
#locals ⇒ Object
Returns the value of attribute locals.
-
#template_content ⇒ Object
Returns the value of attribute template_content.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template_path, locals = {}) ⇒ View
constructor
A new instance of View.
- #render(additional_locals = {}) ⇒ Object
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
#locals ⇒ Object
Returns the value of attribute locals.
6 7 8 |
# File 'lib/stellar/erb/view.rb', line 6 def locals @locals end |
#template_content ⇒ Object
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_path ⇒ Object
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 |