xpub 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a579ef8c6e7e9d5466e33a3e546a291693e5aed5
4
- data.tar.gz: c75ed4a1328a969cee318b099dbd740352945cdb
3
+ metadata.gz: 9fc9eae42fc7bda94dd9691a0e7f18773f46887e
4
+ data.tar.gz: d2fd3a9da17e69da7b1ccc5452f2441b00a85953
5
5
  SHA512:
6
- metadata.gz: c1777154097204b47f7245fd25c03660876b2b91340784a8f9062dbd7d8f31af208d7a0a4ec20894c8c50aa17e943cc301e0894ddac0c545aaf75e457a3807ad
7
- data.tar.gz: c872d2c9b36364f3192da333ec505d37aeead02b0addfda7700cf4422583111cc3e824d3aa8a7be1aec7153b59ce97231dd47734063ecccac64bfd31684d3480
6
+ metadata.gz: cea43745ecc2537ee921aba38f7f5c24d460430764ea3cebb22693ef164cfd4cc250c7d2b498fcd8c3af70c3b6830b78de74cba6abd4fc7b063a832949dbea6d
7
+ data.tar.gz: 0a4ed1b9d0a07a74df850c14473a358cc95c0d6a7c83835a5b54c7bc8eb1a0b5b003baf9626872cda490aff5d8e846f7832de52184d5cda72c1211a050feaa59
@@ -0,0 +1,23 @@
1
+ AsciiComments:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 160
6
+
7
+ Metrics/AbcSize:
8
+ Max: 30
9
+
10
+ Metrics/ClassLength:
11
+ Max: 102
12
+
13
+ Style/MethodLength:
14
+ Max: 30
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ AllCops:
20
+ Exclude:
21
+ - 'cookbooks/**'
22
+ - '.chef/**'
23
+ - '.bundle/**'
data/README.md CHANGED
@@ -50,7 +50,7 @@ $ sudo tlmgr update --self --all
50
50
  インストールディレクトリは
51
51
 
52
52
  * 基本インストール
53
- /usr/local/texlive/2014
53
+ /usr/local/texlive/2015
54
54
  * TEXMFLOCAL
55
55
  /usr/local/texlive/texmf-local
56
56
  * TEXMFHOME
@@ -64,7 +64,7 @@ $ kpsewhich -var-value TEXMF
64
64
  で検索の優先順位がわかるらしい。
65
65
 
66
66
 
67
- ### pandoc 1.13.2
67
+ ### pandoc 1.15.2.1
68
68
 
69
69
  https://github.com/jgm/pandoc/releases
70
70
 
data/bin/xpub CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'bundler/setup'
4
4
 
5
5
  require 'rainbow/ext/string'
6
- require "open3"
6
+ require 'open3'
7
7
  require 'optparse'
8
8
  require 'fileutils'
9
9
  require 'pathname'
@@ -15,69 +15,66 @@ require 'levenshtein'
15
15
 
16
16
  require 'xpub/version.rb'
17
17
 
18
- option={}
19
- opt = OptionParser.new do |opt|
20
- opt.version = Xpub::VERSION
21
- opt.summary_indent = ' ' * 4
22
- opt.banner = 'Usage: xpub [cmd] [options]'
23
- opt.on_head('[cmd]',
24
- ' init Xpubファイルの生成',
25
- ' build ビルド',
26
- ' clean テンポラリフォルダと出力フォルダをクリア',
27
- ' check ソースコードを検証'
28
- )
29
- opt.on('-v', '出力を詳細にする') { |v| option[:v] = v }
30
- opt.on('--book=VALUE', 'ビルドするbookを指定する') { |v| option[:book] = v }
31
- opt.on('--builder=VALUE', 'ビルドするbuilderを指定する') { |v| option[:builder] = v }
32
- opt.on('--checker=VALUE', 'チェックするcheckerを指定する') { |v| option[:checker] = v }
33
- opt.on('--pandoc-json-output', 'ビルド時にpandocのjsonを出力') { |v| option['pandoc-json-output'] = v }
34
- opt.permute!(ARGV)
18
+ option = {}
19
+ opt = OptionParser.new do |o|
20
+ o.version = Xpub::VERSION
21
+ o.summary_indent = ' ' * 4
22
+ o.banner = 'Usage: xpub [cmd] [options]'
23
+ o.on_head('[cmd]',
24
+ ' init Xpubファイルの生成',
25
+ ' build ビルド',
26
+ ' clean テンポラリフォルダと出力フォルダをクリア',
27
+ ' check ソースコードを検証')
28
+ o.on('-v', '出力を詳細にする') { |v| option[:v] = v }
29
+ o.on('--book=VALUE', 'ビルドするbookを指定する') { |v| option[:book] = v }
30
+ o.on('--builder=VALUE', 'ビルドするbuilderを指定する') { |v| option[:builder] = v }
31
+ o.on('--checker=VALUE', 'チェックするcheckerを指定する') { |v| option[:checker] = v }
32
+ o.on('--pandoc-json-output', 'ビルド時にpandocのjsonを出力') { |v| option['pandoc-json-output'] = v }
33
+ o.permute!(ARGV)
35
34
  end
