review 2.4.0 → 2.5.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.
Files changed (54) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +20 -5
  3. data/.travis.yml +2 -1
  4. data/NEWS.ja.md +93 -0
  5. data/NEWS.md +77 -0
  6. data/README.md +1 -1
  7. data/bin/review +38 -12
  8. data/bin/review-compile +106 -88
  9. data/bin/review-epubmaker +6 -1
  10. data/bin/review-init +21 -1
  11. data/bin/review-textmaker +16 -0
  12. data/doc/config.yml.sample +6 -1
  13. data/doc/format.ja.md +23 -0
  14. data/doc/format.md +20 -2
  15. data/doc/quickstart.ja.md +8 -4
  16. data/doc/quickstart.md +11 -8
  17. data/lib/review/book/base.rb +29 -18
  18. data/lib/review/book/index.rb +10 -5
  19. data/lib/review/builder.rb +58 -33
  20. data/lib/review/catalog.rb +30 -0
  21. data/lib/review/compiler.rb +53 -19
  22. data/lib/review/configure.rb +15 -14
  23. data/lib/review/epubmaker.rb +15 -4
  24. data/lib/review/htmlbuilder.rb +56 -24
  25. data/lib/review/idgxmlbuilder.rb +17 -7
  26. data/lib/review/latexbuilder.rb +113 -38
  27. data/lib/review/markdownbuilder.rb +12 -5
  28. data/lib/review/md2inaobuilder.rb +3 -1
  29. data/lib/review/pdfmaker.rb +23 -9
  30. data/lib/review/plaintextbuilder.rb +683 -0
  31. data/lib/review/rstbuilder.rb +30 -10
  32. data/lib/review/textmaker.rb +158 -0
  33. data/lib/review/textutils.rb +10 -1
  34. data/lib/review/topbuilder.rb +32 -417
  35. data/lib/review/version.rb +1 -1
  36. data/lib/review/webmaker.rb +29 -8
  37. data/review.gemspec +3 -4
  38. data/templates/html/layout-xhtml1.html.erb +0 -2
  39. data/templates/latex/layout.tex.erb +6 -4
  40. data/templates/web/html/layout-xhtml1.html.erb +0 -2
  41. data/test/book_test_helper.rb +1 -0
  42. data/test/run_test.rb +1 -1
  43. data/test/sample-book/src/Rakefile +19 -3
  44. data/test/syntax-book/Rakefile +19 -3
  45. data/test/test_catalog.rb +45 -0
  46. data/test/test_compiler.rb +8 -2
  47. data/test/test_htmlbuilder.rb +22 -0
  48. data/test/test_idgxmlbuilder.rb +22 -0
  49. data/test/test_index.rb +31 -0
  50. data/test/test_latexbuilder.rb +48 -16
  51. data/test/test_plaintextbuilder.rb +390 -0
  52. data/test/test_textutils.rb +2 -0
  53. data/test/test_topbuilder.rb +23 -1
  54. metadata +13 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 639a13776cef44b59eb3464cff41726186d37bb1
4
- data.tar.gz: f285c0fb10f02260f16797a412d65287fb035fda
2
+ SHA256:
3
+ metadata.gz: 3908a824bcb0197ea94ec2c8f88be8b4bef238ceb37c6b9616eab435ef8a3670
4
+ data.tar.gz: f80a98194a5be2f5493e631eaed6e271d4f130b64085b93e3507cff1314748cc
5
5
  SHA512:
6
- metadata.gz: 157a8ad3ee0078e7c2a3e3c2bc3fc18f9a2f7f56474384884f750b5ff4d13acdb4514d89777d4d418e315b25e909c3eb52f89a0e8b2411ea2fc23bea6a0091b9
7
- data.tar.gz: 4112950e237224284a1d04efb1b391f427acb043ab121040bfe11e0055a32c7a4a57b8c349755d693da7ea62a80709e9f1d7bf1a7666e194a5011bff13fccb67
6
+ metadata.gz: 7a482cd982b4afdca790bdf3ed47372c476d4e9eff104c85ed533b27ca3f385179df3cabd087c09b627a0f55c472d795e165d102dc998b3e9732acac9c177ace
7
+ data.tar.gz: d48dcfbc1dadd2d3ac9eb0c65165ea84202fe3b3aa5a49000af54834596f82d0ca9034368c4e9e88af825c02d47b8ff20f4fa92b309a9c3d32a242545888708b
@@ -28,8 +28,8 @@ Lint/AssignmentInCondition:
28
28
  Lint/ParenthesesAsGroupedExpression:
