class Lono::Template::Strategy::Erb
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
Lono::AbstractBase::new
# File lib/lono/template/strategy/erb.rb, line 6 def initialize(options={}) super @templates = [] @results = {} end
Public Instance Methods
build_templates()
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 49 def build_templates @templates.each do |t| @results[t[:name]] = Lono::Template::Template.new(@blueprint, t[:name], t[:block], @options).build end end
commented(text)
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 74 def commented(text) comment =<<~EOS # This file was generated with lono. Do not edit directly, the changes will be lost. # More info: http://lono.cloud EOS "#{comment}#{text}" end
evaluate_folder(folder)
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 38 def evaluate_folder(folder) paths = Dir.glob("#{Lono.config.definitions_path}/#{folder}/**/*") paths.select{ |e| File.file?(e) }.each do |path| evaluate_template_path(path) end end
evaluate_template(name)
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 33 def evaluate_template(name) path = "#{Lono.config.definitions_path}/#{name}.rb" evaluate_template_path(path) end
evaluate_templates()
click to toggle source
Instance eval's the template declarations in app/definitions in this order:
app/definitions/base.rb app/definitions/base - all files in folder app/definitions/[Lono.env].rb app/definitions/[Lono.env] - all files in folder
So Lono.env specific template declarations override base template declarations.
# File lib/lono/template/strategy/erb.rb, line 26 def evaluate_templates evaluate_template("base") evaluate_folder("base") evaluate_template(Lono.env) evaluate_folder(Lono.env) end
run(options={})
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 12 def run(options={}) evaluate_templates build_templates write_output end
template(name, &block)
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 45 def template(name, &block) @templates << {name: name, block: block} end
write_output()
click to toggle source
# File lib/lono/template/strategy/erb.rb, line 55 def write_output output_path = "#{Lono.config.output_path}/#{@blueprint}/templates" FileUtils.rm_rf(Lono.config.output_path) if @options[:clean] # removes entire output folder. params and templates FileUtils.mkdir_p(output_path) puts "Generating CloudFormation templates for blueprint #{@blueprint.color(:green)}:" unless @options[:quiet] @results.each do |name,text| path = "#{output_path}/#{name}".sub(/^\.\//,'') # strip leading '.' path += ".yml" unless @options[:quiet] pretty_path = path.sub("#{Lono.root}/",'') puts " #{pretty_path}" end ensure_parent_dir(path) text = commented(text) IO.write(path, text) # write file first so validate method is simpler Lono::Yamler::Validator.new(path).validate! end end