36
35
 
37
- curDir = Dir::getwd
36
+ cur_dir = Dir.getwd
38
37
 
39
- unless File.file?("#{curDir}/Xpub") || ARGV[0] == "init"
40
- puts "File does not exist. #{curDir}/Xpub".color :red
41
- exit
38
+ unless File.file?("#{cur_dir}/Xpub") || ARGV[0] == 'init'
39
+ puts "File does not exist. #{cur_dir}/Xpub".color :red
40
+ exit
42
41
  end
43
42
 
44
- $:.unshift "#{curDir}/lib"
45
- $:.unshift File.dirname(__FILE__) + "/../lib"
43
+ $:.unshift "#{cur_dir}/lib"
44
+ $:.unshift File.dirname(__FILE__) + '/../lib'
46
45
 
47
- require "xpub/dsl_accessor"
48
- require "xpub/dsl/book"
49
- require "xpub/dsl/src_file"
50
- require "xpub/dsl/builder"
51
- require "xpub/dsl/page"
52
- require "xpub/dsl/checker"
46
+ require 'xpub/dsl_accessor'
47
+ require 'xpub/dsl/book'
48
+ require 'xpub/dsl/src_file'
49
+ require 'xpub/dsl/builder'
50
+ require 'xpub/dsl/page'
51
+ require 'xpub/dsl/checker'
53
52
 
54
- if File.file?("#{curDir}/Xpub") && ARGV[0] != "init"
55
- load "#{curDir}/Xpub"
56
- end
53
+ load "#{cur_dir}/Xpub" if File.file?("#{cur_dir}/Xpub") && ARGV[0] != 'init'
57
54
 
58
55
  if ARGV.length != 1
59
- puts opt.help
60
- exit
61
- elsif ARGV[0] == "build"
62
- puts "build...".color :green
63
- Xpub::BookManager.instance.build option
64
- elsif ARGV[0] == "clean"
65
- puts "clean...".color :green
66
- FileUtils.remove_entry_secure("#{curDir}/tmp")
67
- Dir::mkdir("#{curDir}/tmp")
68
- FileUtils.remove_entry_secure("#{curDir}/output")
69
- Dir::mkdir("#{curDir}/output")
70
- elsif ARGV[0] == "init"
71
- if File.file?("#{curDir}/Xpub")
72
- puts "File exist. #{curDir}/Xpub".color :red
56
+ puts opt.help
73
57
  exit
74
- end
75
- puts "init...".color :green
76
- FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + "/../skel/*"),"./")
77
- elsif ARGV[0] == "check"
78
- puts "check...".color :green
79
- Xpub::BookManager.instance.check option
58
+ elsif ARGV[0] == 'build'
59
+ puts 'build...'.color :green
60
+ Xpub::BookManager.instance.build option
61
+ elsif ARGV[0] == 'clean'
62
+ puts 'clean...'.color :green
63
+ FileUtils.remove_entry_secure("#{cur_dir}/tmp")
64
+ Dir.mkdir("#{cur_dir}/tmp")
65
+ FileUtils.remove_entry_secure("#{cur_dir}/output")
66
+ Dir.mkdir("#{cur_dir}/output")
67
+ elsif ARGV[0] == 'init'
68
+ if File.file?("#{cur_dir}/Xpub")
69
+ puts "File exist. #{cur_dir}/Xpub".color :red
70
+ exit
71
+ end
72
+ puts 'init...'.color :green
73
+ FileUtils.cp_r(Dir.glob(File.dirname(__FILE__) + '/../skel/*'), './')
74
+ elsif ARGV[0] == 'check'
75
+ puts 'check...'.color :green
76
+ Xpub::BookManager.instance.check option
80
77
  else
81
- puts opt.help
82
- exit
78
+ puts opt.help
79
+ exit
83
80
  end
@@ -1,4 +1,4 @@
1
- require "xpub/version"
1
+ require 'xpub/version'
2
2
 
3
3
  module Xpub
4
4
  end
@@ -1,138 +1,122 @@
1
1
  module Xpub