29
29
  Enabled: true
30
30
 
31
- Lint/RescueWithoutErrorClass:
32
- Enabled: false
31
+ #Lint/RescueWithoutErrorClass:
32
+ # Enabled: false
33
33
 
34
34
  Lint/UnderscorePrefixedVariableName:
35
35
  Enabled: true
@@ -113,10 +113,16 @@ Style/Encoding:
113
113
  Style/EmptyElse:
114
114
  Enabled: true
115
115
 
116
+ Style/EvalWithLocation:
117
+ Enabled: false
118
+
116
119
  Style/FormatString:
117
120
  EnforcedStyle: sprintf
118
121
  Enabled: true
119
122
 
123
+ Style/FormatStringToken:
124
+ Enabled: false
125
+
120
126
  Style/GuardClause:
121
127
  Enabled: false
122
128
 
@@ -124,7 +130,7 @@ Style/IfInsideElse:
124
130
  Enabled: false
125
131
 
126
132
  Style/IfUnlessModifier:
127
- Enabled: true
133
+ Enabled: false
128
134
 
129
135
  Style/MutableConstant:
130
136
  Enabled: false
@@ -184,6 +190,9 @@ Style/LineEndConcatenation:
184
190
  Style/MethodCallWithoutArgsParentheses:
185
191
  Enabled: true
186
192
 
193
+ Style/MixinUsage:
194
+ Enabled: false
195
+
187
196
  Style/MultilineBlockChain:
188
197
  Enabled: true
189
198
 
@@ -228,6 +237,9 @@ Style/RedundantSelf:
228
237
  Style/RegexpLiteral:
229
238
  Enabled: true
230
239
 
240
+ Style/RescueStandardError:
241
+ Enabled: false
242
+
231
243
  Style/Semicolon:
232
244
  Enabled: true
233
245
 
@@ -262,7 +274,7 @@ Style/UnneededPercentQ:
262
274
  Enabled: false
263
275
 
264
276
  Style/WhileUntilModifier:
265
- Enabled: true
277
+ Enabled: false
266
278
 
267
279
  #Style/YodaCondition:
268
280
  # Enabled: true
@@ -338,7 +350,7 @@ Layout/SpaceAroundOperators:
338
350
  Enabled: true
339
351
 
340
352
  Layout/SpaceBeforeBlockBraces:
341
- Enabled: true
353
+ Enabled: false
342
354
 
343
355
  Layout/SpaceBeforeComma:
344
356
  Enabled: true
@@ -349,6 +361,9 @@ Layout/SpaceInsideBlockBraces:
349
361
  Layout/SpaceInsideHashLiteralBraces:
350
362
  Enabled: true
351
363
 
364
+ Layout/SpaceInsideArrayLiteralBrackets:
365
+ Enabled: true
366
+
352
367
  Layout/SpaceInsideStringInterpolation:
353
368
  EnforcedStyle: no_space
354
369
  Enabled: true
@@ -6,11 +6,12 @@ before_install:
6
6
  - gem update bundler
7
7
 
8
8
  rvm:
9
- - 2.0
9
+ ## - 2.0
10
10
  - 2.1
11
11
  - 2.2
12
12
  - 2.3.3
13
13
  - 2.4.1
14
+ - 2.5.0
14
15
  ## - ruby-head
15
16
 
16
17
  branches:
