review 1.2.0 → 1.3.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +36 -0
  3. data/.rubocop.yml +1 -0
  4. data/ChangeLog +102 -0
  5. data/README.rdoc +2 -2
  6. data/bin/review-check +18 -16
  7. data/bin/review-compile +49 -42
  8. data/bin/review-epubmaker +23 -993
  9. data/bin/review-epubmaker-legacy +1024 -0
  10. data/bin/review-index +17 -15
  11. data/bin/review-init +39 -9
  12. data/bin/review-pdfmaker +124 -89
  13. data/bin/review-preproc +16 -14
  14. data/bin/review-vol +17 -15
  15. data/debian/docs +1 -1
  16. data/doc/catalog.rdoc +34 -0
  17. data/doc/format.rdoc +16 -2
  18. data/doc/libepubmaker/{config.yaml → config.yml} +63 -19
  19. data/doc/quickstart.rdoc +1 -1
  20. data/doc/{sample.yaml → sample.yml} +0 -0
  21. data/lib/epubmaker.rb +1 -1
  22. data/lib/epubmaker/content.rb +9 -1
  23. data/lib/epubmaker/epubv2.rb +59 -7
  24. data/lib/epubmaker/epubv3.rb +14 -9
  25. data/lib/epubmaker/producer.rb +68 -27
  26. data/lib/epubmaker/resource.rb +3 -1
  27. data/lib/lineinput.rb +2 -2
  28. data/lib/review/book/base.rb +125 -24
  29. data/lib/review/book/chapter.rb +42 -0
  30. data/lib/review/book/compilable.rb +23 -4
  31. data/lib/review/book/image_finder.rb +64 -0
  32. data/lib/review/book/index.rb +64 -50
  33. data/lib/review/book/page_metric.rb +1 -1
  34. data/lib/review/builder.rb +19 -12
  35. data/lib/review/catalog.rb +47 -0
  36. data/lib/review/compiler.rb +3 -2
  37. data/lib/review/configure.rb +5 -3
  38. data/lib/review/epubmaker.rb +130 -46
  39. data/lib/review/ewbbuilder.rb +27 -31
  40. data/lib/review/extentions/string.rb +4 -4
  41. data/lib/review/htmlbuilder.rb +140 -79
  42. data/lib/review/htmllayout.rb +26 -4
  43. data/lib/review/htmlutils.rb +20 -1
  44. data/lib/review/i18n.rb +5 -2
  45. data/lib/review/{i18n.yaml → i18n.yml} +4 -2
  46. data/lib/review/idgxmlbuilder.rb +65 -39
  47. data/lib/review/latexbuilder.rb +72 -24
  48. data/lib/review/latexutils.rb +3 -1
  49. data/lib/review/makerhelper.rb +8 -2
  50. data/lib/review/preprocessor.rb +20 -20
  51. data/lib/review/review.tex.erb +4 -0
  52. data/lib/review/sec_counter.rb +9 -11
  53. data/lib/review/tocparser.rb +2 -2
  54. data/lib/review/tocprinter.rb +12 -12
  55. data/lib/review/topbuilder.rb +15 -15
  56. data/lib/review/version.rb +1 -1
  57. data/lib/uuid.rb +7 -7
  58. data/review.gemspec +2 -2
  59. data/rubocop-todo.yml +443 -0
  60. data/test/sample-book/src/config.yml +2 -2
  61. data/test/sample-book/src/{main.css → style.css} +0 -0
  62. data/test/test_book.rb +46 -48
  63. data/test/test_book_chapter.rb +25 -13
  64. data/test/test_builder.rb +3 -3
  65. data/test/test_catalog.rb +107 -0
  66. data/test/test_epubmaker.rb +6 -6
  67. data/test/test_htmlbuilder.rb +160 -39
  68. data/test/test_htmlutils.rb +22 -0
  69. data/test/test_i18n.rb +2 -2
  70. data/test/test_idgxmlbuilder.rb +33 -47
  71. data/test/test_image_finder.rb +82 -0
  72. data/test/test_inaobuilder.rb +1 -1
  73. data/test/test_latexbuilder.rb +35 -39
  74. data/test/test_lineinput.rb +2 -2
  75. data/test/test_markdownbuilder.rb +2 -2
  76. data/test/test_topbuilder.rb +39 -23
  77. metadata +23 -14
  78. data/bin/review-epubmaker-ng +0 -23