2
- class CallBook
3
- attr_reader :name, :src_files, :resource_files, :creators, :contributors, :identifiers
4
-
5
- dsl_accessor :title, :default => "UNTITLED"
6
- dsl_accessor :subtitle
7
- dsl_accessor :short
8
- dsl_accessor :collection
9
- dsl_accessor :edition
10
- dsl_accessor :extended
11
- dsl_accessor :publisher
12
- dsl_accessor :rights
13
- dsl_accessor :publication
14
- dsl_accessor :modification
15
- dsl_accessor :lang, :default => "ja"
16
- dsl_accessor :description
17
-
18
- def initialize name
19
- @name = name
20
- @creators = []
21
- @contributors = []
22
- @identifiers = []
23
- @src_files = []
24
- @resource_files = []
25
- @builders = []
26
- @checkers = []
27
- end
2
+ class CallBook
3
+ attr_reader :name, :src_files, :resource_files, :creators, :contributors, :identifiers
4
+
5
+ dsl_accessor :title, default: 'UNTITLED'
6
+ dsl_accessor :subtitle
7
+ dsl_accessor :short
8
+ dsl_accessor :collection
9
+ dsl_accessor :edition
10
+ dsl_accessor :extended
11
+ dsl_accessor :publisher
12
+ dsl_accessor :rights
13
+ dsl_accessor :publication
14
+ dsl_accessor :modification
15
+ dsl_accessor :lang, default: 'ja'
16
+ dsl_accessor :description
17
+
18
+ def initialize(name)
19
+ @name = name
20
+ @creators = []
21
+ @contributors = []
22
+ @identifiers = []
23
+ @src_files = []
24
+ @resource_files = []
25
+ @builders = []
26
+ @checkers = []
27
+ end
28
28
 
29
- def validate
30
- end
29
+ def validate
30
+ end
31
31
 
32
- def build option
33
- puts "build #{@name} book.".color :green
34
- @builders.each { |b|
35
- if !option[:builder] || option[:builder] == b.name
36
- b.build option
32
+ def build(option)
33
+ puts "build #{@name} book.".color :green
34
+ @builders.each do |b|
35
+ b.build option if !option[:builder] || option[:builder] == b.name
36
+ end
37
37
  end
38
- }
39
- end
40
38
 
41
- def check option
42
- puts "check #{@name} book.".color :green
43
- @checkers.each { |c|
44
- if !option[:checker] || option[:checker] == c.name
45
- c.check option
39
+ def check(option)
40
+ puts "check #{@name} book.".color :green
41
+ @checkers.each do |c|
42
+ c.check option if !option[:checker] || option[:checker] == c.name
43
+ end
46
44
  end
47
- }
48
- end
49
45
 
50
- class CallAuthor
51
- attr_reader :name
52
- dsl_accessor :role
46
+ class CallAuthor
47
+ attr_reader :name
48
+ dsl_accessor :role
53
49
 
54
- def initialize name
55
- @name = name
56
- end
50
+ def initialize(name)
51
+ @name = name
52
+ end
57
53
 
58
- def validate
59
- end
60
- end
54
+ def validate
55
+ end
56
+ end
61
57
 
62
- def creator name, &block
63
- call = CallAuthor.new name
64
- if block
65
- call.instance_eval &block
66
- end
67
- call.validate
68
- @creators << call
69
- end
58
+ def creator(name, &block)
59
+ call = CallAuthor.new name
60
+ call.instance_eval(&block) if block
61
+ call.validate
62
+ @creators << call
63
+ end
70
64
 
71
- def contributor name, &block
72
- call = CallAuthor.new name
73
- if block
74
- call.instance_eval &block
75
- end
76
- call.validate
77
- @contributors << call
78
- end
65
+ def contributor(name, &block)
66
+ call = CallAuthor.new name
67
+ call.instance_eval(&block) if block
68
+ call.validate
69
+ @contributors << call
70
+ end
79
71
 
80
- class CallIdentifier
81
- attr_reader :identifier
82
- dsl_accessor :scheme
83
- dsl_accessor :type_value
72
+ class CallIdentifier
73
+ attr_reader :identifier
74
+ dsl_accessor :scheme
75
+ dsl_accessor :type_value
84
76
 
85
- def initialize identifier
86
- @identifier = identifier
87
- end
77
+ def initialize(identifier)
78
+ @identifier = identifier
79
+ end
88
80
 
89
- def validate
90
- end
91
- end
81
+ def validate
82
+ end
83
+ end
92
84
 
93
- def identifier identifier, &block
94
- call = CallIdentifier.new identifier
95
- if block
96
- call.instance_eval &block
97
- end
98
- call.validate
99
- @identifiers << call
85
+ def identifier(identifier, &block)
86
+ call = CallIdentifier.new identifier
87
+ call.instance_eval(&block) if block
88
+ call.validate
89
+ @identifiers << call
90
+ end
100
91
  end
101
- end
102
92
 
