softcover 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d65d2682e16c04b2e44f824e3032c4002935f270
4
- data.tar.gz: dae934f915b2b65d69fbd3130646c157ae533ed8
3
+ metadata.gz: 255b5cfa0a6625dc9350b9208b1dfd56d26ee59d
4
+ data.tar.gz: c49339cb5622c1b3f75e932c33b410b6d018aea3
5
5
  SHA512:
6
- metadata.gz: 934507312feb8d73c26fd7ad979842ffbe08c71459affc7fc2e99764062d675ea710178ccb90e713daeb1297f4007afefbec3323545c6dd9dc4a1ce14ea500c5
7
- data.tar.gz: b8a699b09007c623004f3b6106ecffe266a14b7ef5fa20faa9bb75a2bd22344ccd1c051d9e0d98d826956ecea07047cee610692f78723629fb189d8a0648be28
6
+ metadata.gz: 372a9db988acd7825e0b55a201d073372d11f76614adc8322c635f2b1d49f8d95d43310beff68118032b38b6217999f14e99c922e36d0d355e3efc01c51a6953
7
+ data.tar.gz: 600853585001e1e8150732932a3040ce81d4a071c1714900180d8cf7efac10b236072f17a08539268d4bdb9071a1c181a2cf4327605a2a868afc11ddbe24d871
@@ -17,6 +17,9 @@ class Softcover::BookManifest < OpenStruct
17
17
  end
18
18
  end
19
19
 
20
+ def escaped_title
21
+ CGI.escape_html(title)
22
+ end
20
23
 
21
24
  class NotFound < StandardError
22
25
  def message
@@ -28,6 +28,88 @@ module Softcover
28
28
  def images_dir
29
29
  path('epub/OEBPS/images')
30
30
  end
31
+
32
+ def escape(string)
33
+ CGI.escape_html(string)
34
+ end
35
+
36
+ # Returns a content.opf file based on a valid template.
37
+ def content_opf_template(title, copyright, author, uuid, cover_id,
38
+ toc_chapters, manifest_chapters, images)
39
+ %(<?xml version="1.0" encoding="UTF-8"?>
40
+ <package unique-identifier="BookID" version="3.0" xmlns="http://www.idpf.org/2007/opf">
41
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
42
+ xmlns:opf="http://www.idpf.org/2007/opf">
43
+ <dc:title>#{escape(title)}</dc:title>
44
+ <dc:language>en</dc:language>
45
+ <dc:rights>Copyright (c) #{copyright} #{escape(author)}</dc:rights>
46
+ <dc:creator>#{author}</dc:creator>
47
+ <dc:publisher>Softcover</dc:publisher>
48
+ <dc:identifier id="BookID">urn:uuid:#{uuid}</dc:identifier>
49
+ <meta property="dcterms:modified">#{Time.now.strftime('%Y-%m-%dT%H:%M:%S')}Z</meta>
50
+ <meta name="cover" content="#{cover_id}"/>
51
+ </metadata>
52
+ <manifest>
53
+ <item href="nav.html" id="nav" media-type="application/xhtml+xml" properties="nav"/>
54
+ <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
55
+ <item id="page-template.xpgt" href="styles/page-template.xpgt" media-type="application/vnd.adobe-page-template+xml"/>
56
+ <item id="pygments.css" href="styles/pygments.css" media-type="text/css"/>
57
+ <item id="softcover.css" href="styles/softcover.css" media-type="text/css"/>
58
+ <item id="epub.css" href="styles/epub.css" media-type="text/css"/>
59
+ <item id="custom.css" href="styles/custom.css" media-type="text/css"/>
60
+ <item id="custom_epub.css" href="styles/custom_epub.css" media-type="text/css"/>
61
+ <item id="cover" href="cover.html" media-type="application/xhtml+xml"/>
62
+ #{manifest_chapters.join("\n")}
63
+ #{images.join("\n")}
64
+ </manifest>
65
+ <spine toc="ncx">
66
+ <itemref idref="cover" linear="no" />
67
+ #{toc_chapters.join("\n")}
68
+ </spine>
69
+ </package>
70
+ )
71
+ end
72
+
73
+ # Returns a toc.ncx file based on a valid template.
74
+ def toc_ncx_template(title, uuid, chapter_nav)
75
+ %(<?xml version="1.0" encoding="UTF-8"?>
76
+ <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
77
+ <head>
78
+ <meta name="dtb:uid" content="#{uuid}"/>
79
+ <meta name="dtb:depth" content="2"/>
80
+ <meta name="dtb:totalPageCount" content="0"/>
81
+ <meta name="dtb:maxPageNumber" content="0"/>
82
+ </head>
83
+ <docTitle>
84
+ <text>#{escape(title)}</text>
85
+ </docTitle>
86
+ <navMap>
87
+ #{chapter_nav.join("\n")}
88
+ </navMap>
89
+ </ncx>
90
+ )
91
+ end
92
+
93
+ # Returns the navigation HTML based on a valid template.
94
+ def nav_html_template(title, nav_list)
95
+ %(<?xml version="1.0" encoding="utf-8"?>
96
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
97
+ <head>
98
+ <meta charset="UTF-8" />
99
+ <title>#{title}</title>
100
+ </head>
101
+ <body>
102
+ <nav epub:type="toc">
103
+ <h1>#{escape(title)}</h1>
104
+ <ol>
105
+ #{nav_list.join("\n")}
106
+ </ol>
107
+ </nav>
108
+ </body>
109
+ </html>
110
+ )
111
+ end
112
+
31
113
  end