@@ -13,6 +13,7 @@
13
13
  require 'review/builder'
14
14
  require 'review/latexutils'
15
15
  require 'review/textutils'
16
+ require 'review/sec_counter'
16
17
 
17
18
  module ReVIEW
18
19
 
@@ -33,12 +34,12 @@ module ReVIEW
33
34
  end
34
35
 
35
36
  def builder_init_file
36
- #@index = indexes[:latex_index]
37
37
  @blank_needed = false
38
38
  @latex_tsize = nil
39
39
  @tsize = nil
40
40
  @table_caption = nil
41
41
  @ol_num = nil
42
+ @sec_counter = SecCounter.new(5, @chapter)
42
43
  end
43
44
  private :builder_init_file
44
45
 
@@ -74,18 +75,30 @@ module ReVIEW
74
75
  6 => 'subparagraph'
75
76
  }
76
77
 
78
+ def headline_prefix(level)
79
+ @sec_counter.inc(level)
80
+ anchor = @sec_counter.anchor(level)
81
+ prefix = @sec_counter.prefix(level, @book.config["secnolevel"])
82
+ [prefix, anchor]
83
+ end
84
+ private :headline_prefix
85
+
86
+
77
87
  def headline(level, label, caption)
88
+ _, anchor = headline_prefix(level)
78
89
  prefix = ""