103
- def self.book name, &block
104
- call = CallBook.new name
105
- if block
106
- call.instance_eval &block
107
- end
108
- call.validate
109
- BookManager.instance.add call
110
- end
111
-
112
- class BookManager
113
- include Singleton
114
- def initialize
115
- @books = []
93
+ def self.book(name, &block)
94
+ call = CallBook.new name
95
+ call.instance_eval(&block) if block
96
+ call.validate
97
+ BookManager.instance.add call
116
98
  end
117
99
 
118
- def add b
119
- @books << b
120
- end
100
+ class BookManager
101
+ include Singleton
102
+ def initialize
103
+ @books = []
104
+ end
121
105
 
122
- def build option
123
- @books.each { |book|
124
- if !option[:book] || option[:book] == book.name
125
- book.build option
106
+ def add(b)
107
+ @books << b
108
+ end
109
+
110
+ def build(option)
111
+ @books.each do |book|
112
+ book.build option if !option[:book] || option[:book] == book.name
113
+ end
126
114
  end
127
- }
128
- end
129
115
 
130
- def check option
131
- @books.each { |book|
132
- if !option[:book] || option[:book] == book.name
133
- book.check option
116
+ def check(option)
117
+ @books.each do |book|
118
+ book.check option if !option[:book] || option[:book] == book.name
119
+ end
134
120
  end
135
- }
136
121
  end
137
- end
138
122
  end
@@ -1,319 +1,319 @@
1
1
  module Xpub
2
- class CallBook
3
- class CallBuilder
4
- attr_reader :name
5
- dsl_accessor :theme, :default => "default"
6
- dsl_accessor :output
7
-
8
- def initialize name, book
9
- @name = name
10
- @book = book
11
- end
12
-
13
- def build
14
- raise "This method is not implement."
15
- end
16
-
17
- def validate
18
- if @book.src_files.count == 0
19
- raise "src_file is empty."
2
+ class CallBook
3
+ class CallBuilder
4
+ attr_reader :name
5
+ dsl_accessor :theme, default: 'default'
6
+ dsl_accessor :output
7
+
8
+ def initialize(name, book)
9
+ @name = name
10
+ @book = book
11
+ end
12
+
13
+ def build
14
+ raise 'This method is not implement.'
15
+ end
16
+
17
+ def validate
18
+ raise 'src_file is empty.' if @book.src_files.count == 0
19
+ end
20
+
21
+ def src_path(file)
22
+ "#{Dir.getwd}/src/#{file}"
23
+ end
24
+
25
+ def tmp_path(file)
26
+ "#{Dir.getwd}/tmp/#{@book.name}/#{file}"
27
+ end
28
+
29
+ def output_path(file)
30
+ "#{Dir.getwd}/output/#{file}"
31
+ end
32
+
33
+ def copy_to_tmp(files)
34
+ files.each do |file|
35
+ pn = Pathname.new tmp_path(file.file)
36
+ FileUtils.mkdir_p(pn.dirname) unless FileTest.exist?(pn.dirname)
37
+
38
+ unless FileTest.exist?(tmp_path(file.file)) && File.mtime(src_path(file.file)) <= File.mtime(tmp_path(file.file))
39
+ puts "copy #{file.file} to tmp/".color :white
40
+ FileUtils.copy_entry(src_path(file.file), tmp_path(file.file))
41
+ end
42
+ end
43
+ end
44
+
45
+ def cmd_exec(cmd, args, option)
46
+ cmd_line = cmd + ' ' + args.map do |arg|
47
+ Shellwords.shellescape(arg)
48
+ end.join(' ')
49
+ puts cmd_line.color :cyan
50
+ stdout, stderr, status = Open3.capture3 cmd_line
51
+ puts stdout.color :green if option[:v] || status != 0
52
+ if status != 0
53
+ puts stderr.color :red
54
+ puts 'error!'.color :red
55
+ exit
56
+ end
57
+ end
20
58
  end
21
- end
22
-
23
- def src_path file
24
- "#{Dir::getwd}/src/#{file}"
25
- end
26
-
27
- def tmp_path file
28
- "#{Dir::getwd}/tmp/#{@book.name}/#{file}"
29
- end
30
-
31
- def output_path file
32
- "#{Dir::getwd}/output/#{file}"
33
- end
34
-
35
- def copy_to_tmp files
36
- files.each { |file|
37
- pn = Pathname.new tmp_path(file.file)
38
- FileUtils.mkdir_p(pn.dirname) unless FileTest.exist?(pn.dirname)
39
-
40
- unless FileTest.exist?(tmp_path(file.file)) && File::mtime(src_path(file.file)) <= File::mtime(tmp_path(file.file))
41
- puts "copy #{file.file} to tmp/".color :white
42
- FileUtils.copy_entry(src_path(file.file), tmp_path(file.file))
43
- end
44
- }
45
- end
46
-
47
- def cmd_exec cmd, args, option
48
- cmd_line = cmd + " " + args.map { |arg|
49
- Shellwords.shellescape(arg)
50
- }.join(" ")
51
- puts cmd_line.color :cyan
52
- stdout, stderr, status = Open3.capture3 cmd_line
53
- if option[:v] || status != 0
54
- puts stdout.color :green
55
- end
56
- if status != 0
57
- puts stderr.color :red
58
- puts "error!".color :red
59
- exit
60
- end
61
- end
62
- end
63
59
 
