review 0.6.0 → 0.9.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 (68) hide show
  1. data/ChangeLog +441 -0
  2. data/README.rdoc +25 -0
  3. data/Rakefile +13 -1
  4. data/VERSION +1 -1
  5. data/bin/review-check +1 -1
  6. data/bin/review-compile +19 -10
  7. data/bin/review-epubmaker +114 -17
  8. data/bin/review-index +8 -1
  9. data/bin/review-pdfmaker +378 -0
  10. data/bin/review-preproc +2 -3
  11. data/bin/review-vol +1 -2
  12. data/debian/README.Debian +12 -0
  13. data/debian/README.source +5 -0
  14. data/debian/changelog +5 -0
  15. data/debian/compat +1 -0
  16. data/debian/control +22 -0
  17. data/debian/copyright +60 -0
  18. data/debian/docs +5 -0
  19. data/debian/manpage.1.ex +59 -0
  20. data/debian/patches/path.diff +91 -0
  21. data/debian/patches/series +1 -0
  22. data/debian/review.install +13 -0
  23. data/debian/review.links +4 -0
  24. data/debian/rules +13 -0
  25. data/debian/source/format +1 -0
  26. data/doc/format.rdoc +477 -0
  27. data/doc/format.re +19 -0
  28. data/doc/format_idg.rdoc +180 -0
  29. data/doc/ruby-uuid/README +11 -0
  30. data/doc/ruby-uuid/README.ja +34 -0
  31. data/doc/sample.css +17 -0
  32. data/doc/sample.yaml +8 -4
  33. data/lib/lineinput.rb +1 -1
  34. data/lib/review/book.rb +43 -36
  35. data/lib/review/builder.rb +78 -33
  36. data/lib/review/compiler.rb +45 -48
  37. data/lib/review/epubbuilder.rb +1 -675
  38. data/lib/review/exception.rb +1 -1
  39. data/lib/review/htmlbuilder.rb +627 -49
  40. data/lib/review/htmlutils.rb +5 -0
  41. data/lib/review/idgxmlbuilder.rb +239 -250
  42. data/lib/review/index.rb +84 -7
  43. data/lib/review/latexbuilder.rb +261 -42
  44. data/lib/review/latexutils.rb +15 -6
  45. data/lib/review/preprocessor.rb +40 -6
  46. data/lib/review/textutils.rb +22 -0
  47. data/lib/review/topbuilder.rb +4 -1
  48. data/lib/uuid.rb +312 -0
  49. data/review.gemspec +44 -12
  50. data/test/CHAPS +2 -0
  51. data/test/bib.re +13 -0
  52. data/test/test.re +43 -0
  53. data/test/test_book.rb +1191 -0
  54. data/test/test_builder.rb +147 -0
  55. data/test/test_htmlbuilder.rb +191 -10
  56. data/test/test_htmlutils.rb +24 -0
  57. data/test/test_idgxmlbuilder.rb +310 -0
  58. data/test/test_index.rb +15 -0
  59. data/test/test_latexbuilder.rb +217 -6
  60. data/test/test_lineinput.rb +198 -0
  61. data/test/test_textutils.rb +68 -0
  62. data/test/test_uuid.rb +156 -0
  63. metadata +43 -10
  64. data/doc/format.txt +0 -434
  65. data/doc/format_idg.txt +0 -194
  66. data/doc/format_sjis.txt +0 -313
  67. data/setup.rb +0 -1587
  68. data/test/test_epubbuilder.rb +0 -73
@@ -14,23 +14,25 @@ module ReVIEW
14
14
  module LaTeXUtils
15
15
 
16
16
  MATACHARS = {
17
- '#' => '\symbol{"23}',
18
- "$" => '\symbol{"24}',
17
+ '#' => '\#',
18
+ "$" => '\textdollar{}',
19
19
  '%' => '\%',
20
20
  '&' => '\&',
21
21
  '{' => '\{',
22
22
  '}' => '\}',
23
- '_' => '\symbol{"5F}',
23
+ '_' => '\textunderscore{}',
24
24
  '^' => '\textasciicircum{}',
25
25
  '~' => '\textasciitilde{}',
26
26
  '|' => '\textbar{}',
27
- '<' => '\symbol{"3C}',
28
- '>' => '\symbol{"3E}',
29
- "\\" => '\symbol{"5C}'
27
+ '<' => '\textless{}',
28
+ '>' => '\textgreater{}',
29
+ "\\" => '\reviewbackslash{}'
30
30
  }
