cbeta 0.5.1 → 0.5.2

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: 17bb523411446bf9b5c62e2f8d8f7fee94b4ece5
4
- data.tar.gz: 5c61e23af96517ac7ebee712aa436b0a0cc7b4a8
3
+ metadata.gz: 1afe98f3c3553447bfd99a1e7e8c4ebdcc3e069b
4
+ data.tar.gz: a624b382995d4b4711a59b4ac9726c8e9d430287
5
5
  SHA512:
6
- metadata.gz: ed3587f8f479046027ba4eb0af8c9ad9c41e9a2e07ebc586046dfa08d8172039a636cc8d7d11edf69356c73d6c37009584f96805caf748c6c60521841e69eb32
7
- data.tar.gz: 7cd3eb6d05c5a2acce351ebd4c8326ba1e9830413a9270d88579ca0b00819f8007235d297e099808323f0108bd901a007c88d96ba9a1555141d82c9fc2985a65
6
+ metadata.gz: 6aa6b616b15193fc7f025218d87b5a61a9a075eef2636a07ea2b0e06a63bb6f2bb8d7332bcfd07b148c4beca6aef32742ee296185e833b987309f015560101f3
7
+ data.tar.gz: 08a3509757d9563796f4371cdd8d686dca18dac66e09f6848d612fa39c0d7bf8bc4eaa96008274ccc7f034e45a079658fdcb41a5fe5276e078062e42dd34f8d7
@@ -23,17 +23,30 @@ class CBETA::P5aToEPUB
23
23
  DATA = File.join(SCRIPT_FOLDER, '../data')
24
24
 
25
25
  # @param temp_folder [String] 供 EPUB 暫存工作檔案的路徑
26
- # @param options [Hash]
27
- # :epub_version [Integer] EPUB 版本,預設為 3
28
- # :graphic_base [String] 圖檔路徑
29
- # :readme [String] 說明檔,如果沒指定的話,就使用預設說明檔
30
- def initialize(temp_folder, options={})
26
+ # @option opts [Integer] :epub_version (3) EPUB 版本
27
+ # @option opts [String] :graphic_base 圖檔路徑
28
+ # @option opts [String] :front_page 內文前可以加一份 HTML 檔,例如「編輯說明」
29
+ # @option opts [String] :front_page_title 加在目錄的 front_page 標題
30
+ # @option opts [String] :back_page 內文後可以加一份 HTML 檔,例如「版權聲明」
31
+ # @option opts [String] :back_page_title 加在目錄的 back_page 標題
32
+ #
33
+ # @example
34
+ # options = {
35
+ # epub_version: 3,
36
+ # front_page: '/path/to/front_page.xhtml',
37
+ # front_page_title: '編輯說明',
38
+ # back_page: '/path/to/back_page.xhtml',
39
+ # back_page_title: '贊助資訊',
40
+ # graphic_base: '/path/to/grphic/files/root'
41
+ # }
42
+ # c = CBETA::P5aToEPUB.new('/path/to/temp/working/folder', options)
43
+ # c.convert_folder('/path/to/xml/roo', '/path/for/output/epubs')
44
+ def initialize(temp_folder, opts={})
31
45
  @temp_folder = temp_folder
32
46
  @settings = {
33
- epub_version: 3,
34
- readme: File.join(DATA, 'epub-readme.xhtml')
47
+ epub_version: 3
35
48
  }
36
- @settings.merge!(options)
49
+ @settings.merge!(opts)
37
50
  puts @settings
38
51
  @cbeta = CBETA.new
39
52
  @gaijis = CBETA::Gaiji.new
@@ -131,10 +144,13 @@ class CBETA::P5aToEPUB
131
144
  end
132
145
 
133
146
  def create_epub(output_path)
134
- copy_static_files(@settings[:readme], 'readme.xhtml')
147
+ if @settings[:front_page]
148
+ copy_static_files(@settings[:front_page], 'front.xhtml')
149
+ end
135
150
 
136
- src = File.join(DATA, 'epub-donate.xhtml')
137
- copy_static_files(src, 'donate.xhtml')
151
+ if @settings[:back_page]
152
+ copy_static_files(@settings[:back_page], 'back.xhtml')
153
+ end
138
154
 
139
155
  src = File.join(DATA, 'epub.css')
140
156
  copy_static_files(src, 'cbeta.css')
@@ -157,6 +173,7 @@ class CBETA::P5aToEPUB
157
173
  }
158
174
 
159
175
  juan_dir = File.join(@temp_folder, 'juans')
176
+ settings = @settings
160
177
  # in resources block, you can define resources by its relative path and datasource.
161
178
  # item creator methods are: files, file.