64
- class CallEpubBuilder < CallBuilder
65
- dsl_accessor :template, :default => "template.html"
66
- dsl_accessor :filter, :default => "pandoc-filter.rb"
67
- dsl_accessor :stylesheet, :default => "epub.css"
68
- dsl_accessor :metadata, :default => "metadata.dat"
69
- dsl_accessor :page_progression_direction, :default => "rtl"
70
- dsl_accessor :cover_image
71
- dsl_accessor :pandoc_cmd, :default => "pandoc"
72
-
73
- def initialize name, book
74
- @vars = []
75
- @meta = []
76
- if book.title != ""
77
- @vars << ["title", book.title]
60
+ class CallEpubBuilder < CallBuilder
61
+ dsl_accessor :template, default: 'template.html'
62
+ dsl_accessor :filter, default: 'pandoc-filter.rb'
63
+ dsl_accessor :stylesheet, default: 'epub.css'
64
+ dsl_accessor :metadata, default: 'metadata.dat'
65
+ dsl_accessor :page_progression_direction, default: 'rtl'
66
+ dsl_accessor :cover_image
67
+ dsl_accessor :pandoc_cmd, default: 'pandoc'
68
+
69
+ def initialize(name, book)
70
+ @vars = []
71
+ @meta = []
72
+ @vars << ['title', book.title] if book.title != ''
73
+ super name, book
74
+ end
75
+
76
+ def meta_option
77
+ result = []
78
+ @meta.concat([['page-progression-direction', page_progression_direction]]).each do |m|
79
+ result << '-M'
80
+ result << "#{m[0]}=#{m[1]}"
81
+ end
82
+ result
83
+ end
84
+
85
+ def vars_option
86
+ result = []
87
+ @vars.concat([[:book_name, @book.name]]).each do |v|
88
+ result << '-V'
89
+ result << "#{v[0]}=#{v[1]}"
90
+ end
91
+ result
92
+ end
93
+
94
+ def template_option
95
+ "--template=#{Dir.getwd}/theme/#{theme}/#{@name}/#{template}"
96
+ end
97
+
98
+ def filter_option
99
+ "--filter=#{Dir.getwd}/theme/#{theme}/#{@name}/#{filter}"
100
+ end
101
+
102
+ def stylesheet_option
103
+ "--epub-stylesheet=#{Dir.getwd}/theme/#{theme}/#{@name}/#{stylesheet}"
104
+ end
105
+
106
+ def metadata_option
107
+ '--epub-metadata=' + metadata_path
108
+ end
109
+
110
+ def metadata_path
111
+ tmp_path("#{@book.name}.#{metadata}")
112
+ end
113
+
114
+ def metadata_template_path
115
+ "#{Dir.getwd}/theme/#{theme}/#{@name}/#{metadata}.erb"
116
+ end
117
+
118
+ def epub_path
119
+ output_path(@book.name) + '.epub'
120
+ end
121
+
122
+ def json_path
123
+ tmp_path(@book.name) + '.json'
124
+ end
125
+
126
+ def _build_resource(files, _option)
127
+ copy_to_tmp files
128
+ end
129
+
130
+ def pandoc_option(option)
131
+ option = [
132
+ '--epub-chapter-level=1',
133
+ '--toc',
134
+ '-f',
135
+ 'markdown_phpextra+hard_line_breaks+raw_html',
136
+ '-s',
137
+ template_option,
138
+ filter_option,
139
+ stylesheet_option,
140
+ metadata_option
141
+ ]
142
+ option << '--epub-cover-image=' + src_path(cover_image) if cover_image
143
+ option
144
+ end
145
+
146
+ def build_epub_metadata(option)
147
+ f = open metadata_template_path
148
+ erb = ERB.new f.read, nil, '-'
149
+ f.close
150
+ f = open metadata_path, 'w'
151
+ f.write erb.result(binding)
152
+ f.close
153
+ end
154
+
155
+ def build(option)
156
+ FileUtils.mkdir_p(tmp_path('')) unless FileTest.exist?(tmp_path(''))
157
+
158
+ build_epub_metadata option
159
+
160
+ pandoc_option = pandoc_option(option).concat(vars_option).concat(meta_option).concat(@book.src_files.map(&:full_path))
161
+
162
+ cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', json_path, '-t', 'json'].concat(pandoc_option), option if option['pandoc-json-output']
163
+ cmd_exec "cd #{tmp_path ''};" + pandoc_cmd, ['-o', epub_path, '-t', 'epub3'].concat(pandoc_option), option
164
+ end
78
165
  end