31
31
 
32
32
  METACHARS_RE = /[#{Regexp.escape(MATACHARS.keys.join(''))}]/
33
33
 
34
+ MATACHARS_INVERT = MATACHARS.invert
35
+
34
36
  def escape_latex(str)
35
37
  str.gsub(METACHARS_RE) {|s|
36
38
  MATACHARS[s] or raise "unknown trans char: #{s}"
@@ -39,6 +41,13 @@ module ReVIEW
39
41
 
40
42
  alias escape escape_latex
41
43
 
44
+ def unescape_latex(str)
45
+ metachars_invert_re = Regexp.new(MATACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
46
+ str.gsub(metachars_invert_re) {|s|
47
+ MATACHARS_INVERT[s] or raise "unknown trans char: #{s}"
48
+ }
49
+ end
50
+
42
51
  def escape_index(str)
43
52
  str.gsub(/[@!|"]/) {|s| '"' + s }
44
53
  end
@@ -12,6 +12,7 @@
12
12
 
13
13
  require 'review/textutils'
14
14
  require 'review/exception'
15
+ require 'nkf'
15
16
 
16
17
  module ReVIEW
17
18
 
@@ -99,11 +100,8 @@ module ReVIEW
99
100
  end
100
101
  end
101
102
 
102
- def initialize(repo)
103
+ def initialize(repo, param)
103
104
  @repository = repo
104
- end
105
-
106
- def setParameter(param)
107
105
  @param = param
108
106
  end
109
107
 
@@ -181,11 +179,34 @@ module ReVIEW
181
179
  KNOWN_DIRECTIVES.index(op)
182
180
  end
183
181
 
182
+ def convert_outencoding(*s)
183
+ ine = ""
184
+ if @param["inencoding"] =~ /^EUC$/i
185
+ ine = "-E,"
186
+ elsif @param["inencoding"] =~ /^SJIS$/i
187
+ ine = "-S,"
188
+ elsif @param["inencoding"] =~ /^JIS$/i
189
+ ine = "-J,"
190
+ elsif @param["inencoding"] =~ /^UTF\-8$/i
191
+ ine = "-W,"
192
+ end
193
+
194
+ if @param["outencoding"] =~ /^EUC$/i
195
+ NKF.nkf("#{ine} -e", *s)
196
+ elsif @param["outencoding"] =~ /^SJIS$/i
197
+ NKF.nkf("#{ine} -s", *s)
198
+ elsif @param["outencoding"] =~ /^JIS$/i
199
+ NKF.nkf("#{ine} -j", *s)
200
+ else
201
+ NKF.nkf("#{ine} -w", *s)
202
+ end
203
+ end
204
+
184
205
  def replace_block(f, directive_line, newlines, with_lineno)
185
206
  @f.print directive_line
186
207
  newlines.each do |line|
187
208
  print_number line.number if with_lineno
188
- @f.print line.string
209
+ @f.print convert_outencoding(line.string)
189
210
  end
190
211
  skip_list f
191
212
  end
@@ -411,7 +432,20 @@ module ReVIEW
411
432
  private
412
433
 
413
434
  def file_descripter(fname)
414
- @repository[fname] ||= parse_file(fname)
435
+ return @repository[fname] if @repository[fname]
436
+
437
+ @repository[fname] = git?(fname) ? parse_git_blob(fname) : parse_file(fname)
438
+ end
439
+
440
+ def git?(fname)
441
+ fname =~ /\Agit\|/
442
+ end
443
+
444
+ def parse_git_blob(g_obj)
445
+ IO.popen('git show ' + g_obj.sub(/\Agit\|/, ''), 'r') do |f|
446
+ init_ErrorUtils f
447
+ return _parse_file(f)
448
+ end
415
449
  end
416
450
 
417
451
  def parse_file(fname)
@@ -14,6 +14,28 @@ module ReVIEW
14
14
  }
15
15
  end
16
16
 
17
+ def split_paragraph(lines)
18
+ pre = pre_paragraph
19
+ post = post_paragraph
20
+
21
+ blocked_lines = [[]]
22
+ lines.each {|element|
23
+ if element == ""
24
+ if blocked_lines.last != []
25
+ blocked_lines << []
26
+ end
27
+ else
28
+ blocked_lines.last << element
29
+ end
30
+ }
31
+
32
+ if !pre.nil? and !post.nil?
33
+ blocked_lines.map!{|i| [pre] + i + [post] }
34
+ end
35
+
36
+ blocked_lines.map{|l| l.join("")}
37
+ end
38
+
17
39
  end
18
40
 
19
41
  end
@@ -42,7 +42,6 @@ module ReVIEW
42
42
  Compiler.defblock(:reference, 0)
43
43
  Compiler.defblock(:term, 0)
44
44
  Compiler.defblock(:practice, 0)
45
- Compiler.defblock(:box, 0..1)
46
45
  Compiler.defblock(:expert, 0)
47
46
  Compiler.defblock(:lead, 0)
48
47
 
@@ -516,6 +515,10 @@ module ReVIEW
516
515
  # FIXME
517
516
  ""
518
517
  end
518
+
519
+ def inline_br(str)
520
+ %Q(\n)
521
+ end
519
522
 
520
523
  def raw(str)
521
524
  if str =~ /\A<\/(.+)>$/
@@ -0,0 +1,312 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright(c) 2005 URABE, Shyouhei.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this code, to deal in the code without restriction, including without
6
+ # limitation the rights to use, copy, modify, merge, publish, distribute,
7
+ # sublicense, and/or sell copies of the code, and to permit persons to whom the
8
+ # code is furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be
11
+ # included in all copies or substantial portions of the code.
12
+ #
13
+ # THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE CODE OR THE USE OR OTHER DEALINGS IN THE
19
+ # CODE.
20
+
21
+ %w[
22
+ digest/md5
23
+ digest/sha1
24
+ tmpdir
25
+ ].each do |f|
26
+ require f
27
+ end
28
+
29
+ # Pure ruby UUID generator, which is compatible with RFC4122
30
+ class UUID
31
+ # UUID epoch is 15th Oct. 1582
32
+ UNIXEpoch = 0x01B21DD213814000 # in 100-nanoseconds resolution
33
+
34
+ private_class_method :new
35
+
36
+ private
37
+ def initialize str
38
+ tmp = str.unpack "C*"
39
+ @num = tmp.inject do |r, i|
40
+ r * 256 | i
41
+ end
42
+ @num.freeze
43
+ self.freeze
44
+ end
45
+
46
+ public
47
+
48
+ def raw_bytes
49
+ ret = String.new
50
+ tmp = @num
51
+ 16.times do |i|
52
+ x, y = tmp.divmod 256
53
+ ret << y
54
+ tmp = x
55
+ end
56
+ ret.reverse!
57
+ ret
58
+ end
59
+
60
+ class << self
61
+ def mask ver, str # :nodoc:
62
+ ver = ver & 15
63
+ v = str[6].ord
64
+ v &= 0b0000_1111
65
+ v |= ver << 4
66
+ str[6] = v.chr
67
+ r = str[8].ord
68
+ r &= 0b0011_1111
69
+ r |= 0b1000_0000
70
+ str[8] = r.chr
71
+ str
72
+ end
73
+
74
+ def prand # :nodoc:
75
+ rand 0x100000000
76
+ end
77
+
78
+ private :mask, :prand
79
+
80
+ # UUID generation using SHA1. Recommended over create_md5.
81
+ # Namespace object is another UUID, some of them are pre-defined below.
82
+ def create_sha1 str, namespace
83
+ sha1 = Digest::SHA1.new
84
+ sha1.update namespace.raw_bytes
85
+ sha1.update str
86
+ sum = sha1.digest
87
+ raw = mask 5, sum[0..15]
88
+ new raw
89
+ end
90
+
91
+ # UUID generation using MD5 (for backward compat.)
92
+ def create_md5 str, namespace
93
+ md5 = Digest::MD5.new
94
+ md5.update namespace.raw_bytes
95
+ md5.update str
96
+ sum = md5.digest
97
+ raw = mask 3, sum[0..16]
98
+ new raw
99
+ end
100
+
101
+ # UUID generation using random-number generator. From it's random
102
+ # nature, there's no warranty that the created ID is really universaly
103
+ # unique.
104
+ def create_random
105
+ rnd = [prand, prand, prand, prand].pack "N4"
106
+ raw = mask 4, rnd
107
+ new raw
108
+ end
109
+
110
+ def read_state fp # :nodoc:
111
+ fp.rewind
112
+ Marshal.load fp.read
113
+ end
114
+
115
+ def write_state fp, c, m # :nodoc:
116
+ fp.rewind
117
+ str = Marshal.dump [c, m]
118
+ fp.write str
119
+ end
120
+
121
+ private :read_state, :write_state
122
+ STATE_FILE = 'ruby-uuid'
123
+
124
+ # create the "version 1" UUID with current system clock, current UTC
125
+ # timestamp, and the IEEE 802 address (so-called MAC address).
126
+ #
127
+ # Speed notice: it's slow. It writes some data into hard drive on every
128
+ # invokation. If you want to speed this up, try remounting tmpdir with a
129
+ # memory based filesystem (such as tmpfs). STILL slow? then no way but
130
+ # rewrite it with c :)
131
+ def create clock=nil, time=Time.now, mac_addr=nil
132
+ c = t = m = nil
133
+ Dir.chdir Dir.tmpdir do
134
+ unless FileTest.exist? STATE_FILE then
135
+ # Generate a pseudo MAC address because we have no pure-ruby way
136
+ # to know the MAC address of the NIC this system uses. Note
137
+ # that cheating with pseudo arresses here is completely legal:
138
+ # see Section 4.5 of RFC4122 for details.
139
+ sha1 = Digest::SHA1.new
140
+ 256.times do
141
+ r = [prand].pack "N"
142
+ sha1.update r
143
+ end
144
+ ary = sha1.digest.bytes.to_a
145
+ node = ary.last 6
146
+ node[0] |= 0x01 # multicast bit
147
+ node = node.pack "C*"
148
+ k = rand 0x40000
149
+ open STATE_FILE, 'w' do |fp|
150
+ fp.flock IO::LOCK_EX
151
+ write_state fp, k, node
152
+ fp.chmod 0o777 # must be world writable
153
+ end
154
+ end
155
+ open STATE_FILE, 'r+' do |fp|
156
+ fp.flock IO::LOCK_EX
157
+ c, m = read_state fp
158
+ c += 1 # important; increment here
159
+ write_state fp, c, m
160
+ end
161
+ end
162
+ c = clock & 0b11_1111_1111_1111 if clock
163
+ m = mac_addr if mac_addr
164
+ time = Time.at time if time.is_a? Float
165
+ case time
166
+ when Time
167
+ t = time.to_i * 10_000_000 + time.tv_usec * 10 + UNIXEpoch
168
+ when Integer
169
+ t = time + UNIXEpoch
170
+ else
171
+ raise TypeError, "cannot convert ``#{time}'' into Time."
172
+ end
173
+
174
+ tl = t & 0xFFFF_FFFF
175
+ tm = t >> 32
176
+ tm = tm & 0xFFFF
177
+ th = t >> 48
178
+ th = th & 0b0000_1111_1111_1111
179
+ th = th | 0b0001_0000_0000_0000
180
+ cl = c & 0b0000_0000_1111_1111
181
+ ch = c & 0b0011_1111_0000_0000
182
+ ch = ch >> 8
183
+ ch = ch | 0b1000_0000
184
+ pack tl, tm, th, ch, cl, m
185
+ end
186
+
187
+ # A simple GUID parser: just ignores unknown characters and convert
188
+ # hexadecimal dump into 16-octet object.
189
+ def parse obj
190
+ str = obj.to_s.sub %r/\Aurn:uuid:/, ''
191
+ str.gsub! %r/[^0-9A-Fa-f]/, ''
192
+ raw = [str[0..31]].pack 'H*'
193
+ new raw
194
+ end
195
+
196
+ # The 'primitive constructor' of this class
197
+ # Note UUID.pack(uuid.unpack) == uuid
198
+ def pack tl, tm, th, ch, cl, n
199
+ raw = [tl, tm, th, ch, cl, n].pack "NnnCCa6"
200
+ new raw
201
+ end
202
+ end
203
+
204
+ # The 'primitive deconstructor', or the dual to pack.
205
+ # Note UUID.pack(uuid.unpack) == uuid
206
+ def unpack
207
+ raw_bytes.unpack "NnnCCa6"
208
+ end
209
+
210
+ # The timestamp of this UUID.
211
+ # Throws RageError if that time exceeds UNIX time range
212
+ def time
213
+ a = unpack
214
+ tl = a[0]
215
+ tm = a[1]
216
+ th = a[2] & 0x0FFF
217
+ t = tl
218
+ t += tm << 32
219
+ t += th << 48
220
+ t -= UNIXEpoch
221
+ tv_sec = t / 10_000_000
222
+ t -= tv_sec * 10_000_000
223
+ tv_usec = t / 10
224
+ Time.at tv_sec, tv_usec
225
+ end
226
+
227
+ # The version of this UUID
228
+ def version
229
+ v = unpack[2] & 0b1111_0000_0000_0000
230
+ v >> 12
231
+ end
232
+
233
+ # The clock sequence of this UUID
234
+ def clock
235
+ a = unpack
236
+ ch = a[3] & 0b0001_1111
237
+ cl = a[4]
238
+ c = cl
239
+ c += ch << 8
240
+ c
241
+ end
242
+
243
+ # The IEEE 802 address in a hexadecimal format
244
+ def node
245
+ m = unpack[5].unpack 'C*'
246
+ '%02x%02x%02x%02x%02x%02x' % m
247
+ end
248
+ alias mac_address node
249
+ alias ieee802 node
250
+
251
+ # Generate the string representation (a.k.a GUID) of this UUID
252
+ def to_s
253
+ a = unpack
254
+ a[-1] = mac_address
255
+ "%08x-%04x-%04x-%02x%02x-%s" % a
256
+ end
257
+ alias guid to_s
258
+
259
+ # Convert into a RFC4122-comforming URN representation
260
+ def to_uri
261
+ "urn:uuid:" + self.to_s
262
+ end
263
+ alias urn to_uri
264
+ alias inspect to_uri
265
+
266
+ # Convert into 128-bit unsigned integer
267
+ # Typically a Bignum instance, but can be a Fixnum.
268
+ def to_int
269
+ @num
270
+ end
271
+ alias to_i to_int
272
+
273
+ # Two UUIDs are said to be equal if and only if their (byte-order
274
+ # canonicalized) integer representations are equivallent. Refer RFC4122 for
275
+ # details.
276
+ def == other
277
+ to_i == other.to_i
278
+ end
279
+ alias eql? ==
280
+
281
+ # Two identical UUIDs should have same hash
282
+ def hash
283
+ to_i
284
+ end
285
+
286
+ include Comparable
287
+ # UUIDs are comparable (don't know what benefits are there, though).
288
+ def <=> other
289
+ to_s <=> other.to_s
290
+ end
291
+
292
+ # Pre-defined UUID Namespaces described in RFC4122 Appendix C.
293
+ NameSpace_DNS = parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
294
+ NameSpace_URL = parse "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
295
+ NameSpace_OID = parse "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
296
+ NameSpace_X500 = parse "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
297
+
298
+ # The Nil UUID in RFC4122 Section 4.1.7
299
+ Nil = parse "00000000-0000-0000-0000-000000000000"
300
+ end
301
+
302
+
303
+ # Local Variables:
304
+ # mode: ruby
305
+ # coding: utf-8
306
+ # indent-tabs-mode: t
307
+ # tab-width: 3
308
+ # ruby-indent-level: 3
309
+ # fill-column: 79
310
+ # default-justification: full
311
+ # End:
312
+ # vi: ts=3 sw=3