Class: XCCache::Template
- Inherits:
-
Object
- Object
- XCCache::Template
- Defined in:
- lib/xccache/utils/template.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(name) ⇒ Template
constructor
A new instance of Template.
- #render(hash = {}, save_to: nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Template
Returns a new instance of Template.
8 9 10 11 |
# File 'lib/xccache/utils/template.rb', line 8 def initialize(name) @name = name @path = ROOT / "lib/xccache/assets/templates/#{name}.template" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/xccache/utils/template.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/xccache/utils/template.rb', line 6 def path @path end |
Instance Method Details
#render(hash = {}, save_to: nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/xccache/utils/template.rb', line 13 def render(hash = {}, save_to: nil) raise GeneralError, "Template not found: #{name}" if path.nil? rendered = ERB.new(File.read(@path)).result_with_hash(hash) Pathname(save_to).write(rendered) unless save_to.nil? rendered end |