79
- super name, book
80
- end
81
-
82
- def meta_option
83
- result = []
84
- @meta.concat([["page-progression-direction", page_progression_direction]]).each { |m|
85
- result << "-M"
86
- result << "#{m[0]}=#{m[1]}"
87
- }
88
- result
89
- end
90
-
91
- def vars_option
92
- result = []
93
- @vars.concat([[:book_name, @book.name]]).each { |v|
94
- result << "-V"
95
- result << "#{v[0]}=#{v[1]}"
96
- }
97
- result
98
- end
99
-
100
- def template_option
101
- "--template=#{Dir::getwd}/theme/#{theme}/#{@name}/#{template}"
102
- end
103
-
104
- def filter_option
105
- "--filter=#{Dir::getwd}/theme/#{theme}/#{@name}/#{filter}"
106
- end
107
-
108
- def stylesheet_option
109
- "--epub-stylesheet=#{Dir::getwd}/theme/#{theme}/#{@name}/#{stylesheet}"
110
- end
111
-
112
- def metadata_option
113
- "--epub-metadata=" + metadata_path
114
- end
115
-
116
- def metadata_path
117
- tmp_path("#{@book.name}.#{metadata}")
118
- end
119
-
120
- def metadata_template_path
121
- "#{Dir::getwd}/theme/#{theme}/#{@name}/#{metadata}.erb"
122
- end
123
-
124
- def epub_path
125
- output_path(@book.name) + '.epub'
126
- end
127
-
128
- def json_path
129
- tmp_path(@book.name) + '.json'
130
- end
131
-
132
- def _build_resource files, option
133
- copy_to_tmp files
134
- end
135
-
136
- def pandoc_option option
137
- option = [
138
- "--epub-chapter-level=1",
139
- "--toc",
140
- "-f",
141
- "markdown_phpextra+hard_line_breaks+raw_html",
142
- "-s",
143
- template_option,
144
- filter_option,
145
- stylesheet_option,
146
- metadata_option
147
- ]
148
- if cover_image
149
- option << "--epub-cover-image=" + src_path(cover_image)
150
- end
151
- option
152
- end
153
-
154
- def build_epub_metadata option
155
- f = open metadata_template_path
156
- erb = ERB.new f.read, nil, "-"
157
- f.close
158
- f = open metadata_path, "w"
159
- f.write erb.result(binding)
160
- f.close
161
- end
162
166
 