data/NEWS.ja.md CHANGED
@@ -1,3 +1,96 @@
1
+ # Version 3.x (未リリース)
2
+
3
+ TODO:lib/review/version.rbとreview.gemspecの更新をすること
4
+
5
+ 以下は未マージ・開発中。なるべく入れたいが…
6
+
7
+ * 非互換の変更:LaTeX の `@<m>` によるインラインの数式の前後にスペースを入れるのを止めました ([#943])
8
+ * 機能追加:LaTeX から生成する PDF の圧縮レベルオプション指定 (`-z 9`、最大圧縮) を config.yml のサンプルに記載しました ([#935])
9
+ * 非互換の変更:`@<chapref>`、`@<column>` の展開文字列を locale.yml で変更しやすいようにしました ([#886])
10
+ * 非互換の変更:LaTeX の表紙 (`cover` パラメータ) と大扉 (`titlepage` パラメータ) は独立した設定となりました ([#848])
11
+ * 非互換の変更:インライン文字装飾の LaTeX への変換結果を `\textbf` ではなく `\reviewbold` のように抽象化した名前にしました ([#792])
12
+ * 非互換の変更:LaTeX でルビを表現できるよう pxrubrica パッケージを読み込むようにしました ([#655])
13
+ * 非互換の変更:LaTeX のコードリスト環境を jlisting から plistings パッケージに変更しました ([#635])
14
+ * 非互換の変更:LaTeX のハイパーリンクの枠線のデフォルトをなしにしました ([#808])
15
+ * 非互換の変更:LaTeX のコードリストを reviewlistblock 環境で囲むようにしました ([#916])
16
+ * 非互換の変更:LaTeX で geometry.sty を使うのを止めました ([#912])
17
+ * 非互換の変更・新機能:
18
+ * 機能追加:表のセル内で `@<br>{}` による改行ができるようにしました ([#668])
19
+ * 非互換の変更・新機能:複数の LaTeX レイアウトファイルから選択できるようにしました ([#812])
20
+
21
+ 非互換になるところはもう少し詳しく説明が必要そう
22
+
23
+ # Version 2.5.0
24
+
25
+ ## 新機能
26
+ * プレインテキストを出力する review-textmaker コマンドを用意しました ([#926])
27
+ * LaTeX 向けに、図版の BoudingBox の採取手段を変更する `pdfmaker/bbox` パラメータを追加しました ([#947])
28
+ * 新機能:空行を入れる命令 `//blankline` を追加しました ([#942])
29
+
30
+ ## 非互換の変更
31
+ * `//include` 命令は不完全でユーザーの混乱を招くため、削除しました ([#887])
32
+ * LaTeX において、見出しや図表キャプション内にある脚注は `\footnotemark` を暗黙に使うようにしました ([#841])
33
+ * EPUB および WebMaker の大扉では、印刷所 (prt) の代わりに出版社 (pbl) を記載するようにしました ([#927])
34
+
35
+ ## バグ修正
36
+ * column の終了が正しく動作しないのを修正しました ([#894])
37
+ * `@<hd>` 命令の使用時に内部エラーが出ることがあるのを修正しました ([#896])
38
+ * LaTeX において、キャプションが空のときに空行が入ってしまうのを修正しました ([#922])
39
+ * `//graph` 命令内で gnuplot を使用したときにエラーが発生するのを修正しました ([#931])
40
+ * Windows で review コマンドがエラーになるのを修正しました ([#940])
41
+ * Windows で EPUB 生成時に一時作業ファイルの削除エラーが発生するのを修正しました ([#946])
42
+
43
+ ## 機能強化
44
+ * `//note` などの囲み要素内で末尾に空行があるときに不要な空の段落が作成されるのを修正しました ([#882])
45
+ * `@<chap>` などで catalog.yml に存在しない ID を指定したときのエラーメッセージをわかりやすいものにしました ([#891])
46
+ * catalog.yml に UTF-8 BOM ヘッダがあっても正常に動作するようにしました ([#899])
47
+ * LaTeX の奥付の罫線の長さを固定幅ではなく紙面幅にしました ([#907])
48
+ * texstyle パラメータで配列による複数の TeX スタイルファイルの読み込みを許可するようにしました ([#908])
49
+ * 独自の Rakefile を利用するための `lib/tasks` フォルダを `review-init` コマンドで作成するようにしました ([#921])
50
+ * `review-init` コマンド実行時に、`doc` フォルダにドキュメントをコピーするようにしました ([#918])
51
+ * `review` コマンドのヘルプメッセージを追加しました ([#933])
52
+ * 存在しないあるいは壊れている YAML ファイルを読み込もうとしたときに妥当なエラーメッセージを出すようにしました ([#958])
53
+ * `@<img>` や `@<table>` などのインライン命令で存在しない ID を指定したときのエラーメッセージをわかりやすいものに統一しました ([#954])
54
+ * catalog.yml に存在しないファイルをコンパイルしようとしたときのエラーメッセージをわかりやすいものにしました ([#953])
55
+ * LaTeX において、table, imgtable, image, indepimage から変換した TeX ソースコードにコメントで ID を記述するようにしました(`\begin{reviewimage}%%sampleimg` など)。フック処理での書き換えを簡易化するための修正であり、通常のLaTeX(PDF)の出力には影響ありませんが、独自のフック処理を使用していたプロジェクトでは修正が必要になるかもしれません ([#937])
56
+
57
+ ## ドキュメント
58
+ * 画像ファイルの拡張子の探索順序を文書化しました ([#939])
59
+ * review-textmaker の説明を追加しました ([#944])
60
+
61
+ ## コントリビューターのみなさん
62
+ * [@kauplan](https://github.com/kauplan)
63
+ * [@krororo](https://github.com/krororo)
64
+ * [@mhidaka](https://github.com/mhidaka)
65
+ * [@Pegasus204](https://github.com/Pegasus204)
66
+
67
+ [#841]: https://github.com/kmuto/review/issues/841
68
+ [#882]: https://github.com/kmuto/review/issues/882
69
+ [#887]: https://github.com/kmuto/review/issues/887
70
+ [#891]: https://github.com/kmuto/review/issues/891
71
+ [#894]: https://github.com/kmuto/review/pull/894
72
+ [#896]: https://github.com/kmuto/review/issues/896
73
+ [#899]: https://github.com/kmuto/review/issues/899
74
+ [#907]: https://github.com/kmuto/review/pull/907
75
+ [#908]: https://github.com/kmuto/review/pull/908
76
+ [#918]: https://github.com/kmuto/review/issues/918
77
+ [#921]: https://github.com/kmuto/review/issues/921
78
+ [#922]: https://github.com/kmuto/review/pull/922
79
+ [#926]: https://github.com/kmuto/review/issues/926
80
+ [#927]: https://github.com/kmuto/review/pull/927
81
+ [#931]: https://github.com/kmuto/review/pull/931
82
+ [#933]: https://github.com/kmuto/review/issues/933
83
+ [#937]: https://github.com/kmuto/review/pull/937
84
+ [#939]: https://github.com/kmuto/review/pull/939
85
+ [#940]: https://github.com/kmuto/review/issues/940
86
+ [#942]: https://github.com/kmuto/review/issues/942
87
+ [#944]: https://github.com/kmuto/review/pull/944
88
+ [#946]: https://github.com/kmuto/review/issues/946
89
+ [#947]: https://github.com/kmuto/review/pull/947
90
+ [#953]: https://github.com/kmuto/review/issues/953
91
+ [#954]: https://github.com/kmuto/review/issues/954
92
+ [#958]: https://github.com/kmuto/review/issues/958
93
+
1
94
  # Version 2.4.0
2
95
 
3
96
  ## 新機能
data/NEWS.md CHANGED
@@ -1,3 +1,80 @@
1
+ # Version 2.5.0
2
+
3
+ ## New Features
4
+
5
+ * add a new maker command `review-textmaker` to output plain text files ([#926])
6
+ * LATEXBuilder: add a new parameter `pdfmaker/bbox` for settings of BoudingBox ([#947])
7
+ * add a new command `//blankline` ([#942])
8
+
9
+ ## Breaking Changes
10
+
11
+ * remove (incomplete) command `//include` ([#887])
12
+ * LATEXBuilder: use `\footnotemark` implicitly for captions and headings ([#841])
13
+ * EPUBMaker, WEBMaker: use `pbl` (publisher) instead of `prt` (printer) in titlepage ([#927])
14
+
15
+ ## Bug Fixes
16
+
17
+ * fix column closing ([#894])
18
+ * fix internal errors in `@<hd>` ([#896])
19
+ * LATEXBuilder: fix to ignore empty caption ([#922])
20
+ * fix invalid commmand errors in `//graph` when using gnuplot ([#931])
21
+ * fix errors of `review` command in Windows ([#940])
22
+ * EPUBMaker: fix error of removing temporary files in Windows ([#946])
23
+
24
+ ## Enhancements
25
+
26
+ * remove tailing empty lines in block (captionblocks) such as `//note`. ([#882])
27
+ * fix error messages when using non-existent ID of catalog.yml in inline commands such as `@<chap>` ([#891])
28
+ * ignore UTF-8 BOM in catalog.yml ([#899])
29
+ * LATEXBuilder: fix a length of horizontal line in colophon ([#907])
30
+ * allow to use multiple parameters of `texstyle` in config.yml ([#908])
31
+ * review-init: create `lib/tasks` folder to use original Rake commands ([#921])
32
+ * review-init: copy `doc` folder into the target project ([#918])
33
+ * add a help message of `review` ([#933])
34
+ * show appropriate error messages when using invalid or non-existent YAML files ([#958])
35
+ * show better error messages when using unknown ID in inline commands such as `@<img>` and `@<table>` ([#954])
36
+ * show better error messages when compiling a file not included in catalog.yml ([#953])
37
+ * LATEXBuilder: add IDs of `table`, `imgtable`, `image` and `indepimage` as comments (ex. `\begin{reviewimage}%%sampleimg`) ([#937])
38
+
39
+ ## Docs
40
+
41
+ * add the rule of searching image files with extension ([#939])
42
+ * add description of `review-textmaker` ([#944])
43
+
44
+ ## Contributors
45
+
46
+ * [@kauplan](https://github.com/kauplan)
47
+ * [@krororo](https://github.com/krororo)
48
+ * [@mhidaka](https://github.com/mhidaka)
49
+ * [@Pegasus204](https://github.com/Pegasus204)
50
+
51
+ [#841]: https://github.com/kmuto/review/issues/841
52
+ [#882]: https://github.com/kmuto/review/issues/882
53
+ [#887]: https://github.com/kmuto/review/issues/887
54
+ [#891]: https://github.com/kmuto/review/issues/891
55
+ [#894]: https://github.com/kmuto/review/pull/894
56
+ [#896]: https://github.com/kmuto/review/issues/896
57
+ [#899]: https://github.com/kmuto/review/issues/899
58
+ [#907]: https://github.com/kmuto/review/pull/907
59
+ [#908]: https://github.com/kmuto/review/pull/908
60
+ [#918]: https://github.com/kmuto/review/issues/918
61
+ [#921]: https://github.com/kmuto/review/issues/921
62
+ [#922]: https://github.com/kmuto/review/pull/922
63
+ [#926]: https://github.com/kmuto/review/issues/926
64
+ [#927]: https://github.com/kmuto/review/pull/927
65
+ [#931]: https://github.com/kmuto/review/pull/931
66
+ [#933]: https://github.com/kmuto/review/issues/933
67
+ [#937]: https://github.com/kmuto/review/pull/937
68
+ [#939]: https://github.com/kmuto/review/pull/939
69
+ [#940]: https://github.com/kmuto/review/issues/940
70
+ [#942]: https://github.com/kmuto/review/issues/942
71
+ [#944]: https://github.com/kmuto/review/pull/944
72
+ [#946]: https://github.com/kmuto/review/issues/946
73
+ [#947]: https://github.com/kmuto/review/pull/947
74
+ [#953]: https://github.com/kmuto/review/issues/953
75
+ [#954]: https://github.com/kmuto/review/issues/954
76
+ [#958]: https://github.com/kmuto/review/issues/958
77
+
1
78
  # Version 2.4.0
2
79
 
3
80
  ## New Features
data/README.md CHANGED
@@ -99,4 +99,4 @@ LGPL. See [COPYING](https://github.com/kmuto/review/blob/master/COPYING) file.
99
99
 
100
100
  ## Copyright
101
101
 
102
- Copyright (c) 2006-2017 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado.
102
+ Copyright (c) 2006-2018 Minero Aoki, Kenshi Muto, Masayoshi Takahashi, Masanori Kado.
data/bin/review CHANGED
@@ -6,29 +6,48 @@
6
6
  # review epubmaker config.yml
7
7
  # -> call `review-epubmaker config.yml`
8
8
  #
9
+ # Copyright (c) 2017-2018 Kenshi Muto, Masayoshi Takahashi
10
+ #
11
+ # This program is free software.
12
+ # You can distribute or modify this program under the terms of
13
+ # the GNU LGPL, Lesser General Public License version 2.1.
14
+ # For details of the GNU LGPL, see the file "COPYING".
9
15
 
10
16
  require 'pathname'
17
+ bindir = Pathname.new(__FILE__).realpath.dirname
18
+ $LOAD_PATH.unshift((bindir + '../lib').realpath)
19
+
20
+ require 'review'
11
21
 
12
22
  def usage
13
23
  message = <<-EOB
14
24
  usage: review <command> [<args>]
15
25
 
16
- ReVIEW commands are:
17
- init
18
- preproc
19
- compile
20
- epubmaker
21
- pdfmaker
22
- vol
23
- check
24
- index
25
- validate
26
+ Re:VIEW commands are:
27
+ init : generate Re:VIEW project directory.
28
+ preproc : preprocess Re:VIEW document file.
29
+ compile : convert Re:VIEW document file.
30
+ epubmaker : build EPUB.
31
+ webmaker : build web pages.
32
+ pdfmaker : build PDF with LaTeX.
33
+ textmaker : build text files.
34
+ vol : show volume of Re:VIEW document.
35
+ check : check there are no REJECT words in the document.
36
+ index : show heading list.
37
+ validate : validate Re:VIEW document files.
38
+ version : show Re:VIEW version.
39
+ --help : show this message.
26
40
  EOB
27
41
  print message
28
42
  exit 1
29
43
  end
30
44
 
31
- usage if ARGV.length == 0
45
+ usage if ARGV.length == 0 || ARGV[0] == '--help'
46
+
47
+ if ARGV[0] == 'version'
48
+ puts ReVIEW::VERSION
49
+ exit
50
+ end
32
51
 
33
52
  command = "review-#{ARGV.shift}"
34
53
  bindir = Pathname.new(__FILE__).realpath.dirname
@@ -39,4 +58,11 @@ unless File.exist?(command_path)
39
58
  usage
40
59
  end
41
60
 
42
- exec(command_path, *ARGV)
61
+ if RUBY_PLATFORM =~ /mswin|bccwin|mingw/
62
+ cmd = File.join(RbConfig::CONFIG['bindir'],
63
+ RbConfig::CONFIG['ruby_install_name'])
64
+ cmd << RbConfig::CONFIG['EXEEXT']
65
+ exec(cmd, command_path, *ARGV)
66
+ else
67
+ exec(command_path, *ARGV)
68
+ end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (c) 2008-2017 Kenshi Muto, Masayoshi Takahashi, KADO Masanori, Minero Aoki
3
+ # Copyright (c) 2008-2018 Kenshi Muto, Masayoshi Takahashi, KADO Masanori, Minero Aoki
4
4
  # Copyright (c) 1999-2007 Minero Aoki
5
5
  #
6
6
  # This program is free software.
@@ -33,133 +33,151 @@ end
33
33
 
34
34
  def _main
35
35
  @logger = ReVIEW.logger
36
- mode = :files
37
- basedir = nil
36
+ @mode = :files
37
+ @basedir = nil
38
38
  if /\Areview2/ =~ File.basename($PROGRAM_NAME)
39
- target = File.basename($PROGRAM_NAME, '.rb').sub('review2', '')
39
+ @target = File.basename($PROGRAM_NAME, '.rb').sub('review2', '')
40
40
  else
41
- target = nil
41
+ @target = nil
42
42
  end
43
- check_only = false
44
- output_filename = nil
43
+ @check_only = false
44
+ @output_filename = nil
45
45
 
46
- config = ReVIEW::Configure.values
46
+ @config = ReVIEW::Configure.values
47
47
 
48
- opts = OptionParser.new
49
- opts.version = ReVIEW::VERSION
50
- opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [--target=FMT]"
51
- opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| config['yaml'] = yaml }
52
- opts.on('-c', '--check', 'Check manuscript') { check_only = true }
53
- opts.on('--level=LVL', 'Section level to append number.') { |lvl| config['secnolevel'] = lvl.to_i }
54
- opts.on('--toclevel=LVL', 'Section level to append number.') { |lvl| config['toclevel'] = lvl.to_i }
55
- opts.on('--structuredxml', 'Produce XML with structured sections. (idgxml)') { config['structuredxml'] = true }
56
- opts.on('--table=WIDTH', 'Default table width. (idgxml)') { |tbl| config['tableopt'] = tbl }
57
- opts.on('--listinfo', 'Append listinfo tag to lists to indicate begin/end. (idgxml)') { config['listinfo'] = true }
58
- opts.on('--chapref="before,middle,after"', 'Chapref decoration. (idgxml)') { |cdec| config['chapref'] = cdec }
59
- opts.on('--chapterlink', 'make chapref hyperlink') { config['chapterlink'] = true }
60
- opts.on('--stylesheet=file', 'Stylesheet file for HTML (comma separated)') { |files| config['stylesheet'] = files.split(/\s*,\s*/) }
61
- opts.on('--mathml', 'Use MathML for TeX equation in HTML') { config['mathml'] = true }
62
- opts.on('--htmlversion=VERSION', 'HTML version.') do |v|
63
- v = v.to_i
64
- config['htmlversion'] = v if [4, 5].include?(v)
65
- end
66
- opts.on('--epubversion=VERSION', 'EPUB version.') do |v|
67
- v = v.to_i
68
- config['epubversion'] = v if [2, 3].include?(v)
69
- end
70
- opts.on('--target=FMT', 'Target format.') { |fmt| target = fmt } unless target
71
- opts.on('--footnotetext',
72
- 'Use footnotetext and footnotemark instead of footnote (latex)') { config['footnotetext'] = true }
73
- opts.on('--draft', 'use draft mode(inline comment)') { config['draft'] = true }
74
- opts.on('--directory=DIR', 'Compile all chapters in DIR.') do |path|
75
- mode = :dir
76
- basedir = path
77
- end
78
- opts.on('--output-file=FILENAME', 'Write all results into file instead of stdout.') { |filename| output_filename = filename }
79
- opts.on('--tabwidth=WIDTH', 'tab width') { |width| config['tabwidth'] = width.to_i }
80
- opts.on('--catalogfile=FILENAME', 'Set catalog file') { |catalogfile| config['catalogfile'] = catalogfile }
81
- opts.on('--help', 'Prints this message and quit.') do
82
- puts opts.help
83
- exit 0
84
- end
85
- begin
86
- opts.parse!
87
-
88
- unless target
89
- if check_only
90
- target = 'html'
91
- else
92
- raise OptionParser::ParseError, 'no target given'
93
- end
94
- end
95
- rescue OptionParser::ParseError => err
96
- @logger.error(err.message)
97
- $stderr.puts opts.help
98
- exit 1
99
- end
48
+ parse_opts
100
49
 
101
50
  begin
102
51
  loader = ReVIEW::YAMLLoader.new
103
- if config['yaml']
104
- config.deep_merge!(loader.load_file(config['yaml']))
52
+ if @config['yaml']
53
+ error "#{config['yaml']} not found." unless File.exist?(@config['yaml'])
54
+ begin
55
+ @config.deep_merge!(loader.load_file(@config['yaml']))
56
+ rescue => e
57
+ error "yaml error #{e.message}"
58
+ end
105
59
  elsif File.exist?(DEFAULT_CONFIG_FILENAME)
106
- config.deep_merge!(loader.load_file(DEFAULT_CONFIG_FILENAME))
60
+ begin
61
+ @config.deep_merge!(loader.load_file(DEFAULT_CONFIG_FILENAME))
62
+ rescue => e
63
+ error "yaml error #{e.message}"
64
+ end
107
65
  end
108
66
 
109
- config['builder'] = target
110
- ReVIEW::I18n.setup(config['language'])
67
+ @config['builder'] = @target
68
+ ReVIEW::I18n.setup(@config['language'])
111
69
  begin
112
- config.check_version(ReVIEW::VERSION)
70
+ @config.check_version(ReVIEW::VERSION)
113
71
  rescue ReVIEW::ConfigError => e
114
- @logger.warn e.message
72
+ warn e.message
115
73
  end
116
74
 
117
- mode = :dir if ARGV.blank?
75
+ @mode = :dir if ARGV.blank?
118
76
 
119
- case mode
77
+ case @mode
120
78
  when :files
121
- if ARGV.empty?
122
- @logger.error('no input')
123
- exit 1
124
- end
79
+ error('no input') if ARGV.empty?
125
80
 
126
- basedir = File.dirname(ARGV[0])
127
- book = ReVIEW::Book::Base.load(basedir)
128
- book.config = config # needs only at the first time
81
+ @basedir = File.dirname(ARGV[0])
82
+ book = ReVIEW::Book::Base.load(@basedir)
83
+ book.config = @config # needs only at the first time
129
84
  ARGV.each do |item|
85
+ error("file not found: #{item}") unless File.exist?(item)
130
86
  chap_name = File.basename(item, '.*')
131
87
  chap = book.chapter(chap_name)
132
- compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
88
+ compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only))
133
89
  result = compiler.compile(chap)
134
- if output_filename
135
- write output_filename, result
90
+ if @output_filename
91
+ write @output_filename, result
136
92
  else
137
- puts result unless check_only
93
+ puts result unless @check_only
138
94
  end
139
95
  end
140
96
  when :dir
141
- book = basedir ? ReVIEW::Book.load(basedir) : ReVIEW::Book::Base.load
142
- book.config = config
143
- compiler = ReVIEW::Compiler.new(load_strategy_class(target, check_only))
97
+ book = @basedir ? ReVIEW::Book.load(@basedir) : ReVIEW::Book::Base.load
98
+ book.config = @config
99
+ compiler = ReVIEW::Compiler.new(load_strategy_class(@target, @check_only))
144
100
  book.chapters.each do |chap|
145
101
  str = compiler.compile(chap)
146
- write "#{chap.name}#{compiler.strategy.extname}", str unless check_only
102
+ write "#{chap.name}#{compiler.strategy.extname}", str unless @check_only
147
103
  end
148
104
  # PART
149
105
  book.parts_in_file.each do |part|
150
106
  str = compiler.compile(part)
151
- write "#{part.name}#{compiler.strategy.extname}", str unless check_only
107
+ write "#{part.name}#{compiler.strategy.extname}", str unless @check_only
152
108
  end
153
109
  else
154
- raise "must not happen: #{mode}"
110
+ raise "must not happen: #{@mode}"
155
111
  end
156
112
  rescue ReVIEW::ApplicationError => err
157
- raise if $DEBUG
158
- @logger.error(err.message)
113
+ error(err.message)
114
+ end
115
+ end
116
+
117
+ def parse_opts
118
+ opts = OptionParser.new
119
+ opts.version = ReVIEW::VERSION
120
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [--target=FMT]"
121
+ opts.on('--yaml=YAML', 'Read configurations from YAML file.') { |yaml| @config['yaml'] = yaml }
122
+ opts.on('-c', '--check', 'Check manuscript') { @check_only = true }
123
+ opts.on('--level=LVL', 'Section level to append number.') { |lvl| @config['secnolevel'] = lvl.to_i }
124
+ opts.on('--toclevel=LVL', 'Section level to append number.') { |lvl| @config['toclevel'] = lvl.to_i }
125
+ opts.on('--structuredxml', 'Produce XML with structured sections. (idgxml)') { @config['structuredxml'] = true }
126
+ opts.on('--table=WIDTH', 'Default table width. (idgxml)') { |tbl| @config['tableopt'] = tbl }
127
+ opts.on('--listinfo', 'Append listinfo tag to lists to indicate begin/end. (idgxml)') { @config['listinfo'] = true }
128
+ opts.on('--chapref="before,middle,after"', 'Chapref decoration. (idgxml)') { |cdec| @config['chapref'] = cdec }
129
+ opts.on('--chapterlink', 'make chapref hyperlink') { @config['chapterlink'] = true }
130
+ opts.on('--stylesheet=file', 'Stylesheet file for HTML (comma separated)') { |files| @config['stylesheet'] = files.split(/\s*,\s*/) }
131
+ opts.on('--mathml', 'Use MathML for TeX equation in HTML') { @config['mathml'] = true }
132
+ opts.on('--htmlversion=VERSION', 'HTML version.') do |v|
133
+ v = v.to_i
134
+ @config['htmlversion'] = v if [4, 5].include?(v)
135
+ end
136
+ opts.on('--epubversion=VERSION', 'EPUB version.') do |v|
137
+ v = v.to_i
138
+ @config['epubversion'] = v if [2, 3].include?(v)
139
+ end
140
+ opts.on('--target=FMT', 'Target format.') { |fmt| @target = fmt } unless @target
141
+ opts.on('--footnotetext',
142
+ 'Use footnotetext and footnotemark instead of footnote (latex)') { @config['footnotetext'] = true }
143
+ opts.on('--draft', 'use draft mode(inline comment)') { @config['draft'] = true }
144
+ opts.on('--directory=DIR', 'Compile all chapters in DIR.') do |path|
145
+ @mode = :dir
146
+ @basedir = path
147
+ end
148
+ opts.on('--output-file=FILENAME', 'Write all results into file instead of stdout.') { |filename| @output_filename = filename }
149
+ opts.on('--tabwidth=WIDTH', 'tab width') { |width| @config['tabwidth'] = width.to_i }
150
+ opts.on('--catalogfile=FILENAME', 'Set catalog file') { |catalogfile| @config['catalogfile'] = catalogfile }
151
+ opts.on('--help', 'Prints this message and quit.') do
152
+ puts opts.help
153
+ exit 0
154
+ end
155
+ begin
156
+ opts.parse!
157
+
158
+ unless @target
159
+ if @check_only
160
+ @target = 'html'
161
+ else
162
+ raise OptionParser::ParseError, 'no target given'
163
+ end
164
+ end
165
+ rescue OptionParser::ParseError => err
166
+ warn(err.message)
167
+ $stderr.puts opts.help
159
168
  exit 1
160
169
  end
161
170
  end
162
171
 
172
+ def error(msg)
173
+ @logger.error "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
174
+ exit 1
175
+ end
176
+
177
+ def warn(msg)
178
+ @logger.warn "#{File.basename($PROGRAM_NAME, '.*')}: #{msg}"
179
+ end
180
+
163
181
  def load_strategy_class(target, strict)
164
182
  require "review/#{target}builder"
165
183
  ReVIEW.const_get("#{target.upcase}Builder").new(strict)