Module: Cloudkeeper::One::ApplianceActions::Utils::TemplatePreparation
- Included in:
- Registration, Cloudkeeper::One::ApplianceActions::Update
- Defined in:
- lib/cloudkeeper/one/appliance_actions/utils/template_preparation.rb
Instance Method Summary collapse
Instance Method Details
#prepare_template(filename, data) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cloudkeeper/one/appliance_actions/utils/template_preparation.rb', line 10 def prepare_template(filename, data) template_file = File.join(Cloudkeeper::One::Settings[:'appliances-template-dir'], filename) raise Cloudkeeper::One::Errors::ArgumentError, "Missing file #{filename.inspect} in template directory" \ unless File.exist?(template_file) logger.debug "Populating template from #{template_file}" templates = [template_file, File.join(File.dirname(__FILE__), 'templates', 'attributes.erb')] data[:image] ||= nil rendered = render_templates templates, data logger.debug "Template:\n#{rendered}" rendered end |
#render_templates(templates, data) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/cloudkeeper/one/appliance_actions/utils/template_preparation.rb', line 24 def render_templates(templates, data) template = Tilt::ERBTemplate.new do io = StringIO.new templates.each { |file| io.write(File.read(file)) } io.string end template.render Object.new, data end |