79
- if level > ReVIEW.book.param["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
90
+ if level > @book.config["secnolevel"] || (@chapter.number.to_s.empty? && level > 1)
80
91
  prefix = "*"
81
92
  end
82
93
  blank unless @output.pos == 0
83
94
  puts macro(HEADLINE[level]+prefix, compile_inline(caption))
84
- if prefix == "*" && level <= ReVIEW.book.param["toclevel"].to_i
95
+ if prefix == "*" && level <= @book.config["toclevel"].to_i
85
96
  puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
86
97
  end
87
98
  if level == 1
88
99
  puts macro('label', chapter_label)
100
+ else
101
+ puts macro('label', sec_label(anchor))
89
102
  end
90
103
  rescue
91
104
  error "unknown level: #{level}"
@@ -102,8 +115,15 @@ module ReVIEW
102
115
  def column_begin(level, label, caption)
103
116
  blank
104
117
  puts "\\begin{reviewcolumn}\n"
118
+ if label
119
+ puts "\\hypertarget{#{column_label(label)}}{}"
120
+ else
121
+ puts "\\hypertarget{#{column_label(caption)}}{}"
122
+ end
105
123
  puts macro('reviewcolumnhead', nil, compile_inline(caption))
106
-
124
+ if level <= @book.config["toclevel"].to_i
125
+ puts "\\addcontentsline{toc}{#{HEADLINE[level]}}{#{compile_inline(caption)}}"
126
+ end
107
127
  end
108
128
 
109
129
  def column_end(level)
@@ -117,7 +137,7 @@ module ReVIEW
117
137
  puts "\\reviewminicolumntitle{#{compile_inline(caption)}}\n"
118
138
  end
119
139
 
120
- if ReVIEW.book.param["deprecated-blocklines"].nil?
140
+ if @book.config["deprecated-blocklines"].nil?
121
141
  blocked_lines = split_paragraph(lines)
122
142
  puts blocked_lines.join("\n\n")
123
143
  else
@@ -206,7 +226,7 @@ module ReVIEW
206
226
  blank
207
227
  end
208
228
 
209
- def parasep()
229
+ def parasep
210
230
  puts '\\parasep'
211
231
  end
212
232
 
@@ -214,7 +234,7 @@ module ReVIEW
214
234
  latex_block 'quotation', lines
215
235
  end
216
236
 
217
- alias lead read
237
+ alias_method :lead, :read
218
238
 
219
239
  def emlist(lines, caption = nil)
220
240
  blank
@@ -337,16 +357,22 @@ module ReVIEW
337
357
  end
338
358
  private :existence
339
359
 
340
- def image_label(id)
341
- "image:#{@chapter.id}:#{id}"
360
+ def image_label(id, chapter=nil)
361
+ chapter ||= @chapter
362
+ "image:#{chapter.id}:#{id}"
342
363
  end
343
364
  private :image_label
344
365
 
345
- def chapter_label()
366
+ def chapter_label
346
367
  "chap:#{@chapter.id}"
347
368
  end
348
369
  private :chapter_label
349
370
 
371
+ def sec_label(sec_anchor)
372
+ "sec:#{sec_anchor}"
373
+ end
374
+ private :sec_label
375
+
350
376
  def table_label(id)
351
377
  "table:#{@chapter.id}:#{id}"
352
378
  end
@@ -357,6 +383,13 @@ module ReVIEW
357
383
  end
358
384
  private :bib_label
359
385
 
386
+ def column_label(id)
387
+ filename = @chapter.id
388
+ num = @chapter.column(id).number
389
+ "column:#{filename}:#{num}"
390
+ end
391
+ private :column_label
392
+
360
393
  def indepimage(id, caption=nil, metric=nil)
361
394
  metrics = parse_metric("latex", metric)
362
395
  puts '\begin{reviewimage}'
@@ -372,7 +405,7 @@ module ReVIEW
372
405
  puts '\end{reviewimage}'
373
406
  end
374
407
 
375
- alias :numberlessimage indepimage
408
+ alias_method :numberlessimage, :indepimage
376
409
 
377
410
  def table(lines, id = nil, caption = nil)
378
411
  rows = []
@@ -478,7 +511,7 @@ module ReVIEW
478
511
  latex_block 'center', lines
479
512
  end
480
513
 
481
- alias centering center
514
+ alias_method :centering, :center
482
515
 
483
516
  def flushright(lines)
484
517
  latex_block 'flushright', lines
@@ -497,7 +530,7 @@ module ReVIEW
497
530
  def latex_block(type, lines)
498
531
  blank
499
532
  puts macro('begin', type)
500
- if ReVIEW.book.param["deprecated-blocklines"].nil?
533
+ if @book.config["deprecated-blocklines"].nil?
501
534
  blocked_lines = split_paragraph(lines)
502
535
  puts blocked_lines.join("\n\n")
503
536
  else
@@ -520,7 +553,7 @@ module ReVIEW
520
553
  def comment(lines, comment = nil)
521
554
  lines ||= []
522
555
  lines.unshift comment unless comment.blank?
523
- if ReVIEW.book.param["draft"]
556
+ if @book.config["draft"]
524
557
  str = lines.join("")
525
558
  puts macro('pdfcomment', escape(str))
526
559
  end
@@ -548,7 +581,7 @@ module ReVIEW
548
581
 
549
582
  def inline_chapref(id)
550
583
  title = super
551
- if ReVIEW.book.param["chapterlink"]
584
+ if @book.config["chapterlink"]
552
585
  "\\hyperref[chap:#{id}]{#{title}}"
553
586
  else
554
587
  title
@@ -559,7 +592,7 @@ module ReVIEW
559
592
  end
560
593
 
561
594
  def inline_chap(id)
562
- if ReVIEW.book.param["chapterlink"]
595
+ if @book.config["chapterlink"]
563
596
  "\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.number(id)}}"
564
597
  else
565
598
  @chapter.env.chapter_index.number(id)
@@ -570,7 +603,7 @@ module ReVIEW
570
603
  end
571
604
 
572
605
  def inline_title(id)
573
- if ReVIEW.book.param["chapterlink"]
606
+ if @book.config["chapterlink"]
574
607
  "\\hyperref[chap:#{id}]{#{@chapter.env.chapter_index.title(id)}}"
575
608
  else
576
609
  @chapter.env.chapter_index.title(id)
@@ -594,18 +627,18 @@ module ReVIEW
594
627
 
595
628
  def inline_img(id)
596
629
  chapter, id = extract_chapter_id(id)
597
- macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id))
630
+ macro('reviewimageref', "#{chapter.number}.#{chapter.image(id).number}", image_label(id, chapter))
598
631
  end
