-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Rakefile
111 lines (95 loc) · 3.44 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require 'asciidoctor'
require 'asciidoctor-pdf'
require 'yaml'
LANGS = %w[en fr es pt-br].freeze
VERSIONS = %w[5 6].freeze
OUTPUT_DIR = File.join __dir__, 'build'
THEMES_DIR = File.join __dir__, 'themes'
FONTS_DIR = File.join __dir__, 'fonts'
def check_args(args)
lang = args[:lang]
unless LANGS.include?(lang)
msg = format('Lang not available. Select on of these langs: %s', LANGS.join(', '))
raise ArgumentError, msg
end
version = args[:version]
unless VERSIONS.include?(version)
msg = format('Version not available. Select on of these versions: %s', VERSIONS.join(', '))
raise ArgumentError, msg
end
lang
end
def in_filename(args)
format('rails%s/%s/api_on_rails.adoc', args[:version], args[:lang])
end
def out_filename(args, extension)
format("api_on_rails_%s-%s.%s",args[:version], args[:lang], extension)
end
namespace :build do
desc 'Build for all versions, languages'
task :CI do
builds = YAML.load(File.read("builds.yaml"))
builds.each do |version, languages|
languages.each do |language|
puts "VERSION: #{version} - LANG: #{language}"
args = { version: version.to_s, lang: language }
Rake::Task['build:pdf'].execute(args)
Rake::Task['build:html'].execute(args)
Rake::Task['build:epub'].execute(args)
# [temporary] no mobi build
# TODO: fix when issue(https://github.com/tdtds/kindlegen/issues/42) solved
# Rake::Task['build:mobi'].execute(args)
end
end
end
desc 'Build all versions'
task :all, [:version, :lang] do |_task, args|
check_args(args)
Rake::Task['build:pdf'].invoke(args[:version], args[:lang])
Rake::Task['build:epub'].invoke(args[:version], args[:lang])
Rake::Task['build:mobi'].invoke(args[:version], args[:lang])
end
desc 'Build a PDF version'
task :pdf, [:version, :lang] do |_task, args|
check_args(args)
input = in_filename args
output = out_filename args, 'pdf'
Asciidoctor.convert_file input,
safe: :unsafe,
backend: 'pdf',
to_dir: OUTPUT_DIR,
mkdirs: true,
to_file: output,
attributes: {
'pdf-stylesdir' => THEMES_DIR,
'pdf-style' => 'my',
'pdf-fontsdir' => FONTS_DIR,
}
# `asciidoctor-pdf #{input} --destination-dir build --out-file #{output}`
puts "Book compiled on build/#{output}"
end
desc 'Build an HTML version'
task :html, [:version, :lang] do |_task, args|
check_args(args)
input = in_filename args
output = out_filename args, 'html'
`asciidoctor #{input} --destination-dir build --out-file #{output}`
puts "Book compiled on build/#{output}"
end
desc 'Build an EPUB version'
task :epub, [:version, :lang] do |_task, args|
check_args(args)
input = in_filename args
output = out_filename args, 'epub'
`asciidoctor-epub3 #{input} --destination-dir build --out-file #{output}`
puts "Book compiled on build/#{output}"
end
desc 'Build a MOBI version'
task :mobi, [:version, :lang] do |_task, args|
check_args(args)
input = in_filename args
output = out_filename args, 'mobi'
`asciidoctor-epub3 #{input} --destination-dir build -a ebook-format=kf8 --out-file #{output}`
puts "Book compiled on build/#{output}"
end
end