softcover 1.1.21 → 1.1.22
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/softcover/builders/epub.rb +47 -15
- data/lib/softcover/version.rb +1 -1
- 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: 72e252aa13bbad0e3f8324319dbc95735e44b543
|
4
|
+
data.tar.gz: e0103feb26670764f118d26adec63daf3ad72f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc00bf1862a43dbb8a3ba1abfd91c447e1075992103b01412eb9e9141412f244d35059655ec6062d2d11265001c44a8026277953b443281de138d1e9bac1fa37
|
7
|
+
data.tar.gz: 53df4405acc260fed02cfd3d2d075316afbe1b961422fc7c9f70baba1df9e1f58e23526ef2e656f79746e5ed599933e14cd5c78228a807961cc9367f34464ca4
|
@@ -141,12 +141,12 @@ module Softcover
|
|
141
141
|
write_mimetype
|
142
142
|
write_container_xml
|
143
143
|
write_ibooks_xml
|
144
|
-
write_toc
|
145
|
-
write_nav
|
146
144
|
copy_image_files
|
147
145
|
write_html(options)
|
148
146
|
write_contents(options)
|
149
147
|
create_style_files(options)
|
148
|
+
write_toc
|
149
|
+
write_nav
|
150
150
|
make_epub(options)
|
151
151
|
move_epub
|
152
152
|
end
|
@@ -472,9 +472,9 @@ module Softcover
|
|
472
472
|
man_ch = chapters.map do |chapter|
|
473
473
|
%(<item id="#{chapter.slug}" href="#{chapter.fragment_name}" media-type="application/xhtml+xml"/>)
|
474
474
|
end
|
475
|
-
|
476
|
-
|
477
|
-
|
475
|
+
toc_ch = chapters.map do |chapter|
|
476
|
+
%(<itemref idref="#{chapter.slug}"/>)
|
477
|
+
end
|
478
478
|
image_files = Dir['epub/OEBPS/images/**/*'].select { |f| File.file?(f) }
|
479
479
|
images = image_files.map do |image|
|
480
480
|
ext = File.extname(image).sub('.', '') # e.g., 'png'
|
@@ -517,25 +517,44 @@ module Softcover
|
|
517
517
|
# Returns the Table of Contents for the spine.
|
518
518
|
def toc_ncx
|
519
519
|
chapter_nav = []
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
520
|
+
|
521
|
+
if article?
|
522
|
+
article = chapters.first
|
523
|
+
section_names_and_ids(article).each_with_index do |(name, id), n|
|
524
|
+
chapter_nav << %(<navPoint id="#{id}" playOrder="#{n+1}">)
|
525
|
+
chapter_nav << %( <navLabel><text>#{escape(name)}</text></navLabel>)
|
526
|
+
chapter_nav << %( <content src="#{article.fragment_name}##{id}"/>)
|
527
|
+
chapter_nav << %(</navPoint>)
|
528
|
+
end
|
529
|
+
else
|
530
|
+
chapters.each_with_index do |chapter, n|
|
531
|
+
chapter_nav << %(<navPoint id="#{chapter.slug}" playOrder="#{n+1}">)
|
532
|
+
chapter_nav << %( <navLabel><text>#{chapter_name(n)}</text></navLabel>)
|
533
|
+
chapter_nav << %( <content src="#{chapter.fragment_name}"/>)
|
534
|
+
chapter_nav << %(</navPoint>)
|
535
|
+
end
|
525
536
|
end
|
526
537
|
toc_ncx_template(manifest.title, manifest.uuid, chapter_nav)
|
527
538
|
end
|
528
539
|
|
529
540
|
def chapter_name(n)
|
530
|
-
n == 0 ? language_labels["frontmatter"]
|
541
|
+
n == 0 ? language_labels["frontmatter"]
|
542
|
+
: "#{chapter_label(n)}: #{chapters[n].title}"
|
531
543
|
end
|
532
544
|
|
533
545
|
# Returns the nav HTML content.
|
534
546
|
def nav_html
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
547
|
+
if article?
|
548
|
+
article = chapters.first
|
549
|
+
nav_list = section_names_and_ids(article).map do |name, id|
|
550
|
+
%(<li> <a href="#{article.fragment_name}##{id}">#{name}</a></li>)
|
551
|
+
end
|
552
|
+
else
|
553
|
+
nav_list = manifest.chapters.map do |chapter|
|
554
|
+
element = preview? ? chapter.title : nav_link(chapter)
|
555
|
+
%(<li>#{element}</li>)
|
556
|
+
end
|
557
|
+
end
|
539
558
|
nav_html_template(manifest.title, nav_list)
|
540
559
|
end
|
541
560
|
|
@@ -544,6 +563,19 @@ module Softcover
|
|
544
563
|
%(<a href="#{chapter.fragment_name}">#{chapter.html_title}</a>)
|
545
564
|
end
|
546
565
|
|
566
|
+
# Returns a list of the section names and CSS ids.
|
567
|
+
# Form is [['Beginning', 'sec-beginning'], ['Next', 'sec-next']]
|
568
|
+
def section_names_and_ids(article)
|
569
|
+
# Grab section names and ids from the article.
|
570
|
+
filename = File.join('epub', 'OEBPS', article.fragment_name)
|
571
|
+
doc = Nokogiri::HTML(File.read(filename))
|
572
|
+
names = doc.css('div.section>h2').map do |s|
|
573
|
+
s.children.children.last.content
|
574
|
+
end
|
575
|
+
ids = doc.css('div.section').map { |s| s.attributes['id'].value }
|
576
|
+
names.zip(ids)
|
577
|
+
end
|
578
|
+
|
547
579
|
# Returns the HTML template for a chapter.
|
548
580
|
def chapter_template(title, content)
|
549
581
|
%(<?xml version="1.0" encoding="utf-8"?>
|
data/lib/softcover/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.22
|
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:
|
12
|
+
date: 2016-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polytexnic
|