32
114
 
33
115
  module Builders
@@ -372,10 +454,6 @@ module Softcover
372
454
 
373
455
  # Returns the content configuration file.
374
456
  def content_opf
375
- title = manifest.title
376
- author = manifest.author
377
- copyright = manifest.copyright
378
- uuid = manifest.uuid
379
457
  man_ch = chapters.map do |chapter|
380
458
  %(<item id="#{chapter.slug}" href="#{chapter.fragment_name}" media-type="application/xhtml+xml"/>)
381
459
  end
@@ -396,38 +474,9 @@ module Softcover
396
474
  id = "img-#{label}"
397
475
  %(<item id="#{id}" href="#{href}" media-type="image/#{ext}"/>)
398
476
  end
399
- %(<?xml version="1.0" encoding="UTF-8"?>
400
- <package unique-identifier="BookID" version="3.0" xmlns="http://www.idpf.org/2007/opf">
401
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
402
- xmlns:opf="http://www.idpf.org/2007/opf">
403
- <dc:title>#{title}</dc:title>
404
- <dc:language>en</dc:language>
405
- <dc:rights>Copyright (c) #{copyright} #{author}</dc:rights>
406
- <dc:creator>#{author}</dc:creator>
407
- <dc:publisher>Softcover</dc:publisher>
408
- <dc:identifier id="BookID">urn:uuid:#{uuid}</dc:identifier>
409
- <meta property="dcterms:modified">#{Time.now.strftime('%Y-%m-%dT%H:%M:%S')}Z</meta>
410
- <meta name="cover" content="#{cover_id}"/>
411
- </metadata>
412
- <manifest>
413
- <item href="nav.html" id="nav" media-type="application/xhtml+xml" properties="nav"/>
414
- <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
415
- <item id="page-template.xpgt" href="styles/page-template.xpgt" media-type="application/vnd.adobe-page-template+xml"/>
416
- <item id="pygments.css" href="styles/pygments.css" media-type="text/css"/>
417
- <item id="softcover.css" href="styles/softcover.css" media-type="text/css"/>
418
- <item id="epub.css" href="styles/epub.css" media-type="text/css"/>
419
- <item id="custom.css" href="styles/custom.css" media-type="text/css"/>
420
- <item id="custom_epub.css" href="styles/custom_epub.css" media-type="text/css"/>
421
- <item id="cover" href="cover.html" media-type="application/xhtml+xml"/>
422
- #{man_ch.join("\n")}
423
- #{images.join("\n")}
424
- </manifest>
425
- <spine toc="ncx">
426
- <itemref idref="cover" linear="no" />
427
- #{toc_ch.join("\n")}
428
- </spine>
429
- </package>
430
- )
477
+ content_opf_template(manifest.title, manifest.copyright,
478
+ manifest.author, manifest.uuid, cover_id,
479
+ toc_ch, man_ch, images)
431
480
  end
432
481
 
433
482
  def cover_page
@@ -452,7 +501,6 @@ module Softcover
452
501
 
453
502
  # Returns the Table of Contents for the spine.
454
503
  def toc_ncx
455
- title = manifest.title
456
504
  chapter_nav = []
457
505
  chapters.each_with_index do |chapter, n|
458
506
  chapter_nav << %(<navPoint id="#{chapter.slug}" playOrder="#{n+1}">)
@@ -460,22 +508,7 @@ module Softcover
460
508
  chapter_nav << %( <content src="#{chapter.fragment_name}"/>)
461
509
  chapter_nav << %(</navPoint>)
462
510
  end
