mkbok 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/mkbok +77 -66
  2. data/lib/mkbok_version.rb +1 -1
  3. metadata +2 -2
data/bin/mkbok CHANGED
@@ -8,74 +8,85 @@ require 'yaml'
8
8
 
9
9
  include FileUtils
10
10
 
11
- options = {
12
- "build"=> "pdf",
13
- "lang" => "zh",
14
- "config" => "latex/config.yml",
15
- "template" => "latex/template.tex"
16
- }
17
- CONFIG_FILE = File.join('.mkbok.yml')
18
- if File.exists? CONFIG_FILE
19
- config_options = YAML.load_file(CONFIG_FILE)
20
- options.merge!(config_options)
21
- end
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
- executable_name = File.basename($PROGRAM_NAME)
25
- opts.banner = "make ebooks from markdown plain text
26
- Usage: #{executable_name} [options]
27
- "
28
- # Create a switch
29
- opts.on("-b","--build FORMAT","build format:epub,pdf,html. seperated by ','") do |format|
30
- formatOptions = format.split(",")
31
- formatOptions.each do | fmt |
32
- # puts fmt
33
- unless ["pdf","epub","html"].include?(fmt)
34
- raise ArgumentError,"FORMAT must be one of 'pdf,epub,html' format"
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
- options["build"] = format
38
- end
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
- options["lang"] = lang
48
- end
49
- opts.on("-c","--config CONFIG","config file") do |config|
50
- unless File.exists? config
51
- raise ArgumentError,"config file \"#{config}\" doesn't exist"
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
- options["config"] = config
54
- end
55
- opts.on("-t","--template template.tex","latex template file") do |template|
56
- unless File.exists? template
57
- raise ArgumentError,"template file \"#{template}\" doesn't exist"
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
- options["template"] = template
60
- end
61
- opts.on("-n","--name book name","book name") do |name|
62
- unless name =~ /^[a-zA-Z0-9]+$/
63
- raise ArgumentError,"name should be [a-zA-Z0-9]"
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
- if options["outputformat"].include?("pdf")
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
@@ -1,3 +1,3 @@
1
1
  module MkBok
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
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.9
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-02-13 00:00:00.000000000 Z
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: