cbeta 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 170b443c3e9622fde8843f6dd717b3f89607892b
4
- data.tar.gz: ac4ee13f72782ecebcfdc2f8ca6f045fa77cfada
3
+ metadata.gz: 5ec72fbd4c93e57fc423a28a190984256ab7e2dc
4
+ data.tar.gz: 68977b6a4c131378cc98f7252bab67b7a511bb57
5
5
  SHA512:
6
- metadata.gz: 7b200b4163c514a638fceed4f90a4026ab15c00a78c0f670eea6c05571270267290148ddaa2bdbf33397d3954ee54e0a5d10d304d1a6adb7672d1cb85ba18948
7
- data.tar.gz: 87c560dd0128a156c43c8fa3f34a5065e295383e2cfae38a7f99c90ff90761d960b09024d652e8b01bb4b611a6017011ad7d1094c4aa1d6aa122587d682b5789
6
+ metadata.gz: 982ff7caa25181074d1d59d6f49e42b43699cc20208c2661a443d0004845a8358a995c02a9f2135f6fd0725792a2bc29fff34dc2aaac666177d77fade2c88112
7
+ data.tar.gz: c5020c2d999986051a2c8a38f72a6ea03f62ad105019eb018096ffe4f7a746afef3eebf186e29323f7d8cf1dc0f003807b109288ce676e344d0f549d530b9a4b
@@ -17,7 +17,10 @@ class CBETA::P5aToHTMLForEveryEdition
17
17
  # 內容不輸出的元素
18
18
  PASS=['back', 'teiHeader']
19
19
 
20
- private_constant :PASS
20
+ # 某版用字缺的符號
21
+ MISSING = '-'
22
+
23
+ private_constant :PASS, :MISSING
21
24
 
22
25
  # @param xml_root [String] 來源 CBETA XML P5a 路徑
23
26
  # @param out_root [String] 輸出 HTML 路徑
@@ -78,6 +81,7 @@ class CBETA::P5aToHTMLForEveryEdition
78
81
  @next_line_buf = ''
79
82
  @notes_mod = {}
80
83
  @notes_orig = {}
84
+ @notes_dila = {}
81
85
  @open_divs = []
82
86
  @sutra_no = File.basename(xml_fn, ".xml")
83
87
  end
@@ -132,7 +136,7 @@ class CBETA::P5aToHTMLForEveryEdition
132
136
 
133
137
  def handle_byline(e)
134
138
  r = '<p class="byline">'
135
- r += "<span class='lineInfo'>#{@lb}</span>"
139
+ r += line_info
136
140
  r += traverse(e)
137
141
  r + '</p>'
138
142
  end
@@ -158,7 +162,24 @@ class CBETA::P5aToHTMLForEveryEdition
158
162
  end
159
163
 
160
164
  def handle_corr(e)
161
- "<r w='【CBETA】' l='#{@lb}' w='#{@char_count}'>%s</r>" % traverse(e)
165
+ r = ''
166
+ if e.parent.name == 'choice'
167
+ sic = e.parent.at_xpath('sic')
168
+ unless sic.nil?
169
+ n = @notes_dila[@juan].size + 1
170
+ r = "<a class='noteAnchor dila' href='#dila_note#{n}'></a>"
171
+
172
+ note = @orig
173
+ sic_text = traverse(sic, 'back')
174
+ if sic_text.empty?
175
+ note += MISSING
176
+ else
177
+ note += sic_text
178
+ end
179
+ @notes_dila[@juan] << "<span class='footnote dila' id='dila_note#{n}'>#{note}</span>"
180
+ end
181
+ end
182
+ r + "<r w='【CBETA】' l='#{@lb}' w='#{@char_count}'>%s</r>" % traverse(e)
162
183
  end
163
184
 
164
185
  def handle_div(e)
@@ -326,7 +347,7 @@ class CBETA::P5aToHTMLForEveryEdition
326
347
  r += "</div><!-- end of lg-row -->"
327
348
  @lg_row_open = false
328
349
  end
