-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.rb
48 lines (38 loc) · 1 KB
/
generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require "rubygems"
require "fileutils"
require "haml"
require "yaml"
class SignatureGenerator
def initialize
@template_file = "template.haml"
@yaml_file = "people.yml"
@output_directory = "build"
@people = YAML.load_file(@yaml_file)
@engine = Haml::Engine.new(File.read(@template_file))
end
def run
create_directory(@output_directory)
@people.map(&method(:write_person))
puts "Wrote #{@people.size} signatures"
end
def create_directory(dir)
# remove already generated signatures
FileUtils.rm_rf(dir) if File.directory?(dir)
# create a new build directory
FileUtils.mkdir_p(dir)
end
def cdn_url
ENV["CDN_URL"]
end
def write_person(person)
file_name = "#{person["first_name"]}-#{person["last_name"]}.html"
path = File.join(@output_directory, file_name)
File.open(path, "w") do |file|
file.write(@engine.render(Object.new, {
person: person,
cdn_url: cdn_url
}))
end
end
end
SignatureGenerator.new.run