162
179
  builder.resources(:workdir => @temp_folder) {
@@ -168,12 +185,14 @@ class CBETA::P5aToEPUB
168
185
 
169
186
  # ordered item. will be added to spine.
170
187
  ordered {
171
- file 'readme.xhtml'
188
+ file 'front.xhtml' if settings[:front_page]
189
+
172
190
  Dir.entries(juan_dir).sort.each do |f|
173
191
  next if f.start_with? '.'
174
192
  file "juans/#{f}"
175
193
  end
176
- file 'donate.xhtml'
194
+
195
+ file 'back.xhtml' if settings[:back_page]
177
196
  }
178
197
  }
179
198
  builder.book.version = @settings[:epub_version]
@@ -220,10 +239,19 @@ eos
220
239
  end
221
240
 
222
241
  def create_nav_html
223
- @nav_root_ol.add_child("<li><a href='donate.xhtml'>贊助資訊</a></li>")
242
+ if @settings[:back_page_title]
243
+ s = @settings[:back_page_title]
244
+ @nav_root_ol.add_child("<li><a href='back.xhtml'>#{s}</a></li>")
245
+ end
246
+
247
+ #s = @nav_root_ol.to_xml(indent: 2, encoding: 'UTF-8', pertty: true, :save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
248
+ s = @nav_root_ol.to_xml
249
+
250
+
251
+ s += "" % @toc_juan
224
252
 
225
253
  fn = File.join(@temp_folder, 'nav.xhtml')
226
- s = NAV_TEMPLATE % to_html(@nav_root_ol)
254
+ s = NAV_TEMPLATE % s
227
255
  File.write(fn, s)
228
256
  end
229
257
 
@@ -243,7 +271,6 @@ eos
243
271
 
244
272
  def handle_byline(e)
245
273
  r = '<p class="byline">'
246
- r += "<span class='lineInfo'>#{@lb}</span>"
247
274
  r += traverse(e)
248
275
  r + '</p>'
249
276
  end
@@ -258,7 +285,7 @@ eos
258
285
  end
259
286
 
260
287
  def handle_corr(e)
261
- traverse(e)
288
+ "<span class='corr'>" + traverse(e) + "</span>"
262
289
  end
263
290
 
264
291
  def handle_div(e)
@@ -343,7 +370,7 @@ eos
343
370
  r = ''
344
371
  unless e['type'] == 'added'
345
372
  i = @open_divs.size
346
- r = "<p class='head' data-head-level='#{i}'>%s</p>" % traverse(e)
373
+ r = "<p class='h#{i}'>%s</p>" % traverse(e)
347
374
  end
348
375
  r
349
376
  end
@@ -410,7 +437,14 @@ eos
410
437
  end
411
438
 
412
439
  def handle_lem(e)
413
- r = traverse(e)
440
+ r = ''
441
+ w = e['wit']
442
+ if w.include? 'CBETA' and not w.include? @orig
443
+ r = "<span class='corr'>%s</span>" % traverse(e)
444
+ else
445
+ r = traverse(e)
446
+ end
447
+ r
414
448
  end
415
449
 
416
450
  def handle_lg(e)
@@ -456,19 +490,22 @@ eos
456
490
  end
457
491
 
458
492
  def handle_mulu(e)
459
- return '' if e['type'] == '卷'
460
-
461
- level = e['level'].to_i
462
- while @current_nav.size > level
463
- @current_nav.pop
464
- end
465
-
466
- label = traverse(e, 'txt')
467
493
  @mulu_count += 1
468
494
  fn = "juans/%03d.xhtml" % @juan
469
- li = @current_nav.last.add_child("<li><a href='#{fn}#mulu#{@mulu_count}'>#{label}</a></li>").first
470
- ol = li.add_child('<ol></ol>').first
471
- @current_nav << ol
495
+ if e['type'] == ''
496
+ label = e['n']
497
+ @juan_nav.add_child("<li><a href='#{fn}#mulu#{@mulu_count}'>#{label}</a></li>")
498
+ else
499
+ level = e['level'].to_i
500
+ while @current_nav.size > (level+1)
501
+ @current_nav.pop
502
+ end
503
+
504
+ label = traverse(e, 'txt')
505
+ li = @current_nav.last.add_child("<li><a href='#{fn}#mulu#{@mulu_count}'>#{label}</a></li>").first
506
+ ol = li.add_child('<ol></ol>').first
507
+ @current_nav << ol
508
+ end
472
509
  "<a id='mulu#{@mulu_count}' />"
473
510
  end
474
511
 
@@ -666,11 +703,21 @@ eos
666
703
  @nav_root_ol = @nav_doc.at_xpath('//ol')
667
704
  @current_nav = [@nav_root_ol]
668
705
 
