Class: Codgen::Template
- Inherits:
-
Object
- Object
- Codgen::Template
- Defined in:
- lib/codgen/template.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Used to unit test.
-
#input_path ⇒ Object
readonly
Used to unit test.
-
#template ⇒ Object
readonly
Used to unit test.
Class Method Summary collapse
Instance Method Summary collapse
- #fill_template ⇒ Object
-
#initialize(template_info, data_root) ⇒ Template
constructor
A new instance of Template.
Constructor Details
#initialize(template_info, data_root) ⇒ Template
Returns a new instance of Template.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/codgen/template.rb', line 10 def initialize(template_info, data_root) @input_path = template_info['in'] @out_raw = template_info['out'] source_raw = template_info['source'] source_location = source_raw != nil ? source_raw.split('.') : [] @data = Flattener.merge(data_root, source_location) @template = Template.get_template(@input_path) @template_provider = Codgen.template_provider.named(template_info['template engine']) if @template_provider == nil @template_provider = Codgen.template_provider.for_extension(File.extname(@input_path)) end if @template_provider == nil @template_provider = Codgen.template_provider.named('static') end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Used to unit test
46 47 48 |
# File 'lib/codgen/template.rb', line 46 def data @data end |
#input_path ⇒ Object (readonly)
Used to unit test
46 47 48 |
# File 'lib/codgen/template.rb', line 46 def input_path @input_path end |
#template ⇒ Object (readonly)
Used to unit test
46 47 48 |
# File 'lib/codgen/template.rb', line 46 def template @template end |
Class Method Details
Instance Method Details
#fill_template ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/codgen/template.rb', line 26 def fill_template if @data.is_a?(Array) output = Hash.new @data.each { |data| output.store(Mustache.render(@out_raw, data), @template_provider.render(@template, data)) } return output elsif @data.is_a?(Hash) return { Mustache.render(@out_raw, data) => @template_provider.render(@template, data) } end end |