329
- r += "<span class='lb' id='#{line_head}'>#{line_head}</span>"
350
+ r += "<span \nclass='lb' id='#{line_head}'>#{line_head}</span>"
330
351
  unless @next_line_buf.empty?
331
352
  r += @next_line_buf
332
353
  @next_line_buf = ''
@@ -335,6 +356,20 @@ class CBETA::P5aToHTMLForEveryEdition
335
356
  end
336
357
 
337
358
  def handle_lem(e)
359
+ r = ''
360
+ content = traverse(e)
361
+ w = e['wit']
362
+ if w.include? 'CBETA' and not w.include? @orig
363
+ n = @notes_dila[@juan].size + 1
364
+ r = "<a class='noteAnchor dila' href='#dila_note#{n}'></a>"
365
+ r += "<span class='cbeta'>%s</span>" % content
366
+ r = "<r w='#{w}' l='#{@lb}'>#{r}</r>"
367
+
368
+ note = lem_note_cf(e)
369
+ note += lem_note_rdg(e)
370
+ @notes_dila[@juan] << "<span class='footnote dila' id='dila_note#{n}'>#{note}</span>"
371
+ end
372
+
338
373
  # 沒有 rdg 的版本,用字同 lem
339
374
  editions = Set.new @editions
340
375
  e.xpath('./following-sibling::rdg').each do |rdg|
@@ -342,10 +377,10 @@ class CBETA::P5aToHTMLForEveryEdition
342
377
  editions.delete w
343
378
  end
344
379
  end
345
- w = editions.to_a.join(' ')
346
380
 
347
- r = traverse(e)
348
- "<r w='#{w}' l='#{@lb}'>#{r}</r>"
381
+ editions.delete('【CBETA】') unless r.empty?
382
+ w = editions.to_a.join(' ')
383
+ r + ("<r w='#{w}' l='#{@lb}'>%s</r>" % content)
349
384
  end
350
385
 
351
386
  def handle_lg(e)
@@ -387,6 +422,7 @@ class CBETA::P5aToHTMLForEveryEdition
387
422
  @back_orig[@juan] = @back_orig[0]
388
423
  @notes_mod[@juan] = {}
389
424
  @notes_orig[@juan] = {}
425
+ @notes_dila[@juan] = []
390
426
  r += "<juan #{@juan}>"