599
632
 
600
633
  def footnote(id, content)
601
- if ReVIEW.book.param["footnotetext"]
634
+ if @book.config["footnotetext"]
602
635
  puts macro("footnotetext[#{@chapter.footnote(id).number}]",
603
636
  compile_inline(content.strip))
604
637
  end
605
638
  end
606
639
 
607
640
  def inline_fn(id)
608
- if ReVIEW.book.param["footnotetext"]
641
+ if @book.config["footnotetext"]
609
642
  macro("footnotemark[#{@chapter.footnote(id).number}]", "")
610
643
  else
611
644
  macro('footnote', compile_inline(@chapter.footnote(id).content.strip))
@@ -639,7 +672,7 @@ module ReVIEW
639
672
 
640
673
  # index
641
674
  def inline_idx(str)
642
- text(str) + index(str)
675
+ escape(str) + index(str)
643
676
  end
644
677
 
645
678
  # hidden index??
@@ -692,7 +725,22 @@ module ReVIEW
692
725
  end
693
726
 
694
727
  def inline_hd_chap(chap, id)
695
- "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
728
+ n = chap.headline_index.number(id)
729
+ if chap.number and @book.config["secnolevel"] >= n.split('.').size
730
+ str = "「#{chap.headline_index.number(id)} #{compile_inline(chap.headline(id).caption)}」"
731
+ else
732
+ str = "「#{compile_inline(chap.headline(id).caption)}」"
733
+ end
734
+ if @book.config["chapterlink"]
735
+ anchor = n.gsub(/\./, "-")
736
+ macro('reviewsecref', str, sec_label(anchor))
737
+ else
738
+ str
739
+ end
740
+ end
741
+
742
+ def inline_column(id)
743
+ macro('reviewcolumnref', "#{@chapter.column(id).caption}", column_label(id))
696
744
  end
697
745
 
698
746
  def inline_raw(str)
@@ -733,7 +781,7 @@ module ReVIEW
733
781
  end
734
782
 
735
783
  def inline_comment(str)
736
- if ReVIEW.book.param["draft"]
784
+ if @book.config["draft"]
737
785
  macro('pdfcomment', escape(str))
738
786
  else
739
787
  ""
@@ -797,7 +845,7 @@ module ReVIEW
797
845
  end
798
846
 
799
847
  def image_ext
800
- "svg"
848
+ "pdf"
801
849
  end
802
850
 
803
851
  def olnum(num)
@@ -67,7 +67,7 @@ module ReVIEW
67
67
  }
68
68
  end
69
69
 
70
- alias escape escape_latex
70
+ alias_method :escape, :escape_latex
71
71
 
72
72
  def unescape_latex(str)
73
73
  metachars_invert_re = Regexp.new(METACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
@@ -76,6 +76,8 @@ module ReVIEW
76
76
  }
77
77
  end
78
78
 
79
+ alias_method :unescape, :unescape_latex
80
+
79
81
  def escape_index(str)
