softcover 0.9.12 → 0.9.13
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/book.rb +1 -1
- data/lib/softcover/builders/epub.rb +23 -4
- data/lib/softcover/builders/html.rb +2 -0
- data/lib/softcover/cli.rb +1 -0
- data/lib/softcover/commands/publisher.rb +2 -1
- data/lib/softcover/config.rb +8 -4
- data/lib/softcover/mathjax.rb +10 -2
- data/lib/softcover/template/gitignore +2 -2
- data/lib/softcover/template/images/cover-web.png +0 -0
- data/lib/softcover/template/images/cover.jpg +0 -0
- data/lib/softcover/template/images/cover.pdf +885 -795
- data/lib/softcover/template/images/cover.png +0 -0
- data/lib/softcover/template/images/testimonial_1.png +0 -0
- data/lib/softcover/version.rb +1 -1
- data/softcover.gemspec +1 -1
- data/spec/book_spec.rb +2 -3
- data/spec/builders/epub_spec.rb +12 -0
- data/spec/builders/html_spec.rb +9 -5
- data/spec/commands/generator_spec.rb +1 -1
- data/spec/config_spec.rb +30 -0
- data/spec/webmock_helpers.rb +1 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6c5968c1ee3aa5ac80ae5778c8bd261b276c06a
|
4
|
+
data.tar.gz: 616dcfa6a161311f6717d6461f1ce2a9f91fdf78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60248392104ecb71d092cb9e4241e066ee40a5ef48152d9ec8559a6a4c8fa3a56fe4c61809630710b5563abb1924481deb3b2c58bbcfdb9042170edbf7a79772
|
7
|
+
data.tar.gz: 01e5daacfbc9c515083ec92b6b75b78d9bc113695d964025c979290010fa72adaf21d18bdfb66b8ff576f26e7f080cf0be13d5694bb3dfc3a4e0934a4ef3afa0
|
data/lib/softcover/book.rb
CHANGED
@@ -57,7 +57,7 @@ class Softcover::Book
|
|
57
57
|
|
58
58
|
# get array of paths and checksums
|
59
59
|
def files
|
60
|
-
paths = %
|
60
|
+
paths = %W{html/#{slug}.html html/*_fragment.html images/**/* config/*}
|
61
61
|
Dir[*paths].map do |path|
|
62
62
|
BookFile.new(path) unless File.directory?(path)
|
63
63
|
end.compact
|
@@ -70,12 +70,11 @@ module Softcover
|
|
70
70
|
# Included is a math detector that processes the page with MathJax
|
71
71
|
# (via page.js) so that math can be included in EPUB (and thence MOBI).
|
72
72
|
def write_html(options={})
|
73
|
-
images_dir = File.join('epub', 'OEBPS', 'images')
|
74
73
|
texmath_dir = File.join(images_dir, 'texmath')
|
75
74
|
mkdir images_dir
|
76
75
|
mkdir texmath_dir
|
77
76
|
|
78
|
-
File.write(path('epub/OEBPS/cover.html'), cover_page)
|
77
|
+
File.write(path('epub/OEBPS/cover.html'), cover_page) if cover?
|
79
78
|
|
80
79
|
pngs = []
|
81
80
|
chapters.each_with_index do |chapter, i|
|
@@ -113,6 +112,10 @@ module Softcover
|
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
115
|
+
def images_dir
|
116
|
+
File.join('epub', 'OEBPS', 'images')
|
117
|
+
end
|
118
|
+
|
116
119
|
# Returns HTML for HTML source that includes math.
|
117
120
|
# As a side-effect, html_with_math creates PNGs corresponding to any
|
118
121
|
# math in the given source. The technique involves using PhantomJS to
|
@@ -316,6 +319,7 @@ module Softcover
|
|
316
319
|
image_files = Dir['epub/OEBPS/images/**/*'].select { |f| File.file?(f) }
|
317
320
|
images = image_files.map do |image|
|
318
321
|
ext = File.extname(image).sub('.', '') # e.g., 'png'
|
322
|
+
ext = 'jpeg' if ext == 'jpg'
|
319
323
|
# Strip off the leading 'epub/OEBPS'.
|
320
324
|
sep = File::SEPARATOR
|
321
325
|
href = image.split(sep)[2..-1].join(sep)
|
@@ -337,7 +341,7 @@ module Softcover
|
|
337
341
|
<dc:publisher>Softcover</dc:publisher>
|
338
342
|
<dc:identifier id="BookID">urn:uuid:#{uuid}</dc:identifier>
|
339
343
|
<meta property="dcterms:modified">#{Time.now.strftime('%Y-%m-%dT%H:%M:%S')}Z</meta>
|
340
|
-
<meta name="cover" content="
|
344
|
+
<meta name="cover" content="cover-image"/>
|
341
345
|
</metadata>
|
342
346
|
<manifest>
|
343
347
|
<item href="nav.html" id="nav" media-type="application/xhtml+xml" properties="nav"/>
|
@@ -369,13 +373,28 @@ module Softcover
|
|
369
373
|
</head>
|
370
374
|
<body>
|
371
375
|
<div id="cover">
|
372
|
-
<img width="573" height="800" src="images
|
376
|
+
<img width="573" height="800" src="images/#{cover_img}" alt="cover" />
|
373
377
|
</div>
|
374
378
|
</body>
|
375
379
|
</html>
|
376
380
|
)
|
377
381
|
end
|
378
382
|
|
383
|
+
# Returns the name of the cover file.
|
384
|
+
# We support (in order) JPG/JPEG, PNG, and TIF.
|
385
|
+
def cover_img
|
386
|
+
extensions = %w[jpg jpeg ng tif]
|
387
|
+
extensions.each do |ext|
|
388
|
+
file = Dir[path("#{images_dir}/cover.#{ext}")].first
|
389
|
+
return File.basename(file) if file
|
390
|
+
end
|
391
|
+
return false
|
392
|
+
end
|
393
|
+
|
394
|
+
def cover?
|
395
|
+
cover_img
|
396
|
+
end
|
397
|
+
|
379
398
|
# Returns the Table of Contents for the spine.
|
380
399
|
def toc_ncx
|
381
400
|
title = manifest.title
|
@@ -44,6 +44,8 @@ module Softcover
|
|
44
44
|
basename = File.basename(manifest.filename, '.tex')
|
45
45
|
@html = converted_html(basename)
|
46
46
|
@title = basename
|
47
|
+
@mathjax = Softcover::Mathjax::config(chapter_number: false)
|
48
|
+
@src = Softcover::Mathjax::AMS_SVG
|
47
49
|
erb_file = File.read(File.join(File.dirname(__FILE__),
|
48
50
|
'..', 'server', 'views',
|
49
51
|
'book.html.erb'))
|
data/lib/softcover/cli.rb
CHANGED
@@ -85,7 +85,8 @@ module Softcover::Commands::Publisher
|
|
85
85
|
|
86
86
|
def exit_with_message
|
87
87
|
number = current_book.processed_media.size
|
88
|
-
|
88
|
+
dir = number == 1 ? "directory" : "directories"
|
89
|
+
puts "Processed #{number} #{dir}"
|
89
90
|
end
|
90
91
|
|
91
92
|
def unpublish!(slug=nil)
|
data/lib/softcover/config.rb
CHANGED
@@ -41,18 +41,22 @@ module Softcover
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def file_path
|
44
|
-
File.expand_path(
|
45
|
-
|
44
|
+
File.expand_path(path).tap do |full_path|
|
45
|
+
full_path.gsub!(/$/,"-test") if Softcover::test?
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
class BookConfig < BaseConfig
|
52
|
-
|
52
|
+
def self.path
|
53
|
+
".softcover-book"
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
class Config < BaseConfig
|
56
|
-
|
58
|
+
def self.path
|
59
|
+
File.exists?(".softcover") ? ".softcover" : "~/.softcover"
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
data/lib/softcover/mathjax.rb
CHANGED
@@ -7,9 +7,17 @@ module Softcover
|
|
7
7
|
# Call .inspect.inspect to escape the chapter number
|
8
8
|
# code for interpolation.
|
9
9
|
options[:chapter_number].inspect.inspect
|
10
|
-
|
10
|
+
elsif options[:chapter_number].nil?
|
11
11
|
'#{chapter_number}'
|
12
|
+
else # chapter_number is false, i.e., it's a single page
|
13
|
+
false
|
12
14
|
end
|
15
|
+
fn = if chapter_number
|
16
|
+
"formatNumber: function (n) { return #{chapter_number} + '.' + n }"
|
17
|
+
else
|
18
|
+
""
|
19
|
+
end
|
20
|
+
|
13
21
|
<<-EOS
|
14
22
|
MathJax.Hub.Config({
|
15
23
|
"HTML-CSS": {
|
@@ -19,7 +27,7 @@ module Softcover
|
|
19
27
|
extensions: ["AMSmath.js", "AMSsymbols.js"],
|
20
28
|
equationNumbers: {
|
21
29
|
autoNumber: "AMS",
|
22
|
-
|
30
|
+
#{fn}
|
23
31
|
},
|
24
32
|
Macros: {
|
25
33
|
PolyTeX: "Poly{\\\\TeX}",
|
Binary file
|
Binary file
|