163
- def build option
164
- FileUtils.mkdir_p(tmp_path "") unless FileTest.exist?(tmp_path "")
165
-
166
- build_epub_metadata option
167
-
168
- if option['pandoc-json-output']
169
- cmd_exec "cd #{tmp_path ""};"+ pandoc_cmd, ["-o", json_path, "-t", "json"].concat(pandoc_option option).concat(vars_option).concat(meta_option).concat(@book.src_files.map{ |f| f.full_path }), option
167
+ class CallLatexBuilder < CallBuilder
168
+ dsl_accessor :template, default: 'template.tex'
169
+ dsl_accessor :filter, default: 'pandoc-filter.rb'
170
+ dsl_accessor :extractbb_cmd, default: 'extractbb'
171
+ dsl_accessor :pandoc_cmd, default: 'pandoc'
172
+ dsl_accessor :latex_cmd, default: 'uplatex'
173
+ dsl_accessor :dvipdfm_cmd, default: 'dvipdfmx'
174
+
175
+ def initialize(name, book)
176
+ @vars = []
177
+ @hyoushi = []
178
+ @urahyoushi = []
179
+ super name, book
180
+ end
181
+
182
+ def documentclass(param)
183
+ @vars << [:documentclass, param]
184
+ end
185
+
186
+ def classoption(param)
187
+ @vars << [:classoption, param]
188
+ end
189
+
190
+ def prepartname(param)
191
+ @vars << [:prepartname, param]
192
+ end
193
+
194
+ def postpartname(param)
195
+ @vars << [:postpartname, param]
196
+ end
197
+
198
+ def prechaptername(param)
199
+ @vars << [:prechaptername, param]
200
+ end
201
+
202
+ def postchaptername(param)
203
+ @vars << [:postchaptername, param]
204
+ end
205
+
206
+ def vars_option
207
+ result = []
208
+ @vars.concat([[:book_name, @book.name]]).each do |v|
209
+ result << '-V'
210
+ result << "#{v[0]}=#{v[1]}"
211
+ end
212
+ result
213
+ end
214
+
215
+ def template_option
216
+ "--template=#{Dir.getwd}/theme/#{theme}/#{@name}/#{template}"
217
+ end
218
+
219
+ def filter_option
220
+ "--filter=#{Dir.getwd}/theme/#{theme}/#{@name}/#{filter}"
221
+ end
222
+
223
+ def tex_path
224
+ tmp_path(@book.name) + '.tex'
225
+ end
226
+
227
+ def json_path
228
+ tmp_path(@book.name) + '.json'
229
+ end
230
+
231
+ def dvi_path
232
+ tmp_path(@book.name) + '.dvi'
233
+ end
234
+
235
+ def pdf_path
236
+ if output
237
+ output_path(output) + '.pdf'
238
+ else
239
+ output_path(@book.name) + '.pdf'
240
+ end
241
+ end
242
+
243
+ def _build_resource(files, option)
244
+ copy_to_tmp files
245
+ files.each do |file|
246
+ xbb = File.dirname(tmp_path(file.file)) + '/' + File.basename(tmp_path(file.file), '.*') + '.xbb'
247
+ unless FileTest.exist?(xbb) && File.mtime(tmp_path(file.file)) <= File.mtime(xbb)
248
+ cmd_exec "cd #{Shellwords.shellescape(File.dirname(tmp_path(file.file)))};#{extractbb_cmd}", [File.basename(file.file)], option
249
+ end
250
+ end
251
+ end
252
+
253
+ def build_resource(option)
254
+ _build_resource @book.resource_files, option
255
+ end
256
+
257
+ def pandoc_option(_option)
258
+ [
259
+ '--chapters',
260
+ '-f',
261
+ 'markdown_phpextra+hard_line_breaks+raw_tex',
262
+ '-s',
263
+ template_option,
264
+ filter_option
265
+ ]
266
+ end
267
+
268
+ def build(option)
269
+ FileUtils.mkdir_p(tmp_path('')) unless FileTest.exist?(tmp_path(''))
270
+
271
+ build_pandoc option
272
+ build_resource option
273
+ build_hyoushi option
274
+ build_latex option
275
+ build_pdf option
276
+ end
277
+
278
+ def build_pandoc(option)
279
+ pandoc_option = pandoc_option(option).concat(vars_option).concat(@book.src_files.map(&:full_path))
280
+ cmd_exec pandoc_cmd, ['-o', json_path, '-t', 'json'].concat(pandoc_option), option if option['pandoc-json-output']
281
+ cmd_exec pandoc_cmd, ['-o', tex_path, '-t', 'latex'].concat(pandoc_option), option
282
+ end
283
+
284
+ def build_latex(option)
285
+ cmd_exec latex_cmd, ["-output-directory=#{tmp_path('')}", tex_path], option
286
+ cmd_exec latex_cmd, ["-output-directory=#{tmp_path('')}", tex_path], option
287
+ end
288
+
289
+ def build_hyoushi(option)
290
+ open(tmp_path(@book.name + '.before_body.tex'), 'w') do |io|
291
+ io.puts @hyoushi.map { |h| h.latex @book, self } .join
292
+ end
293
+ open(tmp_path(@book.name + '.after_body.tex'), 'w') do |io|
294
+ io.puts @urahyoushi.map { |h| h.latex @book, self }.join
295
+ end
296
+ end
297
+
298
+ def build_pdf(option)
299
+ unless FileTest.exist?(pdf_path) && (File.mtime(dvi_path) <= File.mtime(pdf_path))
300
+ cmd_exec "cd #{Shellwords.shellescape(tmp_path(''))};#{dvipdfm_cmd}", ['-o', pdf_path, dvi_path], option
301
+ end
302
+ end
170
303
  end
171
- cmd_exec "cd #{tmp_path ""};"+ pandoc_cmd, ["-o", epub_path, "-t", "epub3"].concat(pandoc_option option).concat(vars_option).concat(meta_option).concat(@book.src_files.map{ |f| f.full_path }), option
172
- end
173
- end
174
304
 
