Class: Lono::Template::Strategy::Erb
Instance Method Summary
collapse
Methods included from Util
#ensure_parent_dir
Methods included from Evaluate
#evaluate_template_path, #template_evaluation_error
#reinitialize, #template_path
#find_blueprint_root, #set_blueprint_root
Constructor Details
#initialize(options = {}) ⇒ Erb
Returns a new instance of Erb.
6
7
8
9
10
|
# File 'lib/lono/template/strategy/erb.rb', line 6
def initialize(options={})
super
@templates = []
@results = {}
end
|
Instance Method Details
#build_templates ⇒ Object
49
50
51
52
53
|
# 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
|
74
75
76
77
78
79
80
|
# File 'lib/lono/template/strategy/erb.rb', line 74
def (text)
=<<~EOS
# This file was generated with lono. Do not edit directly, the changes will be lost.
# More info: http://lono.cloud
EOS
"#{}#{text}"
end
|
#evaluate_folder(folder) ⇒ Object
38
39
40
41
42
43
|
# 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) ⇒ Object
33
34
35
36
|
# 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 ⇒ Object
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.
26
27
28
29
30
31
|
# 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 = {}) ⇒ Object
12
13
14
15
16
|
# File 'lib/lono/template/strategy/erb.rb', line 12
def run(options={})
evaluate_templates
build_templates
write_output
end
|
#template(name, &block) ⇒ Object
45
46
47
|
# File 'lib/lono/template/strategy/erb.rb', line 45
def template(name, &block)
@templates << {name: name, block: block}
end
|
#write_output ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# 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] 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(/^\.\//,'') path += ".yml"
unless @options[:quiet]
pretty_path = path.sub("#{Lono.root}/",'')
puts " #{pretty_path}"
end
ensure_parent_dir(path)
text = (text)
IO.write(path, text) Lono::Yamler::Validator.new(path).validate!
end
end
|