669
- @nav_root_ol.add_child("<li><a href='readme.xhtml'>編輯說明</a></li>")
706
+ if @settings[:front_page_title]
707
+ @nav_root_ol.add_child("<li><a href='readme.xhtml'>編輯說明</a></li>")
708
+ end
709
+
710
+ li = @nav_root_ol.add_child("<li><a href='#'>章節目次</a></li>").first
711
+ ol = li.add_child('<ol></ol>').first
712
+ @current_nav << ol
713
+
714
+ li = @nav_root_ol.add_child("<li><a href='#'>卷目次</a></li>").first
715
+ @juan_nav = li.add_child('<ol></ol>').first
670
716
 
671
717
  @mulu_count = 0
672
718
  @main_text = ''
673
719
  @dila_note = 0
720
+ @toc_juan = '' # 卷目次
674
721
 
675
722
  FileUtils::mkdir_p File.join(@temp_folder, 'img')
676
723
  FileUtils::mkdir_p File.join(@temp_folder, 'juans')
@@ -1,3 +1,46 @@
1
+ div.p {
2
+ margin-bottom: 20px;
3
+ line-height: 1.4;
4
+ text-indent: 2em;
5
+ }
6
+ p.byline {
7
+ text-align: right;
8
+ }
9
+ p.h1 {
10
+ text-indent: 2em;
11
+ font-weight: bold;
12
+ }
13
+ p.h2 {
14
+ text-indent: 3em;
15
+ font-weight: bold;
16
+ }
17
+ p.h3 {
18
+ text-indent: 4em;
19
+ font-weight: bold;
20
+ }
21
+ p.h4 {
22
+ text-indent: 2em;
23
+ font-weight: bold;
24
+ }
25
+ p.h5 {
26
+ text-indent: 3em;
27
+ font-weight: bold;
28
+ }
29
+ p.h6 {
30
+ text-indent: 4em;
31
+ font-weight: bold;
32
+ }
33
+ p.h7 {
34
+ text-indent: 2em;
35
+ font-weight: bold;
36
+ }
37
+ p.h8 {
38
+ text-indent: 2em;
39
+ font-weight: bold;
40
+ }
41
+ span.corr {
42
+ color: red;
43
+ }
1
44
  table {
2
45
  border-collapse: collapse;
3
46
  }
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: 0.5.1
4
+ version: 0.5.2
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-08-24 00:00:00.000000000 Z
11
+ date: 2015-08-25 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
@@ -25,9 +25,7 @@ files:
25
25
  - lib/cbeta/p5a_to_simple_html.rb
26
26
  - lib/cbeta/p5a_to_text.rb
27
27
  - lib/data/canons.csv
28
- - lib/data/epub-donate.xhtml
29
28
  - lib/data/epub-nav.xhtml
30
- - lib/data/epub-readme.xhtml
31
29
  - lib/data/epub.css
32
30
  - lib/data/gaiji.json
33
31
  - lib/data/unicode-1.1.json
@@ -1,17 +0,0 @@
1
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW" xmlns:xml="http://www.w3.org/XML/1998/namespace">
2
- <head>
3
- <title>贊助</title>
4
- </head>
5
-
6
- <body>
7
- <p><b>歡迎隨喜贊助</b></p>
8
-
9
- <p><b>劃撥捐款</b></p>
10
-
11
- <p>郵政劃撥帳號:19624224</p>
12
-
13
- <p>戶名:財團法人智諭老和尚教育紀念基金會</p>
14
-
15
- <p>若欲指定特殊用途者,請特別註明,我們會專款專用。</p>
16
- </body>
17
- </html>
@@ -1,25 +0,0 @@
1
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW" xmlns:xml="http://www.w3.org/XML/1998/namespace">
2
- <head>
3
- <title>說明</title>
4
- </head>
5
-
6
- <body>
7
- <div>
8
- <h2>編輯說明</h2>
9
-
10
- <ul>
11
- <li>本電子書以「CBETA 電子佛典集成 Version 2014」為資料來源。</li>
12
-
13
- <li>漢字呈現以 Unicode 1.1 為基礎,不在此範圍的字則採用<a href="http://www.cbeta.org/format/rare-rule.php">組字式</a>表達。</li>
14
-
15
- <li>梵文悉曇字及蘭札字均採用羅馬轉寫字,如無轉寫字則提供字型圖檔。</li>
16
-
17
- <li>CBETA 對底本所做的修訂用字以紅色字元表示。(部份 ePub 閱讀器可能無法呈現指定的顏色)</li>
18
-
19
- <li>若有發現任何問題,歡迎來函 <a href="mailto:service@cbeta.org">service@cbeta.org</a> 回報。</li>
20
-
21
- <li><a href="http://www.cbeta.org/copyright.php">版權所有</a>,歡迎自由流通,但禁止營利使用。</li>
22
- </ul><br />
23
- </div>
24
- </body>
25
- </html>