80
82
  str.gsub(/[@!|"]/) {|s| '"' + s }
81
83
  end
@@ -1,15 +1,21 @@
1
1
  # encoding: utf-8
2
2
  #
3
- # Copyright (c) 2012 Yuto HAYAMIZU
3
+ # Copyright (c) 2012-2014 Yuto HAYAMIZU, Kenshi Muto
4
4
  #
5
5
  # This program is free software.
6
6
  # You can distribute or modify this program under the terms of
7
7
  # the GNU LGPL, Lesser General Public License version 2.1.
8
8
  # For details of the GNU LGPL, see the file "COPYING".
9
9
  #
10
+ require 'pathname'
11
+ require 'fileutils'
10
12
 
11
13
  module ReVIEW
12
14
  class MakerHelper
15
+ # Return review/bin directory
16
+ def self.bindir
17
+ Pathname.new("#{Pathname.new(__FILE__).realpath.dirname}/../../bin").realpath
18
+ end
13
19
 
14
20
  # Copy image files under from_dir to to_dir recursively
15
21
  # ==== Args
@@ -36,7 +42,7 @@ module ReVIEW
36
42
  if FileTest.directory?("#{from_dir}/#{fname}")
37
43
  image_files += copy_images_to_dir("#{from_dir}/#{fname}", "#{to_dir}/#{fname}", options)
38
44
  else
39
- Dir.mkdir(to_dir) unless File.exist?(to_dir)
45
+ FileUtils.mkdir_p(to_dir) unless File.exist?(to_dir)
40
46
 
41
47
  is_converted = false
42
48
  (options[:convert] || {}).each do |orig_type, conv_type|
@@ -24,22 +24,22 @@ module ReVIEW
24
24
  end
25
25
 
26
26
  def warn(msg)
27
- if @param["outencoding"] =~ /^EUC$/
27
+ if @config["outencoding"] =~ /^EUC$/
28
28
  msg = NKF.nkf("-W -e", msg)
29
- elsif @param["outencoding"] =~ /^SJIS$/
29
+ elsif @config["outencoding"] =~ /^SJIS$/
30
30
  msg = NKF.nkf("-W -s", msg)
31
- elsif @param["outencoding"] =~ /^JIS$/
31
+ elsif @config["outencoding"] =~ /^JIS$/
32
32
  msg = NKF.nkf("-W -j", msg)
33
33
  end
34
34
  $stderr.puts "#{location()}: warning: #{msg}"
35
35
  end
36
36
 
37
37
  def error(msg)
38
- if @param["outencoding"] =~ /^EUC$/
38
+ if @config["outencoding"] =~ /^EUC$/
39
39
  msg = NKF.nkf("-W -e", msg)
40
- elsif @param["outencoding"] =~ /^SJIS$/
40
+ elsif @config["outencoding"] =~ /^SJIS$/
41
41
  msg = NKF.nkf("-W -s", msg)
42
- elsif @param["outencoding"] =~ /^JIS$/
42
+ elsif @config["outencoding"] =~ /^JIS$/
43
43
  msg = NKF.nkf("-W -j", msg)
44
44
  end
45
45
  @errutils_err = true
@@ -106,7 +106,7 @@ module ReVIEW
106
106
 
107
107
  def initialize(repo, param)
108
108
  @repository = repo
109
- @param = param
109
+ @config = param
110
110
  end
111
111
 
112
112
  def process(inf, outf)
@@ -142,7 +142,7 @@ module ReVIEW
142
142
  @f.print out.string
143
143
  end
144
144
  skip_list f
145
-
145
+
146
146
  when /\A\#@mapfile/
147
147
  direc = parse_directive(line, 1, 'eval')
148
148
  path = expand(direc.arg)
@@ -166,7 +166,7 @@ module ReVIEW
166
166
  #error "unkown directive: #{line.strip}" unless known_directive?(op)
167
167
  warn "unkown directive: #{line.strip}" unless known_directive?(op)
168
168
  @f.print line
169
-
169
+
170
170
  when /\A\s*\z/ # empty line
171
171
  @f.puts
172
172
  else
@@ -185,21 +185,21 @@ module ReVIEW
185
185
 
186
186
  def convert_outencoding(*s)
187
187
  ine = ""
188
- if @param["inencoding"] =~ /^EUC$/i
188
+ if @config["inencoding"] =~ /^EUC$/i
189
189
  ine = "-E,"
190
- elsif @param["inencoding"] =~ /^SJIS$/i
190
+ elsif @config["inencoding"] =~ /^SJIS$/i
191
191
  ine = "-S,"
192
- elsif @param["inencoding"] =~ /^JIS$/i
192
+ elsif @config["inencoding"] =~ /^JIS$/i
193
193
  ine = "-J,"
194
- elsif @param["inencoding"] =~ /^UTF\-8$/i
194
+ elsif @config["inencoding"] =~ /^UTF\-8$/i
195
195
  ine = "-W,"
196
196
  end
197
197
 
198
- if @param["outencoding"] =~ /^EUC$/i
198
+ if @config["outencoding"] =~ /^EUC$/i
199
199
  NKF.nkf("#{ine} -m0x -e", *s)
200
- elsif @param["outencoding"] =~ /^SJIS$/i
200
+ elsif @config["outencoding"] =~ /^SJIS$/i
201
201
  NKF.nkf("#{ine} -m0x -s", *s)
202
- elsif @param["outencoding"] =~ /^JIS$/i
202
+ elsif @config["outencoding"] =~ /^JIS$/i
203
203
  NKF.nkf("#{ine} -m0x -j", *s)
204
204
  else
205
205
  NKF.nkf("#{ine} -m0x -w", *s)
@@ -395,7 +395,7 @@ module ReVIEW
395
395
 
396
396
  attr_reader :number
397
397
  attr_reader :string
398
- alias to_s string
398
+ alias_method :to_s, :string
399
399
 
400
400
  def edit
401
401
  self.class.new(@number, yield(@string))
@@ -418,7 +418,7 @@ module ReVIEW
418
418
 
419
419
  def initialize(param)
420
420
  @repository = {}
421
- @param = param
421
+ @config = param
422
422
  end
423
423
 
424
424
  def fetch_file(file)
@@ -538,8 +538,8 @@ module ReVIEW
538
538
 
539
539
  def canonical(line)
540
540
  tabwidth = 8
541
- if @param['tabwidth']
542
- tabwidth = @param['tabwidth']
541
+ if @config['tabwidth']
542
+ tabwidth = @config['tabwidth']
543
543
  end
544
544
  if tabwidth > 0
545
545
  detab(line, tabwidth).rstrip + "\n"
@@ -114,6 +114,10 @@
114
114
  リスト #1}
115
115
  \newcommand{\reviewbibref}[2]{%
116
116
  #1}
117
+ \newcommand{\reviewcolumnref}[2]{%
118
+ コラム #1}
119
+ \newcommand{\reviewsecref}[2]{%
120
+ #1}
117
121
 
118
122
  \newcommand{\reviewminicolumntitle}[1]{%
119
123
  {\large ■メモ:#1}\\}
@@ -47,19 +47,17 @@ module ReVIEW
47
47
 
48
48
  if level == 1
49
49
  if secnolevel >= 1
50
- placeholder = if @chapter.is_a? ReVIEW::Book::Part
51
- 'part'
52
- elsif @chapter.on_POSTDEF?
53
- 'appendix'
54
- else
55
- 'chapter'
56
- end
57
- return "#{I18n.t(placeholder, @chapter.number)}#{I18n.t("chapter_postfix")}"
50
+ if @chapter.is_a? ReVIEW::Book::Part
51
+ num = @chapter.number
52
+ return "#{I18n.t('part', num)}#{I18n.t("chapter_postfix")}"
53
+ else
54
+ return "#{@chapter.format_number}#{I18n.t("chapter_postfix")}"
55
+ end
58
56
  end
59
57
  else
60
- if secnolevel >= level && !@chapter.on_POSTDEF?
61
- prefix = "#{@chapter.number}"
62
- 0.upto(level-2) do |i|
58
+ if secnolevel >= level
59
+ prefix = @chapter.format_number(false)
60
+ 0.upto(level - 2) do |i|
63
61
  prefix << ".#{@counter[i]}"
64
62
  end
65
63
  prefix << I18n.t("chapter_postfix")