mkbok 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mkbok +77 -66
- data/lib/mkbok_version.rb +1 -1
- metadata +2 -2
data/bin/mkbok
CHANGED
@@ -8,74 +8,85 @@ require 'yaml'
|
|
8
8
|
|
9
9
|
include FileUtils
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def main()
|
12
|
+
options = {
|
13
|
+
"build"=> "pdf",
|
14
|
+
"lang" => "zh",
|
15
|
+
"config" => "latex/config.yml",
|
16
|
+
"template" => "latex/template.tex"
|
17
|
+
}
|
18
|
+
config_file = File.join('.mkbok.yml')
|
19
|
+
if File.exists? config_file
|
20
|
+
config_options = YAML.load_file(config_file)
|
21
|
+
options.merge!(config_options)
|
22
|
+
end
|
22
23
|
|
23
|
-
option_parser = OptionParser.new do |opts|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
option_parser = OptionParser.new do |opts|
|
25
|
+
executable_name = File.basename($PROGRAM_NAME)
|
26
|
+
opts.banner = "make ebooks from markdown plain text
|
27
|
+
Usage: #{executable_name} [options]
|
28
|
+
"
|
29
|
+
# Create a switch
|
30
|
+
opts.on("-b","--build FORMAT","build format:epub,pdf,html. seperated by ','") do |format|
|
31
|
+
formatOptions = format.split(",")
|
32
|
+
formatOptions.each do | fmt |
|
33
|
+
# puts fmt
|
34
|
+
unless ["pdf","epub","html"].include?(fmt)
|
35
|
+
raise ArgumentError,"FORMAT must be one of 'pdf,epub,html' format"
|
36
|
+
end
|
35
37
|
end
|
38
|
+
options["build"] = format
|
36
39
|
end
|
37
|
-
|
38
|
-
|
39
|
-
opts.on("-d","--debug","debug") do
|
40
|
-
options["debug"] = true
|
41
|
-
end
|
42
|
-
# Create a flag
|
43
|
-
opts.on("-l","--lang LANG","language selection") do |lang|
|
44
|
-
unless lang=="zh" or lang=="en"
|
45
|
-
raise ArgumentError,"LANG must be in zh or en"
|
40
|
+
opts.on("-d","--debug","debug") do
|
41
|
+
options["debug"] = true
|
46
42
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
# Create a flag
|
44
|
+
opts.on("-l","--lang LANG","language selection") do |lang|
|
45
|
+
unless lang=="zh" or lang=="en"
|
46
|
+
raise ArgumentError,"LANG must be in zh or en"
|
47
|
+
end
|
48
|
+
options["lang"] = lang
|
52
49
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
50
|
+
opts.on("-c","--config CONFIG","config file") do |config|
|
51
|
+
unless File.exists? config
|
52
|
+
raise ArgumentError,"config file \"#{config}\" doesn't exist"
|
53
|
+
end
|
54
|
+
options["config"] = config
|
58
55
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
opts.on("-t","--template template.tex","latex template file") do |template|
|
57
|
+
unless File.exists? template
|
58
|
+
raise ArgumentError,"template file \"#{template}\" doesn't exist"
|
59
|
+
end
|
60
|
+
options["template"] = template
|
61
|
+
end
|
62
|
+
opts.on("-n","--name book name","book name") do |name|
|
63
|
+
unless name =~ /^[a-zA-Z0-9]+$/
|
64
|
+
raise ArgumentError,"name should be [a-zA-Z0-9]"
|
65
|
+
end
|
66
|
+
options["name"] = name
|
64
67
|
end
|
65
|
-
options["name"] = name
|
66
68
|
end
|
67
|
-
end
|
68
69
|
|
69
|
-
option_parser.parse!
|
70
|
+
option_parser.parse!
|
70
71
|
|
71
|
-
#$here = File.expand_path(File.dirname(__FILE__))
|
72
|
-
$here = Dir.getwd
|
73
|
-
$root = File.join($here)
|
74
|
-
$outDir = File.join($root, 'pdf')
|
75
|
-
options["name"] = File.basename(Dir.getwd) unless options["name"]
|
76
|
-
options["outputformat"] = options["build"].split(',')
|
72
|
+
#$here = File.expand_path(File.dirname(__FILE__))
|
73
|
+
$here = Dir.getwd
|
74
|
+
$root = File.join($here)
|
75
|
+
$outDir = File.join($root, 'pdf')
|
76
|
+
options["name"] = File.basename(Dir.getwd) unless options["name"]
|
77
|
+
options["outputformat"] = options["build"].split(',')
|
77
78
|
|
78
|
-
puts options.inspect if options["debug"]
|
79
|
+
puts options.inspect if options["debug"]
|
80
|
+
|
81
|
+
if options["outputformat"].include?("pdf")
|
82
|
+
#puts "pdf"
|
83
|
+
generate_pdf(options)
|
84
|
+
end
|
85
|
+
options["outputformat"].delete("pdf")
|
86
|
+
if options["outputformat"].count>0
|
87
|
+
generate_ebook(options)
|
88
|
+
end
|
89
|
+
end
|
79
90
|
|
80
91
|
def figures(&block)
|
81
92
|
begin
|
@@ -312,7 +323,14 @@ end
|
|
312
323
|
|
313
324
|
def generate_ebook(options)
|
314
325
|
name = File.basename(Dir.getwd)
|
315
|
-
|
326
|
+
|
327
|
+
missing = ['pandoc'].reject{|command| command_exists?(command)}
|
328
|
+
unless missing.empty?
|
329
|
+
puts "Missing dependencies: #{missing.join(', ')}."
|
330
|
+
puts "Install these and try again."
|
331
|
+
exit
|
332
|
+
end
|
333
|
+
|
316
334
|
puts " "
|
317
335
|
puts "Will generate ebooks [#{options["outputformat"].join(',')}] for the following languages #{options["lang"]}"
|
318
336
|
puts " "
|
@@ -354,12 +372,5 @@ def generate_ebook(options)
|
|
354
372
|
end
|
355
373
|
end
|
356
374
|
|
357
|
-
|
358
|
-
#puts "pdf"
|
359
|
-
generate_pdf(options)
|
360
|
-
end
|
361
|
-
options["outputformat"].delete("pdf")
|
362
|
-
if options["outputformat"].count>0
|
363
|
-
generate_ebook(options)
|
364
|
-
end
|
375
|
+
main
|
365
376
|
|
data/lib/mkbok_version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mkbok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: the ebook generate tools from markdown plain text
|
15
15
|
email:
|