-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
94 lines (73 loc) · 3.22 KB
/
Rakefile
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'yaml'
require_relative '_components/resume/generators'
RAW_DATA_DIR = '_data'
raw_data = Rake::FileList.new("#{RAW_DATA_DIR}/**/*.yml")
GENERATED_DIR = '_generated'
assets_dir = 'assets'
FILES_DIR = "#{assets_dir}/files"
images_dir = "#{assets_dir}/images"
task default: %w[resume:generate_files portfolio:generate_main_images]
namespace :resume do
resume_generated_dir = "#{GENERATED_DIR}/resume"
RESUME_DATA_FILE = "#{resume_generated_dir}/data.yml"
RESUME_RAW_TEMPLATES_DIR = '_components/resume/templates'
RESUME_RAW_TEMPLATES = Rake::FileList.new("#{RESUME_RAW_TEMPLATES_DIR}/*.md")
RESUME_TEMPLATES_DIR = resume_generated_dir
templates_regex = Regexp.new("#{RESUME_TEMPLATES_DIR}/.+\\.md")
RESUME_TEMPLATES = RESUME_RAW_TEMPLATES.pathmap("%{^#{RESUME_RAW_TEMPLATES_DIR}/,#{RESUME_TEMPLATES_DIR}/}p")
downloadable_files_spec = "%{^#{GENERATED_DIR}/,#{FILES_DIR}/}X"
docx_files = RESUME_TEMPLATES.pathmap("#{downloadable_files_spec}.docx")
pdf_files = RESUME_TEMPLATES.pathmap("#{downloadable_files_spec}.pdf")
downloadable_files = docx_files.add(pdf_files)
desc 'Merge separate YAML files into one and decorate it with additional calculated values'
task generate_data: RESUME_DATA_FILE
directory GENERATED_DIR
file RESUME_DATA_FILE => raw_data.add(GENERATED_DIR) do |t|
mkdir_p t.name.pathmap('%d')
puts "Generating data #{t.name}"
Resume::DataGenerator.new(RAW_DATA_DIR, t.name).generate
end
desc 'Convert Markdown raw templates (with Liquid syntax) to regular Markdown templates'
task convert_templates: RESUME_TEMPLATES
rule templates_regex => [->(f) { source_for_md(f) }, RESUME_DATA_FILE] do |t|
mkdir_p t.name.pathmap('%d')
puts "Generating template #{t.name}"
Resume::TemplateConverter.new(t.source, RESUME_DATA_FILE, t.name).convert
end
def source_for_md(md_file)
RESUME_RAW_TEMPLATES.detect do |f|
f == md_file.pathmap("%{^#{RESUME_TEMPLATES_DIR}/,#{RESUME_RAW_TEMPLATES_DIR}/}p")
end
end
desc 'Convert Markdown templates to downloadable files (docx and pdf)'
task generate_files: downloadable_files
directory assets_dir
rule '.docx' => [->(f) { source_for_downloadable_file(f) }, assets_dir] do |t|
mkdir_p t.name.pathmap('%d')
puts "Generating file #{t.name}"
sh "pandoc -o #{t.name} #{t.source}"
end
rule '.pdf' => [->(f) { source_for_downloadable_file(f) }, assets_dir] do |t|
mkdir_p t.name.pathmap('%d')
puts "Generating file #{t.name}"
sh "pandoc -fmarkdown-implicit_figures -V geometry:margin=0.2in -o #{t.name} #{t.source}"
end
def source_for_downloadable_file(downloadable_file)
RESUME_TEMPLATES.detect do |f|
f.ext == downloadable_file.pathmap("%{^#{FILES_DIR}/,#{GENERATED_DIR}/}X")
end
end
end
namespace :portfolio do
PORTFOLIO_HOME_PAGE_IMAGES = Rake::FileList.new("#{images_dir}/portfolio/**/home.png")
desc 'Generate main images for projects'
task generate_main_images: PORTFOLIO_HOME_PAGE_IMAGES.pathmap('%d/main.jpg')
rule '.jpg' => ->(f) { source_for_jpg(f) } do |t|
sh "convert #{t.source} -crop 1280x1280+0+0 -resize 700x700 #{t.name}"
end
def source_for_jpg(jpg_file)
PORTFOLIO_HOME_PAGE_IMAGES.detect do |f|
f.pathmap('%d') == jpg_file.pathmap('%d')
end
end
end