tmtms-review 1.0.0
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 +7 -0
- data/.travis.yml +9 -0
- data/COPYING +515 -0
- data/ChangeLog +2083 -0
- data/README.rdoc +50 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/bin/review-check +178 -0
- data/bin/review-checkdep +63 -0
- data/bin/review-compile +205 -0
- data/bin/review-epubmaker +661 -0
- data/bin/review-epubmaker-ng +176 -0
- data/bin/review-index +118 -0
- data/bin/review-pdfmaker +208 -0
- data/bin/review-preproc +142 -0
- data/bin/review-validate +51 -0
- data/bin/review-vol +102 -0
- data/debian/README.Debian +12 -0
- data/debian/README.source +5 -0
- data/debian/changelog +5 -0
- data/debian/compat +1 -0
- data/debian/control +22 -0
- data/debian/copyright +62 -0
- data/debian/docs +6 -0
- data/debian/manpage.1.ex +59 -0
- data/debian/patches/path.diff +91 -0
- data/debian/patches/series +1 -0
- data/debian/review.install +13 -0
- data/debian/review.links +4 -0
- data/debian/rules +13 -0
- data/debian/source/format +1 -0
- data/doc/format.rdoc +582 -0
- data/doc/format_idg.rdoc +180 -0
- data/doc/libepubmaker/sample.yaml +90 -0
- data/doc/quickstart.rdoc +188 -0
- data/doc/ruby-uuid/README +11 -0
- data/doc/ruby-uuid/README.ja +34 -0
- data/doc/sample.css +108 -0
- data/doc/sample.yaml +62 -0
- data/lib/epubmaker.rb +28 -0
- data/lib/epubmaker/content.rb +82 -0
- data/lib/epubmaker/epubv2.rb +418 -0
- data/lib/epubmaker/epubv3.rb +249 -0
- data/lib/epubmaker/producer.rb +204 -0
- data/lib/epubmaker/resource.rb +66 -0
- data/lib/lineinput.rb +155 -0
- data/lib/review.rb +3 -0
- data/lib/review/book.rb +46 -0
- data/lib/review/book/base.rb +235 -0
- data/lib/review/book/chapter.rb +81 -0
- data/lib/review/book/compilable.rb +159 -0
- data/lib/review/book/index.rb +339 -0
- data/lib/review/book/page_metric.rb +38 -0
- data/lib/review/book/parameters.rb +97 -0
- data/lib/review/book/part.rb +44 -0
- data/lib/review/book/volume.rb +65 -0
- data/lib/review/builder.rb +444 -0
- data/lib/review/compiler.rb +550 -0
- data/lib/review/configure.rb +38 -0
- data/lib/review/epubbuilder.rb +18 -0
- data/lib/review/exception.rb +21 -0
- data/lib/review/extentions.rb +3 -0
- data/lib/review/extentions/object.rb +9 -0
- data/lib/review/extentions/string.rb +33 -0
- data/lib/review/htmlbuilder.rb +1097 -0
- data/lib/review/htmllayout.rb +19 -0
- data/lib/review/htmlutils.rb +36 -0
- data/lib/review/i18n.rb +30 -0
- data/lib/review/i18n.yaml +34 -0
- data/lib/review/idgxmlbuilder.rb +1145 -0
- data/lib/review/latexbuilder.rb +815 -0
- data/lib/review/latexindex.rb +35 -0
- data/lib/review/latexutils.rb +79 -0
- data/lib/review/preprocessor.rb +563 -0
- data/lib/review/review.tex.erb +232 -0
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/textutils.rb +66 -0
- data/lib/review/tocparser.rb +342 -0
- data/lib/review/tocprinter.rb +221 -0
- data/lib/review/topbuilder.rb +785 -0
- data/lib/review/unfold.rb +138 -0
- data/lib/uuid.rb +312 -0
- data/review.gemspec +141 -0
- data/test/CHAPS +2 -0
- data/test/bib.re +13 -0
- data/test/book_test_helper.rb +35 -0
- data/test/test.re +43 -0
- data/test/test_book.rb +598 -0
- data/test/test_book_chapter.rb +418 -0
- data/test/test_book_parameter.rb +42 -0
- data/test/test_book_part.rb +50 -0
- data/test/test_builder.rb +144 -0
- data/test/test_compiler.rb +44 -0
- data/test/test_epubmaker.rb +507 -0
- data/test/test_helper.rb +27 -0
- data/test/test_htmlbuilder.rb +554 -0
- data/test/test_htmlutils.rb +28 -0
- data/test/test_i18n.rb +64 -0
- data/test/test_idgxmlbuilder.rb +589 -0
- data/test/test_index.rb +31 -0
- data/test/test_latexbuilder.rb +656 -0
- data/test/test_lineinput.rb +198 -0
- data/test/test_preprocessor.rb +23 -0
- data/test/test_textutils.rb +68 -0
- data/test/test_topbuilder.rb +244 -0
- data/test/test_uuid.rb +156 -0
- metadata +161 -0
data/README.rdoc
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
= ReVIEW
|
|
2
|
+
|
|
3
|
+
ReVIEW is a easy-to-use digital publishing system for books and ebooks.
|
|
4
|
+
|
|
5
|
+
== Format
|
|
6
|
+
|
|
7
|
+
ReVIEW uses its original format('ReVIEW format') as source files. See doc/format.rdoc (in Japanese).
|
|
8
|
+
|
|
9
|
+
Output formats ReVIEW supports are:
|
|
10
|
+
|
|
11
|
+
* EPUB
|
|
12
|
+
* LaTeX(ptexlive)
|
|
13
|
+
* InDesign(IDGXML)
|
|
14
|
+
* plain text(TOPBuilder Markup Lang.)
|
|
15
|
+
|
|
16
|
+
== Commands
|
|
17
|
+
|
|
18
|
+
There are two commands generate files directly.
|
|
19
|
+
|
|
20
|
+
* review-epubmaker: generate EPUB file.
|
|
21
|
+
* review-pdfmaker: generate PDF file using LaTeX(ptexlive).
|
|
22
|
+
|
|
23
|
+
And some useful commands.
|
|
24
|
+
|
|
25
|
+
* review-compile: compile ReVIEW fomat files.
|
|
26
|
+
* review-vol: figure out size of ReVIEW files.
|
|
27
|
+
* review-index: generate index with various format.
|
|
28
|
+
* review-preproc: preprocessor.
|
|
29
|
+
|
|
30
|
+
== Note on Patches/Pull Requests
|
|
31
|
+
|
|
32
|
+
* Fork the project.
|
|
33
|
+
* Make your feature addition or bug fix.
|
|
34
|
+
* Add tests for it. This is important so I don't break it in a
|
|
35
|
+
future version unintentionally.
|
|
36
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
37
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
38
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
39
|
+
|
|
40
|
+
== Build status
|
|
41
|
+
|
|
42
|
+
* {<img src="https://secure.travis-ci.org/kmuto/review.png"/>}[http://travis-ci.org/kmuto/review]
|
|
43
|
+
|
|
44
|
+
== License
|
|
45
|
+
|
|
46
|
+
LGPL. See COPYING file.
|
|
47
|
+
|
|
48
|
+
== Copyright
|
|
49
|
+
|
|
50
|
+
Copyright (c) 2006-2012 Minero Aoki, Kenshi Muto, Masayoshi Takahashi.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
require 'rake/clean'
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'jeweler'
|
|
8
|
+
Jeweler::Tasks.new do |gem|
|
|
9
|
+
gem.name = "review"
|
|
10
|
+
gem.summary = %Q{ReVIEW: a easy-to-use digital publishing system}
|
|
11
|
+
gem.description = %Q{ReVIEW is a digital publishing system for books and ebooks. It supports InDesign, EPUB and LaTeX.}
|
|
12
|
+
gem.email = "kmuto@debian.org"
|
|
13
|
+
gem.homepage = "http://github.com/kmuto/review"
|
|
14
|
+
gem.authors = ["kmuto", "takahashim"]
|
|
15
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
17
|
+
end
|
|
18
|
+
Jeweler::GemcutterTasks.new
|
|
19
|
+
rescue LoadError
|
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
task :default => [:test]
|
|
25
|
+
|
|
26
|
+
Rake::TestTask.new("test") do |t|
|
|
27
|
+
t.libs << "test"
|
|
28
|
+
t.test_files = Dir.glob("test/**/test_*.rb")
|
|
29
|
+
t.verbose = true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
require 'rcov/rcovtask'
|
|
34
|
+
Rcov::RcovTask.new do |t|
|
|
35
|
+
t.rcov_opts << '-x /gems/'
|
|
36
|
+
t.rcov_opts << '-x /tmp/'
|
|
37
|
+
t.libs << 'test'
|
|
38
|
+
t.pattern = 'test/test_*.rb'
|
|
39
|
+
t.verbose = true
|
|
40
|
+
end
|
|
41
|
+
rescue LoadError
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
begin
|
|
45
|
+
require 'rdoc/task'
|
|
46
|
+
rescue LoadError
|
|
47
|
+
require 'rake/rdoctask'
|
|
48
|
+
end
|
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
|
50
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
51
|
+
|
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
53
|
+
rdoc.title = "review #{version}"
|
|
54
|
+
rdoc.rdoc_files.include('README*')
|
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
56
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
data/bin/review-check
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
#
|
|
4
|
+
# Copyright (c) 1999-2007 Minero Aoki
|
|
5
|
+
# Copyright (c) 2010 Kenshi Muto, Minero Aoki
|
|
6
|
+
#
|
|
7
|
+
# This program is free software.
|
|
8
|
+
# You can distribute or modify this program under the terms of
|
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
|
10
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
require 'pathname'
|
|
14
|
+
|
|
15
|
+
bindir = Pathname.new(__FILE__).realpath.dirname
|
|
16
|
+
$LOAD_PATH.unshift((bindir + '../lib').realpath)
|
|
17
|
+
|
|
18
|
+
require 'review'
|
|
19
|
+
require 'optparse'
|
|
20
|
+
|
|
21
|
+
include ReVIEW::TextUtils
|
|
22
|
+
|
|
23
|
+
def sigmain
|
|
24
|
+
Signal.trap(:INT) { exit 1 }
|
|
25
|
+
if RUBY_PLATFORM !~ /mswin(?!ce)|mingw|cygwin|bccwin/
|
|
26
|
+
Signal.trap(:PIPE, 'IGNORE')
|
|
27
|
+
end
|
|
28
|
+
main
|
|
29
|
+
rescue Errno::EPIPE
|
|
30
|
+
exit 0
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def main
|
|
34
|
+
$KCODE = 'UTF-8' unless defined?(Encoding)
|
|
35
|
+
@param = {
|
|
36
|
+
"inencoding" => "UTF-8",
|
|
37
|
+
"outencoding" => "UTF-8"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
modes = nil
|
|
41
|
+
files = ARGV unless ARGV.empty?
|
|
42
|
+
parser = OptionParser.new
|
|
43
|
+
parser.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc|
|
|
44
|
+
@param["inencoding"] = enc
|
|
45
|
+
}
|
|
46
|
+
parser.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc|
|
|
47
|
+
@param["outencoding"] = enc
|
|
48
|
+
}
|
|
49
|
+
parser.on('-a', '--all-chapters', 'Check all chapters.') {
|
|
50
|
+
files = ReVIEW.book.chapters.map {|ent| ent.path }
|
|
51
|
+
}
|
|
52
|
+
parser.on('-s', '--section N', 'Check section N. (deprecated)') {|n|
|
|
53
|
+
ents = ReVIEW.env.parts[Integer(n) - 1] or
|
|
54
|
+
raise ReVIEW::ApplicationError, "section #{n} not exist"
|
|
55
|
+
files = ents.map {|ent| ent.path }
|
|
56
|
+
}
|
|
57
|
+
parser.on('--text', 'Check text.') {
|
|
58
|
+
(modes ||= []).push :text
|
|
59
|
+
}
|
|
60
|
+
parser.on('--help', 'print this message and quit.') {
|
|
61
|
+
puts parser.help
|
|
62
|
+
exit 0
|
|
63
|
+
}
|
|
64
|
+
begin
|
|
65
|
+
parser.parse!
|
|
66
|
+
rescue OptionParser::ParseError => err
|
|
67
|
+
$stderr.puts err.message
|
|
68
|
+
$stderr.puts parser.help
|
|
69
|
+
exit 1
|
|
70
|
+
end
|
|
71
|
+
unless files
|
|
72
|
+
$stderr.puts "no input"
|
|
73
|
+
exit 1
|
|
74
|
+
end
|
|
75
|
+
modes ||= [:text]
|
|
76
|
+
|
|
77
|
+
modes.each do |mode|
|
|
78
|
+
case mode
|
|
79
|
+
when :text
|
|
80
|
+
check_text files
|
|
81
|
+
else
|
|
82
|
+
raise 'must not happen'
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def check_text(files)
|
|
88
|
+
re, neg = words_re(ReVIEW.book.basedir + ReVIEW.book.reject_file)
|
|
89
|
+
files.each do |path|
|
|
90
|
+
File.open(path) {|f|
|
|
91
|
+
each_paragraph(f) do |para, lineno|
|
|
92
|
+
s = para.join('')
|
|
93
|
+
if m = re.match(s)
|
|
94
|
+
next if m[0] == $ReVIEW_utils_word_ok
|
|
95
|
+
next if neg and neg =~ s
|
|
96
|
+
str, offset = find_line(para, re)
|
|
97
|
+
out = sprintf("%s:%d: %s\n", path, lineno + offset, str)
|
|
98
|
+
print convert_outencoding(out, @param["outencoding"])
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
}
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def find_line(lines, re)
|
|
106
|
+
# single line?
|
|
107
|
+
lines.each_with_index do |line, idx|
|
|
108
|
+
return line.gsub(re, '<<<\&>>>'), idx if re =~ line
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# multiple lines?
|
|
112
|
+
i = 0
|
|
113
|
+
while i < lines.size - 1
|
|
114
|
+
str = lines[i] + lines[i+1]
|
|
115
|
+
return str.gsub(re, '<<<\&>>>'), i if re =~ str
|
|
116
|
+
i += 1
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
raise 'must not happen'
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def words_re(rc)
|
|
123
|
+
words = []
|
|
124
|
+
nega = []
|
|
125
|
+
File.foreach(rc) do |line|
|
|
126
|
+
next if line[0,1] == '#'
|
|
127
|
+
if / !/ =~ line
|
|
128
|
+
line, n = *line.split(/!/, 2)
|
|
129
|
+
nega.push n.strip
|
|
130
|
+
end
|
|
131
|
+
words.push line.strip
|
|
132
|
+
end
|
|
133
|
+
return Regexp.compile(words.join('|')),
|
|
134
|
+
nega.empty?() ? nil : Regexp.compile(nega.join('|'))
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def each_paragraph(f)
|
|
138
|
+
$ReVIEW_utils_word_ok = nil
|
|
139
|
+
while line = f.gets
|
|
140
|
+
line = convert_inencoding(line, @param["inencoding"])
|
|
141
|
+
|
|
142
|
+
case line
|
|
143
|
+
when /\A\#@ok\((.*)\)/
|
|
144
|
+
$ReVIEW_utils_word_ok = $1
|
|
145
|
+
when /\A\#@/
|
|
146
|
+
;
|
|
147
|
+
when %r[\A//caption\{(.*?)//\}]
|
|
148
|
+
yield [$1], f.filename, f.lineno
|
|
149
|
+
when %r<\A//\w.*\{\s*\z>
|
|
150
|
+
while line = f.gets
|
|
151
|
+
break if %r<//\}> === line
|
|
152
|
+
end
|
|
153
|
+
when /\A=/
|
|
154
|
+
yield [line.slice(/\A=+(?:\[.*?\])?\s+(.*)/, 1).strip], f.lineno
|
|
155
|
+
when /\A\s*\z/
|
|
156
|
+
# skip
|
|
157
|
+
else
|
|
158
|
+
buf = [line.strip]
|
|
159
|
+
lineno = f.lineno
|
|
160
|
+
while line = f.gets
|
|
161
|
+
break if line.strip.empty?
|
|
162
|
+
break if %r<\A(?:=|//[\w\}])> =~ line
|
|
163
|
+
next if %r<\A\#@> =~ line
|
|
164
|
+
buf.push line.strip
|
|
165
|
+
end
|
|
166
|
+
yield buf, lineno
|
|
167
|
+
$ReVIEW_utils_word_ok = nil
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def each_paragraph_line(f, &block)
|
|
173
|
+
each_paragraph(f) do |para, *|
|
|
174
|
+
para.each(&block)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
sigmain
|
data/bin/review-checkdep
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# $Id: review-checkdep 3748 2007-12-24 07:06:06Z aamine $
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 1999-2007 Minero Aoki
|
|
6
|
+
#
|
|
7
|
+
# This program is free software.
|
|
8
|
+
# You can distribute or modify this program under the terms of
|
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
|
10
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
require 'pathname'
|
|
14
|
+
|
|
15
|
+
bindir = Pathname.new(__FILE__).realpath.dirname
|
|
16
|
+
$LOAD_PATH.unshift((bindir + '../lib').realpath)
|
|
17
|
+
|
|
18
|
+
PREDEF_FILE = 'PREDEF'
|
|
19
|
+
|
|
20
|
+
def main
|
|
21
|
+
@provided = parse_predefined()
|
|
22
|
+
@unprovided = {}
|
|
23
|
+
ARGF.each do |line|
|
|
24
|
+
case line
|
|
25
|
+
when /\A\#@require\((.*)\)/
|
|
26
|
+
kw = $1
|
|
27
|
+
unless @provided.key?(kw)
|
|
28
|
+
puts "#{location()}: not provided: #{kw}"
|
|
29
|
+
@unprovided[kw] = location()
|
|
30
|
+
end
|
|
31
|
+
when /\A\#@provide\((.*)\)/
|
|
32
|
+
provide $1
|
|
33
|
+
else
|
|
34
|
+
line.scan(/@<kw>\{(.*?)[,\}]/) do
|
|
35
|
+
provide $1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def provide(kw)
|
|
42
|
+
@provided[kw] ||= location()
|
|
43
|
+
if @unprovided[kw]
|
|
44
|
+
reqpos = @unprovided.delete(kw)
|
|
45
|
+
puts "#{location()}: provided now: #{kw} (#{reqpos})"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def parse_predefined
|
|
50
|
+
result = {}
|
|
51
|
+
File.foreach(PREDEF_FILE) do |line|
|
|
52
|
+
result[line.strip] = '(predefined)'
|
|
53
|
+
end
|
|
54
|
+
result
|
|
55
|
+
rescue Errno::ENOENT
|
|
56
|
+
return {}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def location
|
|
60
|
+
"#{ARGF.filename}:#{ARGF.file.lineno}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
main
|
data/bin/review-compile
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# $Id: review-compile 4326 2010-01-12 14:10:17Z kmuto $
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 1999-2007 Minero Aoki
|
|
6
|
+
#
|
|
7
|
+
# This program is free software.
|
|
8
|
+
# You can distribute or modify this program under the terms of
|
|
9
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
|
10
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
require 'pathname'
|
|
14
|
+
|
|
15
|
+
bindir = Pathname.new(__FILE__).realpath.dirname
|
|
16
|
+
$LOAD_PATH.unshift((bindir + '../lib').realpath)
|
|
17
|
+
|
|
18
|
+
require 'review'
|
|
19
|
+
require 'review/compiler'
|
|
20
|
+
require 'review/book'
|
|
21
|
+
require 'fileutils'
|
|
22
|
+
require 'optparse'
|
|
23
|
+
|
|
24
|
+
def main
|
|
25
|
+
Signal.trap(:INT) { exit 1 }
|
|
26
|
+
if RUBY_PLATFORM !~ /mswin(?!ce)|mingw|cygwin|bccwin/
|
|
27
|
+
Signal.trap(:PIPE, 'IGNORE')
|
|
28
|
+
end
|
|
29
|
+
_main
|
|
30
|
+
rescue Errno::EPIPE
|
|
31
|
+
exit 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def _main
|
|
35
|
+
$KCODE = 'UTF-8' unless defined?(Encoding)
|
|
36
|
+
|
|
37
|
+
mode = :files
|
|
38
|
+
basedir = nil
|
|
39
|
+
if /\Areview2/ =~ File.basename($0)
|
|
40
|
+
target = File.basename($0, '.rb').sub(/review2/, '')
|
|
41
|
+
else
|
|
42
|
+
target = nil
|
|
43
|
+
end
|
|
44
|
+
check_only = false
|
|
45
|
+
output_filename = nil
|
|
46
|
+
|
|
47
|
+
param = {
|
|
48
|
+
"secnolevel" => 2, # for IDGXML and HTML
|
|
49
|
+
"tableopt" => nil, # for IDGXML
|
|
50
|
+
"nolf" => nil, # for IDGXML
|
|
51
|
+
"chapref" => nil, # for IDGXML
|
|
52
|
+
"structuredxml" => nil, # for IDGXML
|
|
53
|
+
"inencoding" => "UTF-8",
|
|
54
|
+
"outencoding" => "UTF-8",
|
|
55
|
+
"subdirmode" => nil,
|
|
56
|
+
"singledirmode" => nil,
|
|
57
|
+
"stylesheet" => [], # for HTML
|
|
58
|
+
"mathml" => nil, # for HTML
|
|
59
|
+
"language" => "ja", # for HTML
|
|
60
|
+
"deprecated-blocklines" => nil,
|
|
61
|
+
"footnotetext" => false,
|
|
62
|
+
"htmlext" => "html",
|
|
63
|
+
"htmlversion" => 4,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
parser = OptionParser.new
|
|
67
|
+
parser.banner = "Usage: #{File.basename($0)} [--target=FMT]"
|
|
68
|
+
parser.on('--yaml=YAML', 'Read configurations from YAML file.') do |yaml|
|
|
69
|
+
require 'yaml'
|
|
70
|
+
param = param.merge(YAML.load_file(yaml))
|
|
71
|
+
end
|
|
72
|
+
parser.on('--inencoding=ENCODING', 'Set input encoding. (UTF-8, EUC, JIS, and SJIS)') {|enc| param["inencoding"] = enc }
|
|
73
|
+
parser.on('--outencoding=ENCODING', 'Set output encoding. (UTF-8[default], EUC, JIS, and SJIS)') {|enc| param["outencoding"] = enc }
|
|
74
|
+
parser.on('-c', '--check', 'Check manuscript') { check_only = true }
|
|
75
|
+
parser.on('--level=LVL', 'Section level to append number.') {|lvl| param["secnolevel"] = lvl.to_i }
|
|
76
|
+
parser.on('--toclevel=LVL', 'Section level to append number.') {|lvl| param["toclevel"] = lvl.to_i }
|
|
77
|
+
parser.on('--nolfinxml', 'Do not insert LF in XML. (idgxml)') { param["nolf"] = true }
|
|
78
|
+
parser.on('--structuredxml', 'Produce XML with structured sections. (idgxml)') { param["structuredxml"] = true }
|
|
79
|
+
parser.on('--table=WIDTH', 'Default table width. (idgxml)') {|tbl| param["tableopt"] = tbl }
|
|
80
|
+
parser.on('--listinfo', 'Append listinfo tag to lists to indicate begin/end. (idgxml)') { param["listinfo"] = true }
|
|
81
|
+
parser.on('--chapref="before,middle,after"', 'Chapref decoration.') {|cdec| param["chapref"] = cdec }
|
|
82
|
+
parser.on('--subdirmode', 'Use chapter/id.ext path style to find images.') { param["subdirmode"] = true }
|
|
83
|
+
parser.on('--singledirmode', 'Use id.ext path style to find images.') { param["singledirmode"] = true }
|
|
84
|
+
parser.on('--chapterlink', 'make chapref hyperlink') { param["chapterlink"] = true }
|
|
85
|
+
parser.on('--stylesheet=file', 'Stylesheet file for HTML (comma separated)') {|files| param["stylesheet"] = files.split(/\s*,\s*/) }
|
|
86
|
+
parser.on('--mathml', 'Use MathML for TeX equation in HTML') do
|
|
87
|
+
param["mathml"] = true
|
|
88
|
+
require 'math_ml'
|
|
89
|
+
end
|
|
90
|
+
parser.on('--htmlversion=VERSION', 'HTML version.') do |v|
|
|
91
|
+
v = v.to_i
|
|
92
|
+
param["htmlversion"] = v if v == 4 || v == 5
|
|
93
|
+
end
|
|
94
|
+
parser.on('--hdnumberingmode', 'Output numbering headlines. (deprecated)') { param["hdnumberingmode"] = true }
|
|
95
|
+
parser.on('--deprecated-blocklines', 'Disable paragrahs in block tags. Treat physical line as a paragraph. (deprecated)') { param["deprecated-blocklines"] = true }
|
|
96
|
+
parser.on('--target=FMT', 'Target format.') {|fmt| target = fmt } unless target
|
|
97
|
+
parser.on('--footnotetext',
|
|
98
|
+
'Use footnotetext and footnotemark instead of footnote (latex)') {
|
|
99
|
+
param["footnotetext"] = true
|
|
100
|
+
}
|
|
101
|
+
parser.on('--draft', 'use draft mode(inline comment)') { param["draft"] = true }
|
|
102
|
+
parser.on('-a', '--all', 'Compile all chapters.') do
|
|
103
|
+
mode = :dir
|
|
104
|
+
basedir = nil
|
|
105
|
+
end
|
|
106
|
+
parser.on('--directory=DIR', 'Compile all chapters in DIR.') do |path|
|
|
107
|
+
mode = :dir
|
|
108
|
+
basedir = path
|
|
109
|
+
end
|
|
110
|
+
parser.on('--output-file=FILENAME', 'Write all results into file instead of stdout.') do |filename|
|
|
111
|
+
output_filename = filename
|
|
112
|
+
end
|
|
113
|
+
parser.on('--tabwidth=WIDTH', 'tab width') {|width| param["tabwidth"] = width.to_i }
|
|
114
|
+
parser.on('--help', 'Prints this message and quit.') do
|
|
115
|
+
puts parser.help
|
|
116
|
+
exit 0
|
|
117
|
+
end
|
|
118
|
+
begin
|
|
119
|
+
parser.parse!
|
|
120
|
+
unless target
|
|
121
|
+
if check_only
|
|
122
|
+
target = 'html'
|
|
123
|
+
else
|
|
124
|
+
raise OptionParser::ParseError, "no target given"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
rescue OptionParser::ParseError => err
|
|
128
|
+
error err.message
|
|
129
|
+
$stderr.puts parser.help
|
|
130
|
+
exit 1
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
begin
|
|
134
|
+
ReVIEW.book.param = param
|
|
135
|
+
compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
|
|
136
|
+
case mode
|
|
137
|
+
when :files
|
|
138
|
+
if ARGV.empty?
|
|
139
|
+
error 'no input'
|
|
140
|
+
exit 1
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
begin
|
|
144
|
+
ReVIEW::Book::Chapter.intern_pathes(ARGV).each do |chap|
|
|
145
|
+
result = compiler.compile(chap)
|
|
146
|
+
if output_filename
|
|
147
|
+
write output_filename, result
|
|
148
|
+
else
|
|
149
|
+
puts result unless check_only
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
rescue => e
|
|
153
|
+
# PART
|
|
154
|
+
part = ReVIEW.book.parts_in_file.select{|part| ARGV.include? part.path }
|
|
155
|
+
if part.present?
|
|
156
|
+
result = compiler.compile(part.first)
|
|
157
|
+
if output_filename
|
|
158
|
+
write output_filename, result
|
|
159
|
+
else
|
|
160
|
+
puts result unless check_only
|
|
161
|
+
end
|
|
162
|
+
else
|
|
163
|
+
raise e
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
when :dir
|
|
167
|
+
book = basedir ? ReVIEW::Book.load(basedir) : ReVIEW.book
|
|
168
|
+
book.chapters.each do |chap|
|
|
169
|
+
str = compiler.compile(chap)
|
|
170
|
+
write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
|
|
171
|
+
end
|
|
172
|
+
# PART
|
|
173
|
+
book.parts_in_file.each do |part|
|
|
174
|
+
str = compiler.compile(part)
|
|
175
|
+
if compiler.strategy.extname == ".tex"
|
|
176
|
+
str.gsub!(/\A\\chapter\{/, '\part{') # FIXME: UGLY...
|
|
177
|
+
end
|
|
178
|
+
write "#{part.name}#{compiler.strategy.extname}", str unless check_only
|
|
179
|
+
end
|
|
180
|
+
else
|
|
181
|
+
raise "must not happen: #{mode}"
|
|
182
|
+
end
|
|
183
|
+
rescue ReVIEW::ApplicationError => err
|
|
184
|
+
raise if $DEBUG
|
|
185
|
+
error err.message
|
|
186
|
+
exit 1
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def error(msg)
|
|
191
|
+
$stderr.puts "#{File.basename($0, '.*')}: error: #{msg}"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def load_strategy_class(target, strict)
|
|
195
|
+
require "review/#{target}builder"
|
|
196
|
+
ReVIEW.const_get("#{target.upcase}Builder").new(strict)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def write(path, str)
|
|
200
|
+
File.open(path, 'w') {|f|
|
|
201
|
+
f.puts str
|
|
202
|
+
}
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
main
|