Class: Lono::Template::PostProcessor
Instance Method Summary
collapse
#initialize, #reinitialize
#find_blueprint_root, #set_blueprint_root
Instance Method Details
#replacements ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/lono/template/post_processor.rb', line 14
def replacements
map = {}
registry_items.each do |item|
if item.directory? || item.file?
replacement = item.s3_path
else
puts "WARN: PostProcessor replacements Cannot find file: #{item.path}"
next
end
placeholder = "file://app/files/#{item.name}"
map[placeholder] = replacement
end
map
end
|
#run ⇒ Object
3
4
5
6
7
8
|
# File 'lib/lono/template/post_processor.rb', line 3
def run
replacements.each do |placeholder, replacement|
update_template!(template)
end
write_template!
end
|
#template ⇒ Object
50
51
52
|
# File 'lib/lono/template/post_processor.rb', line 50
def template
YAML.load_file(template_path)
end
|
#template_path ⇒ Object
55
56
57
|
# File 'lib/lono/template/post_processor.rb', line 55
def template_path
"#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
end
|
#update_template!(hash) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/lono/template/post_processor.rb', line 30
def update_template!(hash)
hash.each do |k, v|
if v.is_a?(String)
if v =~ %r{^file://}
v.replace(replacements[v]) end
elsif v.is_a?(Hash)
update_template!(v) elsif v.is_a?(Array)
v.each { |x| update_template!(x) if x.is_a?(Hash) }
end
end
hash
end
|
#write_template! ⇒ Object
10
11
12
|
# File 'lib/lono/template/post_processor.rb', line 10
def write_template!
IO.write(template_path, YAML.dump(template)) end
|