391
427
  @open_divs.each { |d|
392
428
  r += "<div class='div-#{d['type']}'>"
@@ -507,8 +543,12 @@ class CBETA::P5aToHTMLForEveryEdition
507
543
  end
508
544
 
509
545
  def handle_p(e)
510
- r = '<p>'
511
- r += "<span class='lineInfo'>#{@lb}</span>"
546
+ if e.key? 'type'
547
+ r = "<p class='%s'>" % e['type']
548
+ else
549
+ r = '<p>'
550
+ end
551
+ r += line_info
512
552
  r += traverse(e)
513
553
  r + '</p>'
514
554
  end
@@ -649,17 +689,73 @@ class CBETA::P5aToHTMLForEveryEdition
649
689
  when '【CBETA】'
650
690
  r = @back[juan_no]
651
691
  @notes_mod[juan_no].each_pair do |k,v|
652
- r += "<span class='footnote_cb' id='n#{k}'>#{v}</span>\n"
692
+ r += "<span class='footnote cb' id='n#{k}'>#{v}</span>\n"
653
693
  end
694
+ r += @notes_dila[juan_no].join("\n")
654
695
  when @orig
655
696
  r = @back_orig[juan_no]
656
697
  @notes_orig[juan_no].each_pair do |k,v|
657
- r += "<span class='footnote_orig' id='n#{k}'>#{v}</span>\n"
698
+ r += "<span class='footnote #{@series}' id='n#{k}'>#{v}</span>\n"
699
+ end
700
+ end
701
+ r
702
+ end
703
+
704
+ def html_copyright
705
+ r = "<div id='cbeta-copyright'><p>\n"
706
+
707
+ orig = @cbeta.get_canon_nickname(@series)
708
+ v = @vol.sub(/^[A-Z]0*([^0].*)$/, '\1')
709
+ n = @sutra_no.sub(/^[A-Z]\d{2,3}n0*([^0].*)$/, '\1')
710
+ r += "【經文資訊】#{orig}第 #{v} 冊 No. #{n} #{@title}<br/>\n"
711
+ r += "【版本記錄】CBETA 電子佛典 版本日期:#{@edition_date}<br/>\n"
712
+ r += "【編輯說明】本資料庫由中華電子佛典協會(CBETA)依#{orig}所編輯<br/>\n"
713
+
714
+ r += "【原始資料】#{@contributors}<br/>\n"
715
+ r += "【其他事項】本資料庫可自由免費流通,詳細內容請參閱【中華電子佛典協會資料庫版權宣告】\n"
716
+ r += "</p></div><!-- end of cbeta-copyright -->\n"
717
+ end
718
+
719
+ def lem_note_cf(e)
720
+ # ex: T32n1670A.xml, p. 703a16
721
+ # <note type="cf1">K30n1002_p0257a01-a23</note>
722
+ refs = []
723
+ e.xpath('./note').each { |n|
724
+ if n.key?('type') and n['type'].start_with? 'cf'
725
+ s = n.content
726
+ if linehead_exist_in_cbeta(s)
727
+ s = "<span class='note_cf'>#{s}</span>"
728
+ end
729
+ refs << s
658
730
  end
731
+ }
732
+ if refs.empty?
733
+ ''
734
+ else
735
+ '修訂依據:' + refs.join(';') + '。'
659
736
  end
737
+ end
738
+
739
+ def lem_note_rdg(lem)
740
+ r = ''
741
+ app = lem.parent
742
+ @pass << false
743
+ app.xpath('rdg').each { |rdg|
744
+ if rdg['wit'].include? @orig
745
+ s = traverse(rdg, 'back')
746
+ s = MISSING if s.empty?
747
+ r += @orig + s
748
+ end
749
+ }
750
+ @pass.pop
751
+ r += '。' unless r.empty?
660
752
  r
661
753
  end
662
754
 
755
+ def line_info
756
+ "<span class='lineInfo' line='#{@lb}'></span>"
757
+ end
758
+
663
759
  def linehead_exist_in_cbeta(s)
664
760
  @xml_root
665
761
  corpus = s[0]
@@ -706,6 +802,14 @@ class CBETA::P5aToHTMLForEveryEdition
706
802
  @title = traverse(e, 'txt')
707
803
  @title = @title.split()[-1]
708
804
 
805
+ e = doc.at_xpath("//editionStmt/edition/date")
806
+ abort "找不到版本日期" if e.nil?
807
+ @edition_date = e.text.sub(/\$Date: (.*?) \$$/, '\1')
808
+
809
+ e = doc.at_xpath("//projectDesc/p[@lang='zh']")
810
+ abort "找不到貢獻者" if e.nil?
811
+ @contributors = e.text
812
+
709
813
  read_mod_notes(doc)
710
814
 
711
815
  root = doc.root()
@@ -753,6 +857,7 @@ class CBETA::P5aToHTMLForEveryEdition
753
857
  text = frag.to_html
754
858
 
755
859
  back = html_back(juan_no, ed)
860
+ copyright = html_copyright
756
861
 
757
862
  fn = ed.sub(/^【(.*)】$/, '\1')
758
863
  if fn != 'CBETA' and fn != @orig_short
@@ -764,7 +869,6 @@ class CBETA::P5aToHTMLForEveryEdition
764
869
  <html>
765
870
  <head>
766
871
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
767
- <meta name="filename" content="#{fn}" />
768
872
  <title>#{@title}</title>
769
873
  </head>
770
874
  <body>
@@ -772,6 +876,7 @@ class CBETA::P5aToHTMLForEveryEdition
772
876
  <div id='back'>
773
877
  #{back}
774
878
  </div>
879
+ #{copyright}
775
880
  </body></html>
776
881
  eos
777
882
  File.write(output_path, text)
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.1.5
4
+ version: 2.1.6
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-01-18 00:00:00.000000000 Z
11
+ date: 2016-01-22 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