175
- class CallLatexBuilder < CallBuilder
176
- dsl_accessor :template, :default => "template.tex"
177
- dsl_accessor :filter, :default => "pandoc-filter.rb"
178
- dsl_accessor :extractbb_cmd, :default => "extractbb"
179
- dsl_accessor :pandoc_cmd, :default => "pandoc"
180
- dsl_accessor :latex_cmd, :default => "uplatex"
181
- dsl_accessor :dvipdfm_cmd, :default => "dvipdfmx"
182
-
183
- def initialize name, book
184
- @vars = []
185
- @hyoushi = []
186
- @urahyoushi = []
187
- super name, book
188
- end
189
-
190
- def documentclass param
191
- @vars << [:documentclass, param]
192
- end
193
-
194
- def classoption param
195
- @vars << [:classoption, param]
196
- end
197
-
198
- def prepartname param
199
- @vars << [:prepartname, param]
200
- end
201
-
202
- def postpartname param
203
- @vars << [:postpartname, param]
204
- end
205
-
206
- def prechaptername param
207
- @vars << [:prechaptername, param]
208
- end
209
-
210
- def postchaptername param
211
- @vars << [:postchaptername, param]
212
- end
213
-
214
-
215
- def vars_option
216
- result = []
217
- @vars.concat([[:book_name, @book.name]]).each { |v|
218
- result << "-V"
219
- result << "#{v[0]}=#{v[1]}"
220
- }
221
- result
222
- end
223
-
224
- def template_option
225
- "--template=#{Dir::getwd}/theme/#{theme}/#{@name}/#{template}"
226
- end
227
-
228
- def filter_option
229
- "--filter=#{Dir::getwd}/theme/#{theme}/#{@name}/#{filter}"
230
- end
231
-
232
- def tex_path
233
- tmp_path(@book.name) + '.tex'
234
- end
235
-
236
- def json_path
237
- tmp_path(@book.name) + '.json'
238
- end
239
-
240
- def dvi_path
241
- tmp_path(@book.name) + '.dvi'
242
- end
243
-
244
- def pdf_path
245
- if output
246
- output_path(output) + '.pdf'
247
- else
248
- output_path(@book.name) + '.pdf'
249
- end
250
- end
251
-
252
- def _build_resource files, option
253
- copy_to_tmp files
254
- files.each { |file|
255
- xbb = File.dirname(tmp_path(file.file)) + "/" + File.basename(tmp_path(file.file), ".*") + ".xbb"
256
- unless FileTest.exist?(xbb) && File::mtime(tmp_path(file.file)) <= File::mtime(xbb)
257
- cmd_exec extractbb_cmd, [tmp_path(file.file)], option
258
- end
259
- }
260
- end
261
-
262
- def build_resource option
263
- _build_resource @book.resource_files, option
264
- end
265
-
266
- def pandoc_option option
267
- [
268
- "--chapters",
269
- "-f",
270
- "markdown_phpextra+hard_line_breaks+raw_tex",
271
- "-s",
272
- template_option,
273
- filter_option
274
- ]
275
- end
276
-
277
- def build option
278
- FileUtils.mkdir_p(tmp_path "") unless FileTest.exist?(tmp_path "")
279
- if option['pandoc-json-output']
280
- cmd_exec pandoc_cmd, ["-o", json_path, "-t", "json"].concat(pandoc_option option).concat(vars_option).concat(@book.src_files.map{ |f| f.full_path }), option
305
+ def epub_builder(name, &block)
306
+ call = CallEpubBuilder.new name, self
307
+ call.instance_eval(&block) if block
308
+ call.validate
309
+ @builders << call
281
310
  end
282
- cmd_exec pandoc_cmd, ["-o", tex_path, "-t", "latex"].concat(pandoc_option option).concat(vars_option).concat(@book.src_files.map{ |f| f.full_path }), option
283
311
 
284
- build_resource option
285
-
286
- f = open(tmp_path(@book.name + ".before_body.tex"), "w") do |io|
287
- io.puts @hyoushi.map { |h| h.latex @book, self} .join()
288
- end
289
-
290
- f = open(tmp_path(@book.name + ".after_body.tex"), "w") do |io|
291
- io.puts @urahyoushi.map { |h| h.latex @book, self }.join()
292
- end
293
- cmd_exec latex_cmd, ["-output-directory=#{tmp_path ""}", tex_path], option
294
- cmd_exec latex_cmd, ["-output-directory=#{tmp_path ""}", tex_path], option
295
- unless FileTest.exist?(pdf_path) && (File::mtime(dvi_path) <= File::mtime(pdf_path))
296
- cmd_exec "cd #{Shellwords.shellescape(tmp_path "")};#{dvipdfm_cmd}", ["-o", pdf_path, dvi_path], option
312
+ def latex_builder(name, &block)
313
+ call = CallLatexBuilder.new name, self
314
+ call.instance_eval(&block) if block
315
+ call.validate
316
+ @builders << call
297
317
  end
298
- end
299
- end
300
-
301
- def epub_builder name, &block
302
- call = CallEpubBuilder.new name, self
303
- if block
304
- call.instance_eval &block
305
- end
306
- call.validate
307
- @builders << call
308
- end
309
-
310
- def latex_builder name, &block
311
- call = CallLatexBuilder.new name, self
312
- if block
313
- call.instance_eval &block
314
- end
315
- call.validate
316
- @builders << call
317
318
  end
318
- end
319
319
  end