forked from jerrywdlee/yaml_2_resume
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_cv.rb
76 lines (62 loc) · 1.61 KB
/
make_cv.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8
require "optparse"
require "prawn"
require "yaml"
require './config'
require './lib/cv_maker'
require './lib/txt2yaml'
require './lib/util'
include Util
def parse_option
args = {}
OptionParser.new do |op|
op.on("-i [datafile]", "--input [datafile]") { |v| args[:input] = v }
op.on("-s [stylefile]", "--style [stylefile]") { |v| args[:style] = v }
op.on("-o [output]", "--output [output]") { |v| args[:output] = v }
op.on("-v", "--version") { |v| args[:version] = v }
op.parse!(ARGV)
end
args
end
def check_fonts
$font_faces.each do |k, v|
if !File.exists?(v)
puts <<-EOS
Font files are not found.
Please download IPAex fonts via
https://ipafont.ipa.go.jp/node26
and place them as
├── fonts
│ ├── ipaexg.ttf
│ └── ipaexm.ttf
└── make_cv.rb
EOS
exit
end
end
end
def cerate_pdf(input_file, style_file, output_file)
@date = Date.today
@data = YAML.load(load_as_erb(input_file))
if style_file =~ /\.txt$/
@style = TXT2YAMLConverter.new.convert(load_as_erb(style_file))
else
@style = YAML.load(load_as_erb(style_file))
end
puts "input file: #{input_file}"
puts "style file: #{style_file}"
puts "output file: #{output_file}"
@doc = CVMaker.new.generate(@data, @style)
@doc.render_file output_file
puts "Done."
end
check_fonts
args = parse_option
if args[:version]
puts Config.VERSION
exit(0)
end
input_file = args.fetch(:input, "templates/data.yaml")
style_file = args.fetch(:style, "templates/style.txt")
output_file = args.fetch(:output, "output.pdf")
cerate_pdf(input_file, style_file, output_file)