cbeta 2.2.0 → 2.2.1
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 +4 -4
- data/lib/cbeta/p5a_to_simple_html.rb +42 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a987ed6695917c4c1e0f9cbc4828b4f91cf3d71
|
4
|
+
data.tar.gz: 1baf61c0590a184ba725f739dee075b6cf9fc57f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 596eb2b3782ec4c9219596f4fc1cc8f52c13fdd6d1671a0b961ac12e2f14b6efba060ed815ec2901eb0dd3aed0f2d1dd83bc15ac0f98116d74053b61778c25dd
|
7
|
+
data.tar.gz: 9df1a481e8f140072a1021941e800fac0922644ea011dab5304a4b6fd912acda42270973607c9848f056bddb540ee93133270e8a81a51a703071810ef1d9fed5
|
@@ -24,11 +24,13 @@ class CBETA::P5aToSimpleHTML
|
|
24
24
|
|
25
25
|
# @param xml_root [String] 來源 CBETA XML P5a 路徑
|
26
26
|
# @param output_root [String] 輸出 Text 路徑
|
27
|
-
def initialize(xml_root, output_root)
|
27
|
+
def initialize(xml_root, output_root, opts={})
|
28
28
|
@xml_root = xml_root
|
29
29
|
@output_root = output_root
|
30
30
|
@cbeta = CBETA.new
|
31
31
|
@gaijis = CBETA::Gaiji.new
|
32
|
+
@config = { multi_edition: false }
|
33
|
+
@config.merge!(opts)
|
32
34
|
end
|
33
35
|
|
34
36
|
# 將 CBETA XML P5a 轉為 Simple HTML
|
@@ -96,7 +98,11 @@ class CBETA::P5aToSimpleHTML
|
|
96
98
|
end
|
97
99
|
|
98
100
|
def handle_corr(e)
|
99
|
-
|
101
|
+
r = traverse(e)
|
102
|
+
if @config[:multi_edition]
|
103
|
+
r = "<r w='【CBETA】'>#{r}</r>"
|
104
|
+
end
|
105
|
+
r
|
100
106
|
end
|
101
107
|
|
102
108
|
def handle_g(e)
|
@@ -149,12 +155,14 @@ class CBETA::P5aToSimpleHTML
|
|
149
155
|
end
|
150
156
|
|
151
157
|
def handle_lem(e)
|
152
|
-
r = ''
|
153
158
|
r = traverse(e)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
if @config[:multi_edition]
|
160
|
+
w = e['wit'].scan(/【.*?】/)
|
161
|
+
@editions.merge w
|
162
|
+
w = w.join(' ')
|
163
|
+
r = "<r w='#{w}'>#{r}</r>"
|
164
|
+
end
|
165
|
+
r
|
158
166
|
end
|
159
167
|
|
160
168
|
def handle_milestone(e)
|
@@ -205,6 +213,8 @@ class CBETA::P5aToSimpleHTML
|
|
205
213
|
end
|
206
214
|
|
207
215
|
def handle_rdg(e)
|
216
|
+
return '' unless @config[:multi_edition]
|
217
|
+
|
208
218
|
r = traverse(e)
|
209
219
|
w = e['wit'].scan(/【.*?】/)
|
210
220
|
@editions.merge w
|
@@ -216,6 +226,8 @@ class CBETA::P5aToSimpleHTML
|
|
216
226
|
end
|
217
227
|
|
218
228
|
def handle_sic(e)
|
229
|
+
return '' unless@config[:multi_edition]
|
230
|
+
|
219
231
|
"<r w='#{@orig}'>" + traverse(e) + "</r>"
|
220
232
|
end
|
221
233
|
|
@@ -359,6 +371,15 @@ class CBETA::P5aToSimpleHTML
|
|
359
371
|
end
|
360
372
|
|
361
373
|
def write_juan(juan_no, txt)
|
374
|
+
if @config[:multi_edition]
|
375
|
+
write_juan_for_editions(juan_no, txt)
|
376
|
+
else
|
377
|
+
fn = File.join(@out_sutra, "%03d.html" % juan_no)
|
378
|
+
write_juan_to_file(fn, txt)
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
def write_juan_for_editions(juan_no, txt)
|
362
383
|
folder = File.join(@out_sutra, "%03d" % juan_no)
|
363
384
|
FileUtils.makedirs(folder)
|
364
385
|
@editions.each do |ed|
|
@@ -369,15 +390,7 @@ class CBETA::P5aToSimpleHTML
|
|
369
390
|
end
|
370
391
|
node.remove
|
371
392
|
end
|
372
|
-
|
373
|
-
text = <<-END.gsub(/^\s+\|/, '')
|
374
|
-
|<!DOCTYPE html>
|
375
|
-
|<html>
|
376
|
-
|<head>
|
377
|
-
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
378
|
-
|</head>
|
379
|
-
END
|
380
|
-
text += "<body>" + to_html(frag) + "</body></html>"
|
393
|
+
html = to_html(frag)
|
381
394
|
|
382
395
|
fn = ed.sub(/^【(.*?)】$/, '\1')
|
383
396
|
if fn != 'CBETA' and fn != @orig_short
|
@@ -385,10 +398,21 @@ class CBETA::P5aToSimpleHTML
|
|
385
398
|
end
|
386
399
|
fn = "#{fn}.html"
|
387
400
|
output_path = File.join(folder, fn)
|
388
|
-
|
389
|
-
File.write(output_path, text)
|
401
|
+
write_juan_to_file(output_path, html)
|
390
402
|
end
|
391
403
|
end
|
404
|
+
|
405
|
+
def write_juan_to_file(fn, html)
|
406
|
+
text = <<-END.gsub(/^\s+\|/, '')
|
407
|
+
|<!DOCTYPE html>
|
408
|
+
|<html>
|
409
|
+
|<head>
|
410
|
+
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
411
|
+
|</head>
|
412
|
+
END
|
413
|
+
text += "<body>#{html}</body></html>"
|
414
|
+
File.write(fn, text)
|
415
|
+
end
|
392
416
|
|
393
417
|
def to_html(e)
|
394
418
|
e.to_xml(encoding: 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Chou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem for use Chinese Buddhist Text resources made by CBETA (http://www.cbeta.org).
|
14
14
|
email: zhoubx@gmail.com
|