review-peg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +605 -0
- data/.travis.yml +18 -0
- data/COPYING +515 -0
- data/ChangeLog +2449 -0
- data/Dockerfile +22 -0
- data/Gemfile +6 -0
- data/README.rdoc +81 -0
- data/Rakefile +51 -0
- data/bin/review-catalog-converter-peg +129 -0
- data/bin/review-check-peg +169 -0
- data/bin/review-checkdep-peg +63 -0
- data/bin/review-compile-peg +202 -0
- data/bin/review-epubmaker-legacy-peg +1024 -0
- data/bin/review-epubmaker-peg +44 -0
- data/bin/review-index-peg +110 -0
- data/bin/review-init-peg +151 -0
- data/bin/review-pdfmaker-peg +18 -0
- data/bin/review-preproc-peg +131 -0
- data/bin/review-validate-peg +51 -0
- data/bin/review-vol-peg +100 -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/NEWS.ja.md +350 -0
- data/doc/NEWS.md +354 -0
- data/doc/catalog.ja.md +53 -0
- data/doc/catalog.md +52 -0
- data/doc/format.ja.md +734 -0
- data/doc/format.md +746 -0
- data/doc/format_idg.ja.md +203 -0
- data/doc/quickstart.ja.md +222 -0
- data/doc/quickstart.md +252 -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.yml +238 -0
- data/lib/epubmaker.rb +24 -0
- data/lib/epubmaker/content.rb +93 -0
- data/lib/epubmaker/epubcommon.rb +424 -0
- data/lib/epubmaker/epubv2.rb +139 -0
- data/lib/epubmaker/epubv3.rb +222 -0
- data/lib/epubmaker/producer.rb +330 -0
- data/lib/lineinput.rb +107 -0
- data/lib/review.rb +3 -0
- data/lib/review/book.rb +43 -0
- data/lib/review/book/base.rb +401 -0
- data/lib/review/book/chapter.rb +100 -0
- data/lib/review/book/compilable.rb +184 -0
- data/lib/review/book/image_finder.rb +71 -0
- data/lib/review/book/index.rb +413 -0
- data/lib/review/book/page_metric.rb +47 -0
- data/lib/review/book/part.rb +54 -0
- data/lib/review/book/volume.rb +67 -0
- data/lib/review/builder.rb +452 -0
- data/lib/review/catalog.rb +52 -0
- data/lib/review/compiler.rb +5183 -0
- data/lib/review/compiler/literals_1_9.kpeg +22 -0
- data/lib/review/compiler/literals_1_9.rb +435 -0
- data/lib/review/configure.rb +64 -0
- data/lib/review/epubbuilder.rb +18 -0
- data/lib/review/epubmaker.rb +480 -0
- data/lib/review/ewbbuilder.rb +381 -0
- data/lib/review/exception.rb +21 -0
- data/lib/review/extentions.rb +4 -0
- data/lib/review/extentions/array.rb +25 -0
- data/lib/review/extentions/object.rb +9 -0
- data/lib/review/extentions/string.rb +33 -0
- data/lib/review/htmlbuilder.rb +1166 -0
- data/lib/review/htmllayout.rb +41 -0
- data/lib/review/htmltoc.rb +45 -0
- data/lib/review/htmlutils.rb +90 -0
- data/lib/review/i18n.rb +96 -0
- data/lib/review/i18n.yml +169 -0
- data/lib/review/idgxmlbuilder.rb +1233 -0
- data/lib/review/inaobuilder.rb +357 -0
- data/lib/review/latexbuilder.rb +941 -0
- data/lib/review/latexindex.rb +35 -0
- data/lib/review/latexutils.rb +95 -0
- data/lib/review/layout.tex.erb +340 -0
- data/lib/review/lineinput.rb +17 -0
- data/lib/review/location.rb +24 -0
- data/lib/review/makerhelper.rb +67 -0
- data/lib/review/markdownbuilder.rb +339 -0
- data/lib/review/node.rb +288 -0
- data/lib/review/pdfmaker.rb +332 -0
- data/lib/review/preprocessor.rb +530 -0
- data/lib/review/review.kpeg +745 -0
- data/lib/review/sec_counter.rb +69 -0
- data/lib/review/template.rb +21 -0
- data/lib/review/textbuilder.rb +17 -0
- data/lib/review/textutils.rb +16 -0
- data/lib/review/tocparser.rb +348 -0
- data/lib/review/tocprinter.rb +205 -0
- data/lib/review/topbuilder.rb +796 -0
- data/lib/review/unfold.rb +138 -0
- data/lib/review/version.rb +3 -0
- data/lib/uuid.rb +312 -0
- data/review.gemspec +32 -0
- data/templates/html/layout-html5.html.erb +17 -0
- data/templates/html/layout-xhtml1.html.erb +20 -0
- data/templates/ncx/epubv2.ncx.erb +11 -0
- data/templates/opf/epubv2.opf.erb +21 -0
- data/templates/opf/epubv3.opf.erb +18 -0
- data/templates/xml/container.xml.erb +6 -0
- data/test/CHAPS +2 -0
- data/test/assets/test.xml.erb +3 -0
- data/test/assets/test_template.tex +255 -0
- data/test/assets/test_template_backmatter.tex +32 -0
- data/test/bib.re +13 -0
- data/test/book_test_helper.rb +35 -0
- data/test/sample-book/README.md +7 -0
- data/test/sample-book/src/Rakefile +58 -0
- data/test/sample-book/src/_cover.html +3 -0
- data/test/sample-book/src/catalog.yml +10 -0
- data/test/sample-book/src/ch01.re +71 -0
- data/test/sample-book/src/ch02.re +3 -0
- data/test/sample-book/src/config.yml +186 -0
- data/test/sample-book/src/images/ch01-imgsample.jpg +0 -0
- data/test/sample-book/src/images/cover.jpg +0 -0
- data/test/sample-book/src/preface.re +15 -0
- data/test/sample-book/src/sty/jumoline.sty +310 -0
- data/test/sample-book/src/sty/reviewmacro.sty +39 -0
- data/test/sample-book/src/style.css +251 -0
- data/test/sample-book/src/vendor/jumoline/README +29 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.dtx +2988 -0
- data/test/sample-book/src/vendor/jumoline/jumoline.ins +6 -0
- data/test/test.re +43 -0
- data/test/test_book.rb +556 -0
- data/test/test_book_chapter.rb +280 -0
- data/test/test_book_part.rb +54 -0
- data/test/test_builder.rb +80 -0
- data/test/test_catalog.rb +119 -0
- data/test/test_catalog_converter_cmd.rb +73 -0
- data/test/test_compiler.rb +92 -0
- data/test/test_configure.rb +50 -0
- data/test/test_epub3maker.rb +529 -0
- data/test/test_epubmaker.rb +569 -0
- data/test/test_epubmaker_cmd.rb +40 -0
- data/test/test_helper.rb +92 -0
- data/test/test_htmlbuilder.rb +1114 -0
- data/test/test_htmltoc.rb +32 -0
- data/test/test_htmlutils.rb +50 -0
- data/test/test_i18n.rb +180 -0
- data/test/test_idgxmlbuilder.rb +608 -0
- data/test/test_image_finder.rb +82 -0
- data/test/test_inaobuilder.rb +245 -0
- data/test/test_index.rb +174 -0
- data/test/test_latexbuilder.rb +732 -0
- data/test/test_lineinput.rb +182 -0
- data/test/test_makerhelper.rb +66 -0
- data/test/test_markdownbuilder.rb +125 -0
- data/test/test_pdfmaker.rb +171 -0
- data/test/test_pdfmaker_cmd.rb +40 -0
- data/test/test_preprocessor.rb +23 -0
- data/test/test_review_ext.rb +31 -0
- data/test/test_template.rb +26 -0
- data/test/test_textutils.rb +32 -0
- data/test/test_topbuilder.rb +291 -0
- data/test/test_uuid.rb +157 -0
- metadata +357 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
|
3
|
+
#
|
4
|
+
# Copyright (c) 2002-2008 Minero Aoki
|
5
|
+
# 2009 Minero Aoki, Kenshi Muto
|
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
|
+
module ReVIEW
|
13
|
+
module Book
|
14
|
+
class PageMetric
|
15
|
+
|
16
|
+
MetricData = Struct.new(:n_lines, :n_columns)
|
17
|
+
|
18
|
+
def initialize(list_lines, list_columns, text_lines, text_columns, page_per_kbyte)
|
19
|
+
@list = MetricData.new(list_lines, list_columns)
|
20
|
+
@text = MetricData.new(text_lines, text_columns)
|
21
|
+
@page_per_kbyte = page_per_kbyte
|
22
|
+
end
|
23
|
+
|
24
|
+
A5 = PageMetric.new(46, 80, 30, 74, 1)
|
25
|
+
B5 = PageMetric.new(46, 80, 30, 74, 2)
|
26
|
+
|
27
|
+
# backward compatible
|
28
|
+
def PageMetric.a5
|
29
|
+
ReVIEW::Book::PageMetric::A5
|
30
|
+
end
|
31
|
+
|
32
|
+
# backward compatible
|
33
|
+
def PageMetric.b5
|
34
|
+
ReVIEW::Book::PageMetric::B5
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :list
|
38
|
+
attr_reader :text
|
39
|
+
attr_reader :page_per_kbyte
|
40
|
+
|
41
|
+
def ==(other)
|
42
|
+
self.list == other.list && self.text == other.text && self.page_per_kbyte == other.page_per_kbyte
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#
|
2
|
+
# $Id: book.rb 4315 2009-09-02 04:15:24Z kmuto $
|
3
|
+
#
|
4
|
+
# Copyright (c) 2002-2008 Minero Aoki
|
5
|
+
# 2009-2014 Minero Aoki, Kenshi Muto
|
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
|
+
require 'review/book/compilable'
|
13
|
+
module ReVIEW
|
14
|
+
module Book
|
15
|
+
class Part
|
16
|
+
include Compilable
|
17
|
+
|
18
|
+
def initialize(book, number, chapters, name="")
|
19
|
+
@book = book
|
20
|
+
@number = number
|
21
|
+
@chapters = chapters
|
22
|
+
@path = name
|
23
|
+
@name = name ? File.basename(name, '.re') : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :number
|
27
|
+
attr_reader :chapters
|
28
|
+
attr_reader :name
|
29
|
+
|
30
|
+
def each_chapter(&block)
|
31
|
+
@chapters.each(&block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def volume
|
35
|
+
vol = Volume.sum(@chapters.map {|chap| chap.volume })
|
36
|
+
vol.page_per_kbyte = @book.page_metric.page_per_kbyte
|
37
|
+
vol
|
38
|
+
end
|
39
|
+
|
40
|
+
def file?
|
41
|
+
(name.present? and path =~ /\.re\z/) ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def format_number(heading = true)
|
45
|
+
if heading
|
46
|
+
"#{I18n.t("part", @number)}"
|
47
|
+
else
|
48
|
+
"#{@number}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# $Id: volume.rb 3883 2008-02-10 11:48:23Z aamine $
|
3
|
+
#
|
4
|
+
# Copyright (c) 2002-2007 Minero Aoki
|
5
|
+
#
|
6
|
+
# This program is free software.
|
7
|
+
# You can distribute or modify this program under the terms of
|
8
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
9
|
+
# For details of the GNU LGPL, see the file "COPYING".
|
10
|
+
#
|
11
|
+
module ReVIEW
|
12
|
+
module Book
|
13
|
+
class Volume
|
14
|
+
|
15
|
+
def Volume.count_file(path)
|
16
|
+
b = c = l = 0
|
17
|
+
File.foreach(path) do |line|
|
18
|
+
next if %r<\A\#@> =~ line
|
19
|
+
text = line.gsub(/\s+/, '')
|
20
|
+
b += text.bytesize
|
21
|
+
c += text.charsize
|
22
|
+
l += 1
|
23
|
+
end
|
24
|
+
new(b, c, l)
|
25
|
+
end
|
26
|
+
|
27
|
+
def Volume.sum(vols)
|
28
|
+
vols.inject(new()) {|sum, i| sum + i }
|
29
|
+
end
|
30
|
+
|
31
|
+
def Volume.dummy
|
32
|
+
new(-1, -1, -1)
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(bytes = 0, chars = 0, lines = 0)
|
36
|
+
@bytes = bytes
|
37
|
+
@chars = chars
|
38
|
+
@lines = lines
|
39
|
+
@page_per_kbyte = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_reader :bytes
|
43
|
+
attr_reader :chars
|
44
|
+
attr_accessor :lines
|
45
|
+
attr_accessor :page_per_kbyte
|
46
|
+
|
47
|
+
def kbytes
|
48
|
+
(@bytes.to_f / 1024).ceil
|
49
|
+
end
|
50
|
+
|
51
|
+
def page
|
52
|
+
(kbytes.to_f/@page_per_kbyte).ceil
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
"#{kbytes()}KB #{@chars}C #{@lines}L #{page()}P"
|
57
|
+
end
|
58
|
+
|
59
|
+
def +(other)
|
60
|
+
Volume.new(@bytes + other.bytes,
|
61
|
+
@chars + other.chars,
|
62
|
+
@lines + other.lines)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,452 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Copyright (c) 2002-2014 Minero Aoki, Kenshi Muto
|
4
|
+
#
|
5
|
+
# This program is free software.
|
6
|
+
# You can distribute or modify this program under the terms of
|
7
|
+
# the GNU LGPL, Lesser General Public License version 2.1.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'review/book/index'
|
11
|
+
require 'review/exception'
|
12
|
+
require 'review/textutils'
|
13
|
+
require 'review/compiler'
|
14
|
+
require 'review/sec_counter'
|
15
|
+
require 'stringio'
|
16
|
+
require 'cgi'
|
17
|
+
|
18
|
+
module ReVIEW
|
19
|
+
|
20
|
+
class Builder
|
21
|
+
include TextUtils
|
22
|
+
|
23
|
+
CAPTION_TITLES = %w(note memo tip info planning best important security caution term link notice point shoot reference practice expert)
|
24
|
+
|
25
|
+
attr_accessor :output
|
26
|
+
attr_accessor :ast
|
27
|
+
|
28
|
+
def pre_paragraph
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
def post_paragraph
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(strict = false, *args)
|
36
|
+
@strict = strict
|
37
|
+
builder_init(*args)
|
38
|
+
end
|
39
|
+
|
40
|
+
def builder_init(*args)
|
41
|
+
end
|
42
|
+
private :builder_init
|
43
|
+
|
44
|
+
def bind(compiler, chapter, location)
|
45
|
+
@compiler = compiler
|
46
|
+
@chapter = chapter
|
47
|
+
@location = location
|
48
|
+
@ast = nil
|
49
|
+
@output = StringIO.new
|
50
|
+
@book = @chapter.book if @chapter.present?
|
51
|
+
@tabwidth = nil
|
52
|
+
if @book && @book.config && @book.config["tabwidth"]
|
53
|
+
@tabwidth = @book.config["tabwidth"]
|
54
|
+
end
|
55
|
+
builder_init_file
|
56
|
+
end
|
57
|
+
|
58
|
+
def builder_init_file
|
59
|
+
@sec_counter = SecCounter.new(5, @chapter)
|
60
|
+
end
|
61
|
+
private :builder_init_file
|
62
|
+
|
63
|
+
def result
|
64
|
+
@output.string
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method :raw_result, :result
|
68
|
+
|
69
|
+
def print(*s)
|
70
|
+
raise NotImplementedError, "XXX: `print` method is obsoleted. Do not use it."
|
71
|
+
end
|
72
|
+
|
73
|
+
def puts(*s)
|
74
|
+
raise NotImplementedError, "XXX: `puts` method is obsoleted. Do not use it."
|
75
|
+
end
|
76
|
+
|
77
|
+
def target_name
|
78
|
+
self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
|
79
|
+
end
|
80
|
+
|
81
|
+
def headline_prefix(level)
|
82
|
+
@sec_counter.inc(level)
|
83
|
+
anchor = @sec_counter.anchor(level)
|
84
|
+
prefix = @sec_counter.prefix(level, @book.config["secnolevel"])
|
85
|
+
[prefix, anchor]
|
86
|
+
end
|
87
|
+
private :headline_prefix
|
88
|
+
|
89
|
+
def list(lines, id, caption = nil, lang = nil)
|
90
|
+
buf = ""
|
91
|
+
begin
|
92
|
+
buf << list_header(id, caption, lang)
|
93
|
+
rescue KeyError
|
94
|
+
error "no such list: #{id}"
|
95
|
+
end
|
96
|
+
buf << list_body(id, lines, lang)
|
97
|
+
buf
|
98
|
+
end
|
99
|
+
|
100
|
+
def listnum(lines, id, caption = nil, lang = nil)
|
101
|
+
buf = ""
|
102
|
+
begin
|
103
|
+
buf << list_header(id, caption, lang)
|
104
|
+
rescue KeyError
|
105
|
+
error "no such list: #{id}"
|
106
|
+
end
|
107
|
+
buf << listnum_body(lines, lang)
|
108
|
+
buf
|
109
|
+
end
|
110
|
+
|
111
|
+
def source(lines, caption = nil)
|
112
|
+
buf = ""
|
113
|
+
buf << source_header(caption)
|
114
|
+
buf << source_body(lines, lang)
|
115
|
+
buf
|
116
|
+
end
|
117
|
+
|
118
|
+
def image(lines, id, caption, metric = nil)
|
119
|
+
if @chapter.image(id).bound?
|
120
|
+
image_image id, caption, metric
|
121
|
+
else
|
122
|
+
warn "image not bound: #{id}" if @strict
|
123
|
+
image_dummy id, caption, lines
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def table(lines, id = nil, caption = nil)
|
128
|
+
buf = ""
|
129
|
+
rows = []
|
130
|
+
sepidx = nil
|
131
|
+
lines.each_with_index do |line, idx|
|
132
|
+
if /\A[\=\-]{12}/ =~ line
|
133
|
+
# just ignore
|
134
|
+
#error "too many table separator" if sepidx
|
135
|
+
sepidx ||= idx
|
136
|
+
next
|
137
|
+
end
|
138
|
+
rows.push line.strip.split(/\t+/).map {|s| s.sub(/\A\./, '') }
|
139
|
+
end
|
140
|
+
rows = adjust_n_cols(rows)
|
141
|
+
|
142
|
+
begin
|
143
|
+
buf << table_header(id, caption) unless caption.nil?
|
144
|
+
rescue KeyError
|
145
|
+
error "no such table: #{id}"
|
146
|
+
end
|
147
|
+
return buf if rows.empty?
|
148
|
+
buf << table_begin(rows.first.size)
|
149
|
+
if sepidx
|
150
|
+
sepidx.times do
|
151
|
+
buf << tr(rows.shift.map {|s| th(s) })
|
152
|
+
end
|
153
|
+
rows.each do |cols|
|
154
|
+
buf << tr(cols.map {|s| td(s) })
|
155
|
+
end
|
156
|
+
else
|
157
|
+
rows.each do |cols|
|
158
|
+
h, *cs = *cols
|
159
|
+
buf << tr([th(h)] + cs.map {|s| td(s) })
|
160
|
+
end
|
161
|
+
end
|
162
|
+
buf << table_end
|
163
|
+
buf
|
164
|
+
end
|
165
|
+
|
166
|
+
def adjust_n_cols(rows)
|
167
|
+
rows.each do |cols|
|
168
|
+
while cols.last and cols.last.strip.empty?
|
169
|
+
cols.pop
|
170
|
+
end
|
171
|
+
end
|
172
|
+
n_maxcols = rows.map {|cols| cols.size }.max
|
173
|
+
rows.each do |cols|
|
174
|
+
cols.concat [''] * (n_maxcols - cols.size)
|
175
|
+
end
|
176
|
+
rows
|
177
|
+
end
|
178
|
+
private :adjust_n_cols
|
179
|
+
|
180
|
+
#def footnote(id, str)
|
181
|
+
# @footnotes.push [id, str]
|
182
|
+
#end
|
183
|
+
#
|
184
|
+
#def flush_footnote
|
185
|
+
# footnote_begin
|
186
|
+
# @footnotes.each do |id, str|
|
187
|
+
# footnote_item(id, str)
|
188
|
+
# end
|
189
|
+
# footnote_end
|
190
|
+
#end
|
191
|
+
|
192
|
+
# def compile_inline(s)
|
193
|
+
# @compiler.text(s)
|
194
|
+
# end
|
195
|
+
|
196
|
+
def inline_chapref(id)
|
197
|
+
@book.chapter_index.display_string(id)
|
198
|
+
rescue KeyError
|
199
|
+
error "unknown chapter: #{id}"
|
200
|
+
nofunc_text("[UnknownChapter:#{id}]")
|
201
|
+
end
|
202
|
+
|
203
|
+
def inline_chap(id)
|
204
|
+
@book.chapter_index.number(id)
|
205
|
+
rescue KeyError
|
206
|
+
error "unknown chapter: #{id}"
|
207
|
+
nofunc_text("[UnknownChapter:#{id}]")
|
208
|
+
end
|
209
|
+
|
210
|
+
def inline_title(id)
|
211
|
+
@book.chapter_index.title(id)
|
212
|
+
rescue KeyError
|
213
|
+
error "unknown chapter: #{id}"
|
214
|
+
nofunc_text("[UnknownChapter:#{id}]")
|
215
|
+
end
|
216
|
+
|
217
|
+
def inline_list(id)
|
218
|
+
"#{I18n.t("list")}#{@chapter.list(id).number}"
|
219
|
+
rescue KeyError
|
220
|
+
error "unknown list: #{id}"
|
221
|
+
nofunc_text("[UnknownList:#{id}]")
|
222
|
+
end
|
223
|
+
|
224
|
+
def inline_img(id)
|
225
|
+
"#{I18n.t("image")}#{@chapter.image(id).number}"
|
226
|
+
rescue KeyError
|
227
|
+
error "unknown image: #{id}"
|
228
|
+
nofunc_text("[UnknownImage:#{id}]")
|
229
|
+
end
|
230
|
+
|
231
|
+
def inline_imgref(id)
|
232
|
+
img = inline_img(id)
|
233
|
+
|
234
|
+
if @chapter.image(id).caption
|
235
|
+
"#{img}#{I18n.t('image_quote', @chapter.image(id).caption)}"
|
236
|
+
else
|
237
|
+
img
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def inline_table(id)
|
242
|
+
"#{I18n.t("table")}#{@chapter.table(id).number}"
|
243
|
+
rescue KeyError
|
244
|
+
error "unknown table: #{id}"
|
245
|
+
nofunc_text("[UnknownTable:#{id}]")
|
246
|
+
end
|
247
|
+
|
248
|
+
def inline_fn(id)
|
249
|
+
@chapter.footnote(id).content
|
250
|
+
rescue KeyError
|
251
|
+
error "unknown footnote: #{id}"
|
252
|
+
nofunc_text("[UnknownFootnote:#{id}]")
|
253
|
+
end
|
254
|
+
|
255
|
+
def inline_bou(str)
|
256
|
+
text(str)
|
257
|
+
end
|
258
|
+
|
259
|
+
def inline_ruby(base, ruby)
|
260
|
+
compile_ruby(base, ruby)
|
261
|
+
end
|
262
|
+
|
263
|
+
def inline_kw(word, alt = nil)
|
264
|
+
compile_kw(word, alt)
|
265
|
+
end
|
266
|
+
|
267
|
+
def inline_href(url, label = nil)
|
268
|
+
url = url.strip
|
269
|
+
label = label.strip if label
|
270
|
+
compile_href(url, label)
|
271
|
+
end
|
272
|
+
|
273
|
+
def text(str)
|
274
|
+
str
|
275
|
+
end
|
276
|
+
|
277
|
+
def bibpaper(lines, id, caption)
|
278
|
+
buf = ""
|
279
|
+
buf << bibpaper_header(id, caption)
|
280
|
+
unless lines.empty?
|
281
|
+
buf << "\n"
|
282
|
+
buf << bibpaper_bibpaper(id, caption, lines)
|
283
|
+
end
|
284
|
+
buf << "\n"
|
285
|
+
buf
|
286
|
+
end
|
287
|
+
|
288
|
+
def node_inline_hd(nodelist)
|
289
|
+
id = nodelist[0].to_raw
|
290
|
+
m = /\A([^|]+)\|(.+)/.match(id)
|
291
|
+
chapter = @book.chapters.detect{|chap| chap.id == m[1]} if m && m[1]
|
292
|
+
return inline_hd_chap(chapter, m[2]) if chapter
|
293
|
+
return inline_hd_chap(@chapter, id)
|
294
|
+
end
|
295
|
+
|
296
|
+
def inline_column(id)
|
297
|
+
@chapter.column(id).caption
|
298
|
+
rescue
|
299
|
+
error "unknown column: #{id}"
|
300
|
+
nofunc_text("[UnknownColumn:#{id}]")
|
301
|
+
end
|
302
|
+
|
303
|
+
def raw(str)
|
304
|
+
if matched = str.match(/\|(.*?)\|(.*)/)
|
305
|
+
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
|
306
|
+
c = target_name
|
307
|
+
if builders.include?(c)
|
308
|
+
matched[2].gsub("\\n", "\n")
|
309
|
+
else
|
310
|
+
""
|
311
|
+
end
|
312
|
+
else
|
313
|
+
str.gsub("\\n", "\n")
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def warn(msg)
|
318
|
+
$stderr.puts "#{@location}: warning: #{msg}"
|
319
|
+
end
|
320
|
+
|
321
|
+
def error(msg)
|
322
|
+
raise ApplicationError, "error: #{msg} at #{@compiler.show_pos} \n (#{@compiler.failure_oneline})"
|
323
|
+
end
|
324
|
+
|
325
|
+
def handle_metric(str)
|
326
|
+
str
|
327
|
+
end
|
328
|
+
|
329
|
+
def result_metric(array)
|
330
|
+
array.join(',')
|
331
|
+
end
|
332
|
+
|
333
|
+
def parse_metric(type, metric)
|
334
|
+
return "" if metric.blank?
|
335
|
+
params = metric.split(/,\s*/)
|
336
|
+
results = []
|
337
|
+
params.each do |p|
|
338
|
+
if p =~ /\A.+?::/
|
339
|
+
if p =~ /\A#{type}::/
|
340
|
+
p.sub!(/\A#{type}::/, '')
|
341
|
+
else
|
342
|
+
next
|
343
|
+
end
|
344
|
+
end
|
345
|
+
p = handle_metric(p)
|
346
|
+
results.push(p)
|
347
|
+
end
|
348
|
+
return result_metric(results)
|
349
|
+
end
|
350
|
+
|
351
|
+
def get_chap(chapter = @chapter)
|
352
|
+
if @book.config["secnolevel"] > 0 && !chapter.number.nil? && !chapter.number.to_s.empty?
|
353
|
+
return chapter.format_number(nil)
|
354
|
+
end
|
355
|
+
return nil
|
356
|
+
end
|
357
|
+
|
358
|
+
def extract_chapter_id(chap_ref)
|
359
|
+
m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
|
360
|
+
if m
|
361
|
+
return [@book.chapters.detect{|chap| chap.id == m[1]}, m[2]]
|
362
|
+
else
|
363
|
+
return [@chapter, chap_ref]
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def captionblock(type, lines, caption, specialstyle = nil)
|
368
|
+
raise NotImplementedError
|
369
|
+
end
|
370
|
+
|
371
|
+
CAPTION_TITLES.each do |name|
|
372
|
+
class_eval %Q{
|
373
|
+
def #{name}(lines, caption = nil)
|
374
|
+
captionblock("#{name}", lines, caption)
|
375
|
+
end
|
376
|
+
}
|
377
|
+
end
|
378
|
+
|
379
|
+
def graph(lines, id, command, caption = nil)
|
380
|
+
c = target_name
|
381
|
+
dir = File.join(@book.basedir, @book.image_dir, c)
|
382
|
+
Dir.mkdir(dir) unless File.exist?(dir)
|
383
|
+
file = "#{id}.#{image_ext}"
|
384
|
+
file_path = File.join(dir, file)
|
385
|
+
|
386
|
+
line = self.unescape(lines.join("\n"))
|
387
|
+
cmds = {
|
388
|
+
:graphviz => "echo '#{line}' | dot -T#{image_ext} -o#{file_path}",
|
389
|
+
:gnuplot => "echo 'set terminal " +
|
390
|
+
"#{(image_ext == "eps") ? "postscript eps" : image_ext}\n" +
|
391
|
+
" set output \"#{file_path}\"\n#{line}' | gnuplot",
|
392
|
+
:blockdiag => "echo '#{line}' "+
|
393
|
+
"| blockdiag -a -T #{image_ext} -o #{file_path} /dev/stdin",
|
394
|
+
:aafigure => "echo '#{line}' | aafigure -t#{image_ext} -o#{file_path}",
|
395
|
+
}
|
396
|
+
cmd = cmds[command.to_sym]
|
397
|
+
warn cmd
|
398
|
+
system cmd
|
399
|
+
@chapter.image_index.image_finder.add_entry(file_path)
|
400
|
+
|
401
|
+
image(lines, id, caption ||= "")
|
402
|
+
end
|
403
|
+
|
404
|
+
def image_ext
|
405
|
+
raise NotImplementedError
|
406
|
+
end
|
407
|
+
|
408
|
+
def inline_include(file_name)
|
409
|
+
File.open(file_name).read
|
410
|
+
end
|
411
|
+
|
412
|
+
def include(file_name)
|
413
|
+
File.foreach(file_name) do |line|
|
414
|
+
paragraph([line])
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
def ul_item_begin(lines)
|
419
|
+
ul_item(lines)
|
420
|
+
end
|
421
|
+
|
422
|
+
def ul_item_end
|
423
|
+
""
|
424
|
+
end
|
425
|
+
|
426
|
+
def inline_raw(args)
|
427
|
+
if matched = args.match(/\|(.*?)\|(.*)/)
|
428
|
+
builders = matched[1].split(/,/).map{|i| i.gsub(/\s/, '') }
|
429
|
+
c = self.class.to_s.gsub(/ReVIEW::/, '').gsub(/Builder/, '').downcase
|
430
|
+
if builders.include?(c)
|
431
|
+
matched[2].gsub("\\n", "\n")
|
432
|
+
else
|
433
|
+
""
|
434
|
+
end
|
435
|
+
else
|
436
|
+
args.gsub("\\n", "\n")
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
## override TextUtils::detab
|
441
|
+
def detab(str, num = nil)
|
442
|
+
if num
|
443
|
+
super(str, num)
|
444
|
+
elsif @tabwidth
|
445
|
+
super(str, @tabwidth)
|
446
|
+
else
|
447
|
+
super(str)
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
end # module ReVIEW
|