Class: PDK::TemplateFile
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PDK::TemplateFile
- Defined in:
- lib/pdk/template_file.rb
Instance Method Summary collapse
- #config_for(path) ⇒ Object
-
#initialize(template_file, data = {}) ⇒ TemplateFile
constructor
Initialises the TemplateFile object with the path to the template file and the data to be used when rendering the template.
-
#render ⇒ String
Renders the template by calling the appropriate engine based on the file extension.
Constructor Details
#initialize(template_file, data = {}) ⇒ TemplateFile
Initialises the TemplateFile object with the path to the template file and the data to be used when rendering the template.
the template when rendering. the template as an instance variable ‘@configs` in order to maintain compatibility with modulesync.
17 18 19 20 21 22 23 24 25 |
# File 'lib/pdk/template_file.rb', line 17 def initialize(template_file, data = {}) @template_file = template_file if data.key?(:configs) @configs = data[:configs] end super(data) end |
Instance Method Details
#config_for(path) ⇒ Object
48 49 50 51 52 |
# File 'lib/pdk/template_file.rb', line 48 def config_for(path) return unless respond_to?(:template_dir) template_dir.config_for(path) end |
#render ⇒ String
Renders the template by calling the appropriate engine based on the file extension.
If the template has an ‘.erb` extension, the content of the template file will be treated as an ERB template. All other extensions are treated as plain text.
39 40 41 42 43 44 45 46 |
# File 'lib/pdk/template_file.rb', line 39 def render case File.extname(@template_file) when '.erb' render_erb else render_plain end end |