cbeta 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cbeta.rb +13 -1
- data/lib/cbeta/p5a_to_html.rb +83 -50
- 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: 965c9247aa8e33b7270dee71d34cb7f5bed26915
|
4
|
+
data.tar.gz: afd561a1aa947591a92d28d4dbcf0d8b0c5b7a82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86b3692cf11c8c3a99f493c88ac303b88bd53126d0d23d741c02aa10440d1579740e2f6caf850ad99151dd69b88ac05c5c59640127410be10d39d33221eda180
|
7
|
+
data.tar.gz: bd2250ce8c318c9bdde3d01ab3ce8a6cdee4ed219f6ccf7113f2b046937da95419124aa432d3a71e37eebed12c1ed919d56c3d997018a07e6032dafc915099f4
|
data/lib/cbeta.rb
CHANGED
@@ -38,10 +38,15 @@ class CBETA
|
|
38
38
|
fn = File.join(File.dirname(__FILE__), 'data/canons.csv')
|
39
39
|
text = File.read(fn)
|
40
40
|
@canon_abbr = {}
|
41
|
+
@canon_nickname = {}
|
41
42
|
CSV.parse(text, :headers => true) do |row|
|
43
|
+
id = row['id']
|
44
|
+
unless row['nickname'].nil?
|
45
|
+
@canon_nickname[id] = row['nickname']
|
46
|
+
end
|
42
47
|
next if row['abbreviation'].nil?
|
43
48
|
next if row['abbreviation'].empty?
|
44
|
-
@canon_abbr[
|
49
|
+
@canon_abbr[id] = row['abbreviation']
|
45
50
|
end
|
46
51
|
|
47
52
|
fn = File.join(File.dirname(__FILE__), 'data/categories.json')
|
@@ -49,6 +54,13 @@ class CBETA
|
|
49
54
|
@categories = JSON.parse(s)
|
50
55
|
end
|
51
56
|
|
57
|
+
# @param id [String] 藏經 ID, 例如大正藏的 ID 是 "T"
|
58
|
+
# @return [String] 藏經短名,例如 "大正藏"
|
59
|
+
def get_canon_nickname(id)
|
60
|
+
return nil unless @canon_nickname.key? id
|
61
|
+
@canon_nickname[id]
|
62
|
+
end
|
63
|
+
|
52
64
|
# 取得藏經略符
|
53
65
|
#
|
54
66
|
# @param id [String] 藏經 ID, 例如大正藏的 ID 是 "T"
|
data/lib/cbeta/p5a_to_html.rb
CHANGED
@@ -450,8 +450,8 @@ class CBETA::P5aToHTML
|
|
450
450
|
@pass << false
|
451
451
|
s = traverse(e)
|
452
452
|
@pass.pop
|
453
|
-
@back[@juan] += "<span class='
|
454
|
-
return "<a class='noteAnchor' href='#n#{n}'></a>"
|
453
|
+
@back[@juan] += "<span class='footnote cb' id='n#{n}'>#{s}</span>\n"
|
454
|
+
return "<a class='noteAnchor cb' href='#n#{n}'></a>"
|
455
455
|
when 'rest'
|
456
456
|
return ''
|
457
457
|
else
|
@@ -463,12 +463,15 @@ class CBETA::P5aToHTML
|
|
463
463
|
return '' if e['resp'].start_with? 'CBETA'
|
464
464
|
end
|
465
465
|
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
466
|
+
r = traverse(e)
|
467
|
+
if e.has_attribute?('place')
|
468
|
+
if e['place']=='inline'
|
469
|
+
r = "<span class='doube-line-note'>#{r}</span>"
|
470
|
+
elsif e['place']=='interlinear'
|
471
|
+
r = "<span class='interlinear-note'>#{r}</span>"
|
472
|
+
end
|
471
473
|
end
|
474
|
+
r
|
472
475
|
end
|
473
476
|
|
474
477
|
def handle_note_orig(e, anchor_type=nil)
|
@@ -476,18 +479,21 @@ class CBETA::P5aToHTML
|
|
476
479
|
@pass << false
|
477
480
|
s = traverse(e)
|
478
481
|
@pass.pop
|
479
|
-
@back[@juan] += "<span class='footnote_orig' id='n#{n}'>#{s}</span>\n"
|
480
482
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
483
|
+
c = @series
|
484
|
+
|
485
|
+
# 如果 CBETA 沒有修訂,就跟底本的註一樣
|
486
|
+
c += " cb" unless @mod_notes.include? n
|
487
|
+
|
488
|
+
@back[@juan] += "<span class='footnote #{c}' id='n#{n}'>#{s}</span>\n"
|
489
|
+
|
490
|
+
label = case anchor_type
|
491
|
+
when 'biao' then " data-label='標#{n[-2..-1]}'"
|
492
|
+
when 'ke' then " data-label='科#{n[-2..-1]}'"
|
493
|
+
else ''
|
490
494
|
end
|
495
|
+
|
496
|
+
return "<a class='noteAnchor #{c}' href='#n#{n}'#{label}></a>"
|
491
497
|
end
|
492
498
|
|
493
499
|
def handle_p(e)
|
@@ -534,39 +540,10 @@ class CBETA::P5aToHTML
|
|
534
540
|
juans.each { |j|
|
535
541
|
if j =~ /<juan (\d+)>$/
|
536
542
|
juan_no = $1.to_i
|
537
|
-
|
538
|
-
fn = "#{$1}n0220_%03d.htm" % juan_no
|
539
|
-
else
|
540
|
-
fn = "#{@sutra_no}_%03d.htm" % juan_no
|
541
|
-
end
|
542
|
-
output_path = File.join(@out_folder, fn)
|
543
|
-
fo = File.open(output_path, 'w')
|
544
|
-
open = true
|
545
|
-
s = <<eos
|
546
|
-
<html>
|
547
|
-
<head>
|
548
|
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
549
|
-
<meta name="filename" content="#{fn}" />
|
550
|
-
<title>#{@title}</title>
|
551
|
-
</head>
|
552
|
-
<body>
|
553
|
-
<!--
|
554
|
-
來源 XML CBETA P5a: https://github.com/cbeta-org/xml-p5a.git
|
555
|
-
轉檔程式: https://rubygems.org/gems/cbeta #{Date.today}
|
556
|
-
說明文件: http://wiki.ddbc.edu.tw/pages/CBETA_XML_P5a_轉_HTML
|
557
|
-
-->
|
558
|
-
<div id='body'>
|
559
|
-
eos
|
560
|
-
fo.write(s)
|
561
|
-
fo.write(buf)
|
562
|
-
buf = ''
|
563
|
-
elsif open
|
564
|
-
fo.write(j + "\n</div><!-- end of div[@id='body'] -->\n")
|
565
|
-
fo.write("<div id='back'>\n" + @back[juan_no] + "</div>\n")
|
566
|
-
fo.write('</body></html>')
|
567
|
-
fo.close
|
568
|
-
else
|
543
|
+
elsif juan_no.nil?
|
569
544
|
buf = j
|
545
|
+
else
|
546
|
+
write_juan(juan_no, buf+j)
|
570
547
|
end
|
571
548
|
}
|
572
549
|
end
|
@@ -719,7 +696,13 @@ eos
|
|
719
696
|
|
720
697
|
def read_mod_notes(doc)
|
721
698
|
doc.xpath("//note[@type='mod']").each { |e|
|
722
|
-
|
699
|
+
n = e['n']
|
700
|
+
@mod_notes << n
|
701
|
+
|
702
|
+
# 例 T01n0026_p0506b07, 原註標為 7, CBETA 修訂為 7a, 7b
|
703
|
+
n.match(/[a-z]$/) {
|
704
|
+
@mod_notes << n[0..-2]
|
705
|
+
}
|
723
706
|
}
|
724
707
|
end
|
725
708
|
|
@@ -732,6 +715,14 @@ eos
|
|
732
715
|
@title = traverse(e, 'txt')
|
733
716
|
@title = @title.split()[-1]
|
734
717
|
|
718
|
+
e = doc.at_xpath("//editionStmt/edition/date")
|
719
|
+
abort "找不到版本日期" if e.nil?
|
720
|
+
@edition_date = e.text.sub(/\$Date: (.*?) \$$/, '\1')
|
721
|
+
|
722
|
+
e = doc.at_xpath("//projectDesc/p[@lang='zh']")
|
723
|
+
abort "找不到貢獻者" if e.nil?
|
724
|
+
@contributors = e.text
|
725
|
+
|
735
726
|
read_mod_notes(doc)
|
736
727
|
|
737
728
|
root = doc.root()
|
@@ -754,5 +745,47 @@ eos
|
|
754
745
|
}
|
755
746
|
r
|
756
747
|
end
|
748
|
+
|
749
|
+
def write_juan(juan_no, body)
|
750
|
+
if @sutra_no.match(/^(T05|T06|T07)n0220/)
|
751
|
+
fn = "#{$1}n0220_%03d.htm" % juan_no
|
752
|
+
else
|
753
|
+
fn = "#{@sutra_no}_%03d.htm" % juan_no
|
754
|
+
end
|
755
|
+
|
756
|
+
html = <<eos
|
757
|
+
<html>
|
758
|
+
<head>
|
759
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
760
|
+
<meta name="filename" content="#{fn}" />
|
761
|
+
<title>#{@title}</title>
|
762
|
+
</head>
|
763
|
+
<body>
|
764
|
+
<!--
|
765
|
+
來源 XML CBETA P5a: https://github.com/cbeta-org/xml-p5a.git
|
766
|
+
轉檔程式: https://rubygems.org/gems/cbeta #{Date.today}
|
767
|
+
說明文件: http://wiki.ddbc.edu.tw/pages/CBETA_XML_P5a_轉_HTML
|
768
|
+
-->
|
769
|
+
<div id='body'>
|
770
|
+
eos
|
771
|
+
html += body + "\n</div><!-- end of div[@id='body'] -->\n"
|
772
|
+
html += "<div id='back'>\n" + @back[juan_no] + "</div>\n"
|
773
|
+
html += "<div id='cbeta-copyright'><p>\n"
|
774
|
+
|
775
|
+
orig = @cbeta.get_canon_nickname(@series)
|
776
|
+
v = @vol.sub(/^[A-Z]0*([^0].*)$/, '\1')
|
777
|
+
n = @sutra_no.sub(/^[A-Z]\d{2,3}n0*([^0].*)$/, '\1')
|
778
|
+
html += "【經文資訊】#{orig}第 #{v} 冊 No. #{n} #{@title}<br/>\n"
|
779
|
+
html += "【版本記錄】CBETA 電子佛典 版本日期:#{@edition_date}<br/>\n"
|
780
|
+
html += "【編輯說明】本資料庫由中華電子佛典協會(CBETA)依#{orig}所編輯<br/>\n"
|
781
|
+
|
782
|
+
html += "【原始資料】#{@contributors}<br/>\n"
|
783
|
+
html += "【其他事項】本資料庫可自由免費流通,詳細內容請參閱【中華電子佛典協會資料庫版權宣告】\n"
|
784
|
+
html += "</p></div><!-- end of cbeta-copyright -->\n"
|
785
|
+
html += '</body></html>'
|
786
|
+
|
787
|
+
output_path = File.join(@out_folder, fn)
|
788
|
+
File.write(output_path, html)
|
789
|
+
end
|
757
790
|
|
758
791
|
end
|
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: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Chou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-08 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
|