463
- %(<?xml version="1.0" encoding="UTF-8"?>
464
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
465
- <head>
466
- <meta name="dtb:uid" content="#{manifest.uuid}"/>
467
- <meta name="dtb:depth" content="2"/>
468
- <meta name="dtb:totalPageCount" content="0"/>
469
- <meta name="dtb:maxPageNumber" content="0"/>
470
- </head>
471
- <docTitle>
472
- <text>#{title}</text>
473
- </docTitle>
474
- <navMap>
475
- #{chapter_nav.join("\n")}
476
- </navMap>
477
- </ncx>
478
- )
511
+ toc_ncx_template(manifest.title, manifest.uuid, chapter_nav)
479
512
  end
480
513
 
481
514
  def chapter_name(n)
@@ -484,27 +517,11 @@ module Softcover
484
517
 
485
518
  # Returns the nav HTML content.
486
519
  def nav_html
487
- title = manifest.title
488
520
  nav_list = manifest.chapters.map do |chapter|
489
521
  element = preview? ? chapter.title : nav_link(chapter)
490
522
  %(<li>#{element}</li>)
491
523
  end
492
- %(<?xml version="1.0" encoding="utf-8"?>
493
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
494
- <head>
495
- <meta charset="UTF-8" />
496
- <title>#{title}</title>
497
- </head>
498
- <body>
499
- <nav epub:type="toc">
500
- <h1>#{title}</h1>
501
- <ol>
502
- #{nav_list.join("\n")}
503
- </ol>
504
- </nav>
505
- </body>
506
- </html>
507
- )
524
+ nav_html_template(manifest.title, nav_list)
508
525
  end
509
526
 
510
527
  # Returns a navigation link for the chapter.
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/softcover.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency 'polytexnic', '~> 1.0.1'
21
+ gem.add_dependency 'polytexnic', '~> 1.0.2'
22
22
  gem.add_dependency 'msgpack', '~> 0.4.2'
23
23
  gem.add_dependency 'nokogiri', '~> 1.6.0'
24
24
  gem.add_dependency 'thor', '~> 0.18.1'
@@ -222,3 +222,55 @@ describe Softcover::Builders::Epub do
222
222
  end
223
223
  end
224
224
  end
225
+
226
+ describe Softcover::EpubUtils do
227
+ let(:dummy_class) { Class.new { include Softcover::EpubUtils } }
228
+ let(:title) { 'Foo Bar & Grill' }
229
+ let(:uuid) { '550e8400-e29b-41d4-a716-446655440000' }
230
+
231
+ context "content.opf template" do
232
+ let(:copyright) { '2015' }
233
+ let(:author) { "Laurel & Hardy" }
234
+ let(:cover_id) { '17' }
235
+ let(:toc_chapters) { [] }
236
+ let(:manifest_chapters) { [] }
237
+ let(:images) { [] }
238
+
239
+ let(:template) do
240
+ dummy_class.new.content_opf_template(title, copyright, author, uuid,
241
+ cover_id, toc_chapters,
242
+ manifest_chapters, images)
243
+ end
244
+
245
+ it "should have the right (escaped) content" do
246
+ expect(template).to include('Foo Bar &amp; Grill')
247
+ expect(template).to include('Laurel &amp; Hardy')
248
+ expect(template).to include(copyright)
249
+ expect(template).to include(uuid)
250
+ expect(template).to include(cover_id)
251
+ end
252
+ end
253
+
254
+ context "toc.ncx template" do
255
+ let(:chapter_nav) { [] }
256
+ let(:template) do
257
+ dummy_class.new.toc_ncx_template(title, uuid, chapter_nav)
258
+ end
259
+
260
+ it "should have the right (escaped) content" do
261
+ expect(template).to include('Foo Bar &amp; Grill')
262
+ expect(template).to include(uuid)
263
+ end
264
+ end
265
+
266
+ context "nav.html template" do
267
+ let(:nav_list) { [] }
268
+ let(:template) do
269
+ dummy_class.new.nav_html_template(title, nav_list)
270
+ end
271
+
272
+ it "should have the right (escaped) content" do
273
+ expect(template).to include('Foo Bar &amp; Grill')
274
+ end
275
+ end
276
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softcover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-07 00:00:00.000000000 Z
12
+ date: 2015-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polytexnic
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.1
20
+ version: 1.0.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.1
27
+ version: 1.0.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: msgpack
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -1071,7 +1071,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1071
1071
  version: '0'
1072
1072
  requirements: []
1073
1073
  rubyforge_project:
1074
- rubygems_version: 2.4.4
1074
+ rubygems_version: 2.2.2
1075
1075
  signing_key:
1076
1076
  specification_version: 4
1077
1077
  summary: A typesetting system for technical authors