Class: Fulmar::Domain::Service::TemplateRenderingService
- Inherits:
-
Object
- Object
- Fulmar::Domain::Service::TemplateRenderingService
- Defined in:
- lib/fulmar/domain/service/template_rendering_service.rb
Overview
Renders templates of config files
Instance Method Summary collapse
-
#initialize(config) ⇒ TemplateRenderingService
constructor
A new instance of TemplateRenderingService.
- #render ⇒ Object
- #template_path(template_file) ⇒ Object
Constructor Details
#initialize(config) ⇒ TemplateRenderingService
Returns a new instance of TemplateRenderingService.
8 9 10 |
# File 'lib/fulmar/domain/service/template_rendering_service.rb', line 8 def initialize(config) @config = config end |
Instance Method Details
#render ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fulmar/domain/service/template_rendering_service.rb', line 12 def render return unless @config[:templates] @config[:templates].each do |template_file| template = template_path(template_file) renderer = ERB.new(File.read(template)) result_path = File.dirname(template) + '/' + File.basename(template, '.erb') File.open(result_path, 'w') { |config_file| config_file.write(renderer.result(binding)) } end end |
#template_path(template_file) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/fulmar/domain/service/template_rendering_service.rb', line 23 def template_path(template_file) template = "#{@config[:local_path]}/#{template_file}" raise "Template filenames must end in .erb - '#{template}' does not" unless template[-4, 4] == '.erb' raise "Cannot render missing config file '#{template}'" unless File.exist? template template end |