asciidoctor-epub3 1.5.0.alpha.10 → 1.5.0.alpha.11

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
  SHA256:
3
- metadata.gz: db1c0f666f96e3a7506d02d7b2254b457f53357d8aec827e181260f34074cf4d
4
- data.tar.gz: 39f647ab1aaa940bb0f71c7666e04d38ac6b239bc5e1c263149146d5b8b6dd68
3
+ metadata.gz: e6cfcebc3d7d9ef77b095587955fd682f7cfb5b245d03a10f7e7c8737f8c7092
4
+ data.tar.gz: db9e5bc0d12af5937f1628bc8313036fca1e50c04e324384e42d11f22922a021
5
5
  SHA512:
6
- metadata.gz: 84708935a105312bf101367e9261460f19e827c3c5a5ea7ecfad8cad1dbd60554bc6e0772dfa6bef29ed9d40fc17ceafd718a32dab7d7b3e44a89f8cbccb4597
7
- data.tar.gz: fe86150318b86702dda3a94da387f3f860e87b298629e85e9b953d17fd6ee969e6b48644b20d722e3fabe0af275e7e4460ed343d1d5e1628821e951f07c9ed11
6
+ metadata.gz: 5ec6e59577eab71f02cefa75d97a48e00516ec7d3aba4ff31122ba31d699de3b779995d2efa44a8016cf1a2f7003e66bad137dd424781fde1a1af1dc6a06621a
7
+ data.tar.gz: 9e409822739509a541afa965466d8574c1de853b3e057db4d810a134093129ac0e261e998f56540c1b8cdfcb1333a0c369fd1a7d3f70a7728552f94cd1f6f0cf
data/.yardopts CHANGED
@@ -4,7 +4,7 @@
4
4
  --hide-api private
5
5
  --title "Asciidoctor EPUB3 API Docs"
6
6
  --output-dir apidoc
7
- --exclude /core_ext(?:\.rb$|/)
7
+ --exclude /ext(?:\.rb$|/)
8
8
  lib/**/*.rb
9
9
  -
10
10
  CHANGELOG.adoc
@@ -5,6 +5,24 @@
5
5
  This document provides a high-level view of the changes to the {project-name} by release.
6
6
  For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
7
7
 
8
+ == 1.5.0.alpha.11 (2020-01-26) - @slonopotamus
9
+
10
+ * drop unused dependencies: thread_safe, concurrent-ruby (#234)
11
+ * add support for Unicode characters in chapter IDs (#217)
12
+ * fix sample-book to be a valid book (#196)
13
+ * don't insert quotation marks around quotes (#129)
14
+ * require at least Asciidoctor 1.5.3 (#245)
15
+ * remove Namo Reader font-icon quirk that produced invalid markup (#192)
16
+ * fix the (in)famous `undefined method `to_ios'` when given a document that doesn't follow asciidoctor-epub3 rules (#7)
17
+ * route messages through the logger (#176)
18
+ * update EPUBCheck to 4.2.2.0 (#240)
19
+ * handle invalid `revdate` gracefully (#14)
20
+ * do not post-process EPUBCHECK env var, but use it as-is (#258)
21
+ * disable Pygments on JRuby to prevent hanging (#253)
22
+ * fix ENOENT error when trying to run EPUBcheck on JRuby on Windows (#256)
23
+ * fix ENOENT error when running kindlegen on JRuby on Windows (#154)
24
+ * set up CI for JRuby on Windows (#254)
25
+
8
26
  == 1.5.0.alpha.10 (2020-01-20) - @slonopotamus
9
27
 
10
28
  * fix deep xrefs between chapters when using Asciidoctor 2 (#210)
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gemspec
8
8
  gem 'asciidoctor', ENV['ASCIIDOCTOR_VERSION'], require: false if ENV.key? 'ASCIIDOCTOR_VERSION'
9
9
 
10
10
  group :optional do
11
- gem 'epubcheck-ruby', '4.1.1.0'
11
+ gem 'epubcheck-ruby', '4.2.2.0'
12
12
  gem 'kindlegen', (Gem::Version.new RUBY_VERSION) < (Gem::Version.new '2.4.0') ? '3.0.3' : '3.0.5'
13
13
  gem 'pygments.rb', '1.2.1'
14
14
  end
@@ -1,3 +1,6 @@
1
+ [[LICENSE]]
2
+ = LICENSE
3
+
1
4
  .The MIT License
2
5
  ....
3
6
  Copyright (C) 2014-2019 OpenDevise Inc. and the Asciidoctor Project
@@ -1,3 +1,4 @@
1
+ [[NOTICE]]
1
2
  = Asciidoctor EPUB3
2
3
 
3
4
  Copyright (C) 2014-2016 OpenDevise Inc. and the Asciidoctor Project.
@@ -1,6 +1,6 @@
1
1
  = {project-name}: A _native_ EPUB3 converter for AsciiDoc
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
3
- v1.5.0.alpha.10, 2020-01-20
3
+ v1.5.0.alpha.11, 2020-01-26
4
4
  // Settings:
5
5
  :experimental:
6
6
  :idprefix:
@@ -251,7 +251,7 @@ However, for the time being, the include directive fills this role.
251
251
 
252
252
  == Prerequisites
253
253
 
254
- All that's needed to use {project-name} is Ruby 2.3 or newer and a few Ruby gems, which we'll explain how to install in the next section.
254
+ All that's needed to use {project-name} is Ruby 2.3 or newer and a few Ruby gems (including at least Asciidoctor 1.5.3), which we'll explain how to install in the next section.
255
255
 
256
256
  To check if you have Ruby available, use the `ruby` command to query the installed version:
257
257
 
@@ -36,8 +36,6 @@ An extension for Asciidoctor that converts AsciiDoc documents to EPUB3 and KF8/M
36
36
  s.add_development_dependency 'rubocop', '~> 0.78.0'
37
37
  s.add_development_dependency 'rubocop-rspec', '~> 1.37.0'
38
38
 
39
- s.add_runtime_dependency 'asciidoctor', '>= 1.5.0', '< 3.0.0'
40
- s.add_runtime_dependency 'concurrent-ruby', '~> 1.1.0'
39
+ s.add_runtime_dependency 'asciidoctor', '>= 1.5.3', '< 3.0.0'
41
40
  s.add_runtime_dependency 'gepub', '~> 1.0.0'
42
- s.add_runtime_dependency 'thread_safe', '~> 0.3.0'
43
41
  end
@@ -14,12 +14,7 @@ options = Asciidoctor::Cli::Options.new backend: 'epub3'
14
14
  unless ARGV != ['-v'] && (ARGV & ['-V', '--version']).empty?
15
15
  require_relative '../lib/asciidoctor-epub3/version'
16
16
  $stdout.write %(Asciidoctor EPUB3 #{Asciidoctor::Epub3::VERSION} using )
17
- # NOTE the print_version method was added in Asciidoctor 1.5.2
18
- if options.respond_to? :print_version
19
- options.print_version
20
- else
21
- puts %(Asciidoctor #{::Asciidoctor::VERSION} [http://asciidoctor.org])
22
- end
17
+ options.print_version
23
18
  exit 0
24
19
  end
25
20
 
@@ -858,12 +858,6 @@ blockquote > p {
858
858
  line-height: 1.75;
859
859
  }
860
860
 
861
- /* hide explicit open quote for CSS3-enabled clients */
862
- blockquote span.open-quote:not(:empty) {
863
- display: none;
864
- }
865
-
866
- /* NOTE if we mapped the font icon to "\201c", we could just style the .open-quote */
867
861
  blockquote > p:first-of-type::before {
868
862
  display: inline-block;
869
863
  color: #666665;
@@ -3,5 +3,9 @@
3
3
  require 'asciidoctor'
4
4
  require 'asciidoctor/extensions'
5
5
  require 'gepub'
6
+ require_relative 'asciidoctor-epub3/ext'
6
7
  require_relative 'asciidoctor-epub3/converter'
7
8
  require_relative 'asciidoctor-epub3/packager'
9
+
10
+ # We need to be able to write files with unicode names. See https://github.com/asciidoctor/asciidoctor-epub3/issues/217
11
+ ::Zip.unicode_names = true
@@ -9,6 +9,7 @@ module Asciidoctor
9
9
  # EPUB3 or KF8 publication file.
10
10
  class Converter
11
11
  include ::Asciidoctor::Converter
12
+ include ::Asciidoctor::Logging
12
13
  include ::Asciidoctor::Writer
13
14
 
14
15
  register_for 'epub3'
@@ -27,7 +28,12 @@ module Asciidoctor
27
28
  @validate = node.attr? 'ebook-validate'
28
29
  @extract = node.attr? 'ebook-extract'
29
30
  @compress = node.attr 'ebook-compress'
30
- Packager.new node, (node.references[:spine_items] || [node]), node.attributes['ebook-format'].to_sym
31
+ spine_items = node.references[:spine_items]
32
+ if spine_items.nil?
33
+ logger.error %(#{::File.basename node.document.attr('docfile')}: failed to find spine items, produced file will be invalid)
34
+ spine_items = []
35
+ end
36
+ Packager.new node, spine_items, node.attributes['ebook-format'].to_sym
31
37
  # converting an element from the spine document, such as an inline node in the doctitle
32
38
  elsif name.start_with? 'inline_'
33
39
  (@content_converter ||= ::Asciidoctor::Converter::Factory.default.create 'epub3-xhtml5').convert node, name
@@ -47,6 +53,7 @@ module Asciidoctor
47
53
  # content documents in an EPUB3 publication.
48
54
  class ContentConverter
49
55
  include ::Asciidoctor::Converter
56
+ include ::Asciidoctor::Logging
50
57
 
51
58
  register_for 'epub3-xhtml5'
52
59
 
@@ -76,9 +83,6 @@ module Asciidoctor
76
83
 
77
84
  ToHtmlSpecialCharsRx = /[#{ToHtmlSpecialCharsMap.keys.join}]/
78
85
 
79
- OpenParagraphTagRx = /^<p>/
80
- CloseParagraphTagRx = /<\/p>$/
81
-
82
86
  def initialize backend, opts
83
87
  super
84
88
  basebackend 'html'
@@ -92,7 +96,7 @@ module Asciidoctor
92
96
  if respond_to? name ||= node.node_name
93
97
  send name, node
94
98
  else
95
- warn %(asciidoctor: WARNING: conversion missing in epub3 backend for #{name})
99
+ logger.warn %(conversion missing in epub3 backend for #{name})
96
100
  end
97
101
  end
98
102
 
@@ -128,7 +132,7 @@ module Asciidoctor
128
132
  # NOTE must run after content is resolved
129
133
  # TODO perhaps create dynamic CSS file?
130
134
  if @icon_names.empty?
131
- icon_css_head = icon_css_scoped = ''
135
+ icon_css_head = ''
132
136
  else
133
137
  icon_defs = @icon_names.map {|name|
134
138
  %(.i-#{name}::before { content: "#{FontIconMap[name.tr('-', '_').to_sym]}"; })
@@ -136,11 +140,6 @@ module Asciidoctor
136
140
  icon_css_head = %(<style>
137
141
  #{icon_defs}
138
142
  </style>
139
- )
140
- # NOTE Namo Pubtree requires icon CSS to be repeated inside <body> (or in a linked stylesheet); wrap in div to hide from Aldiko
141
- icon_css_scoped = (node.attr? 'ebook-format', 'kf8') ? '' : %(<div style="display: none" aria-hidden="true"><style scoped="scoped">
142
- #{icon_defs}
143
- </style></div>
144
143
  )
145
144
  end
146
145
 
@@ -164,7 +163,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
164
163
  </head>
165
164
  <body>
166
165
  <section class="chapter" title="#{doctitle_sanitized.gsub '"', '&quot;'}" epub:type="chapter" id="#{docid}">
167
- #{icon_css_scoped}<header>
166
+ <header>
168
167
  <div class="chapter-header">
169
168
  #{byline}<h1 class="chapter-title">#{title}#{subtitle ? %(<small class="subtitle">#{subtitle_formatted}</small>) : ''}</h1>
170
169
  </div>
@@ -357,7 +356,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
357
356
 
358
357
  footer_tag = footer_content.empty? ? '' : %(
359
358
  <footer>~ #{footer_content * ' '}</footer>)
360
- content = ((convert_content node).strip.sub OpenParagraphTagRx, '<p><span class="open-quote">“</span>').sub CloseParagraphTagRx, '<span class="close-quote">”</span></p>'
359
+ content = (convert_content node).strip
361
360
  %(<div#{id_attr}#{class_attr}>
362
361
  <blockquote>
363
362
  #{content}#{footer_tag}
@@ -687,10 +686,10 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
687
686
  elsif (xreftext = refdoc.references[:ids][refdoc_refid])
688
687
  text ||= xreftext
689
688
  else
690
- warn %(asciidoctor: WARNING: #{::File.basename doc.attr('docfile')}: invalid reference to unknown anchor in #{refdoc_id} chapter: #{refdoc_refid})
689
+ logger.warn %(#{::File.basename doc.attr('docfile')}: invalid reference to unknown anchor in #{refdoc_id} chapter: #{refdoc_refid})
691
690
  end
692
691
  else
693
- warn %(asciidoctor: WARNING: #{::File.basename doc.attr('docfile')}: invalid reference to anchor in unknown chapter: #{refdoc_id})
692
+ logger.warn %(#{::File.basename doc.attr('docfile')}: invalid reference to anchor in unknown chapter: #{refdoc_id})
694
693
  end
695
694
  else
696
695
  id_attr = (@xrefs_seen.add? refid) ? %( id="xref-#{refid}") : ''
@@ -706,7 +705,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
706
705
  text ||= xreftext
707
706
  else
708
707
  # FIXME: we get false negatives for reference to bibref when using Asciidoctor < 1.5.6
709
- warn %(asciidoctor: WARNING: #{::File.basename doc.attr('docfile')}: invalid reference to unknown local anchor (or valid bibref): #{refid})
708
+ logger.warn %(#{::File.basename doc.attr('docfile')}: invalid reference to unknown local anchor (or valid bibref): #{refid})
710
709
  end
711
710
  end
712
711
  %(<a#{id_attr} href="#{target}" class="xref">#{text || "[#{refid}]"}</a>)
@@ -904,7 +903,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
904
903
  end
905
904
  id = %(#{pre}document#{sep}#{doc.object_id}) if synthetic
906
905
  end
907
- warn %(asciidoctor: ERROR: chapter uses a reserved ID: #{id}) if !synthetic && (ReservedIds.include? id)
906
+ logger.error %(chapter uses a reserved ID: #{id}) if !synthetic && (ReservedIds.include? id)
908
907
  id
909
908
  end
910
909
  end
@@ -916,7 +915,7 @@ document.addEventListener('DOMContentLoaded', function(event, reader) {
916
915
  if (document = @document).backend == 'epub3'
917
916
  document.attributes['spine'] = ''
918
917
  document.set_attribute 'listing-caption', 'Listing'
919
- if !(defined? ::AsciidoctorJ) && (::Gem.try_activate 'pygments.rb')
918
+ if !(defined? ::JRuby) && (::Gem.try_activate 'pygments.rb')
920
919
  if document.set_attribute 'source-highlighter', 'pygments'
921
920
  document.set_attribute 'pygments-css', 'style'
922
921
  document.set_attribute 'pygments-style', 'bw'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ext/asciidoctor'
4
+ require_relative 'ext/core'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'asciidoctor/logging_shim' unless defined? Asciidoctor::Logging
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asciidoctor
4
+ module Logging
5
+ class StubLogger
6
+ class << self
7
+ def debug message = nil
8
+ puts %(asciidoctor: DEBUG: #{message || (block_given? ? yield : '???')}) if $VERBOSE
9
+ end
10
+
11
+ def info message = nil
12
+ puts %(asciidoctor: INFO: #{message || (block_given? ? yield : '???')}) if $VERBOSE
13
+ end
14
+
15
+ def warn message = nil
16
+ ::Kernel.warn %(asciidoctor: WARNING: #{message || (block_given? ? yield : '???')})
17
+ end
18
+
19
+ def error message = nil
20
+ ::Kernel.warn %(asciidoctor: ERROR: #{message || (block_given? ? yield : '???')})
21
+ end
22
+
23
+ def fatal message = nil
24
+ ::Kernel.warn %(asciidoctor: FATAL: #{message || (block_given? ? yield : '???')})
25
+ end
26
+ end
27
+ end
28
+
29
+ def logger
30
+ StubLogger
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'core/string'
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'core_ext/string'
4
3
  autoload :FileUtils, 'fileutils'
5
4
  autoload :Open3, 'open3'
6
- autoload :Shellwords, 'shellwords'
7
5
 
8
6
  module Asciidoctor
9
7
  module Epub3
10
8
  module GepubBuilderMixin
9
+ include ::Asciidoctor::Logging
11
10
  DATA_DIR = ::File.expand_path ::File.join(::File.dirname(__FILE__), '..', '..', 'data')
12
11
  SAMPLES_DIR = ::File.join DATA_DIR, 'samples'
13
12
  LF = ?\n
@@ -126,7 +125,7 @@ module Asciidoctor
126
125
  if (image_path = doc.attr 'front-cover-image')
127
126
  image_attrs = {}
128
127
  if (image_path.include? ':') && image_path =~ ImageMacroRx
129
- warn %(asciidoctor: WARNING: deprecated block macro syntax detected in front-cover-image attribute) if image_path.start_with? 'image::'
128
+ logger.warn %(deprecated block macro syntax detected in front-cover-image attribute) if image_path.start_with? 'image::'
130
129
  image_path = %(#{imagesdir}#{$1})
131
130
  (::Asciidoctor::AttributeList.new $2).parse_into image_attrs, %w(alt width height) unless $2.empty?
132
131
  end
@@ -136,7 +135,7 @@ module Asciidoctor
136
135
  width, height = 1050, 1600
137
136
  end
138
137
  else
139
- warn %(asciidoctor: ERROR: #{::File.basename doc.attr('docfile')}: front cover image not found or readable: #{::File.expand_path image_path, workdir})
138
+ logger.error %(#{::File.basename doc.attr('docfile')}: front cover image not found or readable: #{::File.expand_path image_path, workdir})
140
139
  image_path = nil
141
140
  end
142
141
  end
@@ -223,15 +222,16 @@ body > svg {
223
222
  docimagesdir = (doc.attr 'imagesdir', '.').chomp '/'
224
223
  docimagesdir = (docimagesdir == '.' ? nil : %(#{docimagesdir}/))
225
224
 
225
+ self_logger = logger
226
226
  workdir = (workdir = doc.attr 'docdir').nil_or_empty? ? '.' : workdir
227
227
  resources workdir: workdir do
228
228
  images.each do |image|
229
229
  if (image_path = image[:path]).start_with? %(#{docimagesdir}jacket/cover.)
230
- warn %(asciidoctor: WARNING: image path is reserved for cover artwork: #{image_path}; skipping image found in content)
230
+ self_logger.warn %(image path is reserved for cover artwork: #{image_path}; skipping image found in content)
231
231
  elsif ::File.readable? image_path
232
232
  file image_path
233
233
  else
234
- warn %(asciidoctor: ERROR: #{::File.basename image[:docfile]}: image not found or not readable: #{::File.expand_path image_path, workdir})
234
+ self_logger.error %(#{::File.basename image[:docfile]}: image not found or not readable: #{::File.expand_path image_path, workdir})
235
235
  end
236
236
  end
237
237
  end
@@ -247,6 +247,7 @@ body > svg {
247
247
  file %(#{imagesdir}headshots/default.jpg) => ::File.join(DATA_DIR, 'images/default-headshot.jpg')
248
248
  end
249
249
 
250
+ self_logger = logger
250
251
  workdir = (workdir = doc.attr 'docdir').nil_or_empty? ? '.' : workdir
251
252
  resources do
252
253
  usernames.each do |username|
@@ -254,7 +255,7 @@ body > svg {
254
255
  if ::File.readable? (resolved_avatar = (::File.join workdir, avatar))
255
256
  file avatar => resolved_avatar
256
257
  else
257
- warn %(asciidoctor: ERROR: avatar for #{username} not found or readable: #{avatar}; falling back to default avatar)
258
+ self_logger.error %(avatar for #{username} not found or readable: #{avatar}; falling back to default avatar)
258
259
  file avatar => ::File.join(DATA_DIR, 'images/default-avatar.jpg')
259
260
  end
260
261
 
@@ -262,7 +263,7 @@ body > svg {
262
263
  if ::File.readable? (resolved_headshot = (::File.join workdir, headshot))
263
264
  file headshot => resolved_headshot
264
265
  elsif doc.attr? 'builder', 'editions'
265
- warn %(asciidoctor: ERROR: headshot for #{username} not found or readable: #{headshot}; falling back to default headshot)
266
+ self_logger.error %(headshot for #{username} not found or readable: #{headshot}; falling back to default headshot)
266
267
  file headshot => ::File.join(DATA_DIR, 'images/default-headshot.jpg')
267
268
  end
268
269
  end
@@ -475,8 +476,8 @@ body > svg {
475
476
  end
476
477
 
477
478
  class Packager
478
- KINDLEGEN = ENV['KINDLEGEN'] || 'kindlegen'
479
- EPUBCHECK = ENV['EPUBCHECK'] || %(epubcheck#{::Gem.win_platform? ? '.bat' : '.sh'})
479
+ include ::Asciidoctor::Logging
480
+
480
481
  EpubExtensionRx = /\.epub$/i
481
482
  KindlegenCompression = ::Hash['0', '-c0', '1', '-c1', '2', '-c2', 'none', '-c0', 'standard', '-c1', 'huffdic', '-c2']
482
483
 
@@ -552,10 +553,14 @@ body > svg {
552
553
  contributors(*authors)
553
554
 
554
555
  if doc.attr? 'revdate'
555
- # TODO: ensure this is a real date
556
- date doc.attr('revdate')
556
+ begin
557
+ date doc.attr('revdate')
558
+ rescue ArgumentError => e
559
+ logger.error %(#{::File.basename doc.attr('docfile')}: failed to parse revdate: #{e}, using current time as a fallback)
560
+ date ::Time.now
561
+ end
557
562
  else
558
- date ::Time.now.strftime('%Y-%m-%dT%H:%M:%SZ')
563
+ date ::Time.now
559
564
  end
560
565
 
561
566
  description doc.attr('description') if doc.attr? 'description'
@@ -583,7 +588,7 @@ body > svg {
583
588
 
584
589
  epub_file = fmt == :kf8 ? %(#{::Asciidoctor::Helpers.rootname target}-kf8.epub) : target
585
590
  builder.generate_epub epub_file
586
- puts %(Wrote #{fmt.upcase} to #{epub_file}) if $VERBOSE
591
+ logger.debug %(Wrote #{fmt.upcase} to #{epub_file})
587
592
  if options[:extract]
588
593
  extract_dir = epub_file.sub EpubExtensionRx, ''
589
594
  ::FileUtils.remove_dir extract_dir if ::File.directory? extract_dir
@@ -599,7 +604,7 @@ body > svg {
599
604
  end
600
605
  end
601
606
  end
602
- puts %(Extracted #{fmt.upcase} to #{extract_dir}) if $VERBOSE
607
+ logger.debug %(Extracted #{fmt.upcase} to #{extract_dir})
603
608
  end
604
609
 
605
610
  if fmt == :kf8
@@ -611,36 +616,67 @@ body > svg {
611
616
  end
612
617
 
613
618
  def distill_epub_to_mobi epub_file, target, compress
614
- kindlegen_cmd = KINDLEGEN
615
- unless ::File.executable? kindlegen_cmd
619
+ if !(kindlegen_cmd = ENV['kindlegen']).nil?
620
+ argv = [kindlegen_cmd]
621
+ else
616
622
  require 'kindlegen' unless defined? ::Kindlegen
617
- kindlegen_cmd = ::Kindlegen.command
623
+ argv = [::Kindlegen.command.to_s]
618
624
  end
619
625
  mobi_file = ::File.basename target.sub(EpubExtensionRx, '.mobi')
620
626
  compress_flag = KindlegenCompression[compress ? (compress.empty? ? '1' : compress.to_s) : '0']
621
- cmd = [kindlegen_cmd, '-dont_append_source', compress_flag, '-o', mobi_file, epub_file].compact
622
- ::Open3.popen2e ::Shellwords.join(cmd) do |_input, output, _wait_thr|
623
- output.each {|line| puts line } unless $VERBOSE.nil?
627
+ argv += ['-dont_append_source', compress_flag, '-o', mobi_file, epub_file].compact
628
+
629
+ # This duplicates Kindlegen.run, but we want to override executable
630
+ out, err, res = Open3.capture3(*argv) do |r|
631
+ r.force_encoding 'UTF-8' if windows? && r.respond_to?(:force_encoding)
632
+ end
633
+
634
+ out.each_line do |line|
635
+ logger.info line
636
+ end
637
+ err.each_line do |line|
638
+ log_line line
639
+ end
640
+
641
+ output_file = ::File.join ::File.dirname(epub_file), mobi_file
642
+ if res.success?
643
+ logger.debug %(Wrote MOBI to #{output_file})
644
+ else
645
+ logger.error %(kindlegen failed to write MOBI to #{output_file})
624
646
  end
625
- puts %(Wrote MOBI to #{::File.join ::File.dirname(epub_file), mobi_file}) if $VERBOSE
626
647
  end
627
648
 
628
649
  def validate_epub epub_file
629
- if ::File.executable? EPUBCHECK
630
- argv = [EPUBCHECK]
650
+ if !(epubcheck = ENV['EPUBCHECK']).nil?
651
+ argv = [epubcheck]
631
652
  else
632
653
  argv = [::Gem.ruby, ::Gem.bin_path('epubcheck-ruby', 'epubcheck')]
633
654
  end
634
655
 
635
- if $VERBOSE.nil?
636
- argv << '-q'
637
- else
638
- argv << '-w'
656
+ argv += ['-w', epub_file]
657
+ out, err, res = Open3.capture3(*argv)
658
+
659
+ out.each_line do |line|
660
+ logger.info line
661
+ end
662
+ err.each_line do |line|
663
+ log_line line
639
664
  end
640
- argv << epub_file
641
665
 
642
- ::Open3.popen2e ::Shellwords.join(argv) do |_input, output, _wait_thr|
643
- output.each {|line| puts line }
666
+ logger.error %(EPUB validation failed: #{epub_file}) unless res.success?
667
+ end
668
+
669
+ def log_line line
670
+ line = line.strip
671
+
672
+ if line =~ /^fatal/i
673
+ logger.fatal line
674
+ elsif line =~ /^error/i
675
+ logger.error line
676
+ elsif line =~ /^warning/i
677
+ logger.warn line
678
+ else
679
+ logger.info line
644
680
  end
645
681
  end
646
682
  end
@@ -3,6 +3,8 @@
3
3
  module Asciidoctor
4
4
  module Epub3
5
5
  class SpineItemProcessor < Extensions::IncludeProcessor
6
+ include ::Asciidoctor::Logging
7
+
6
8
  def initialize document
7
9
  @document = document
8
10
  end
@@ -12,7 +14,7 @@ module Asciidoctor
12
14
  spine_doc = doc
13
15
  # TODO: allow URI value
14
16
  unless ::File.file? (include_file = (spine_doc.normalize_system_path target, reader.dir, nil, target_name: 'include file'))
15
- warn %(asciidoctor: WARNING: #{reader.line_info}: include file not found: #{include_file})
17
+ logger.warn %(#{reader.line_info}: include file not found: #{include_file})
16
18
  return
17
19
  end
18
20
  inherited_attrs = spine_doc.attributes.dup
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Asciidoctor
4
4
  module Epub3
5
- VERSION = '1.5.0.alpha.10'
5
+ VERSION = '1.5.0.alpha.11'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-epub3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.alpha.10
4
+ version: 1.5.0.alpha.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-20 00:00:00.000000000 Z
12
+ date: 2020-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -73,7 +73,7 @@ dependencies:
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 1.5.0
76
+ version: 1.5.3
77
77
  - - "<"
78
78
  - !ruby/object:Gem::Version
79
79
  version: 3.0.0
@@ -83,24 +83,10 @@ dependencies:
83
83
  requirements:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: 1.5.0
86
+ version: 1.5.3
87
87
  - - "<"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.0.0
90
- - !ruby/object:Gem::Dependency
91
- name: concurrent-ruby
92
- requirement: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 1.1.0
97
- type: :runtime
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.1.0
104
90
  - !ruby/object:Gem::Dependency
105
91
  name: gepub
106
92
  requirement: !ruby/object:Gem::Requirement
@@ -115,20 +101,6 @@ dependencies:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
103
  version: 1.0.0
118
- - !ruby/object:Gem::Dependency
119
- name: thread_safe
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 0.3.0
125
- type: :runtime
126
- prerelease: false
127
- version_requirements: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.3.0
132
104
  description: 'An extension for Asciidoctor that converts AsciiDoc documents to EPUB3
133
105
  and KF8/MOBI (Kindle) e-book archives.
134
106
 
@@ -198,7 +170,11 @@ files:
198
170
  - data/styles/epub3.css
199
171
  - lib/asciidoctor-epub3.rb
200
172
  - lib/asciidoctor-epub3/converter.rb
201
- - lib/asciidoctor-epub3/core_ext/string.rb
173
+ - lib/asciidoctor-epub3/ext.rb
174
+ - lib/asciidoctor-epub3/ext/asciidoctor.rb
175
+ - lib/asciidoctor-epub3/ext/asciidoctor/logging_shim.rb
176
+ - lib/asciidoctor-epub3/ext/core.rb
177
+ - lib/asciidoctor-epub3/ext/core/string.rb
202
178
  - lib/asciidoctor-epub3/font_icon_map.rb
203
179
  - lib/asciidoctor-epub3/packager.rb
204
180
  - lib/asciidoctor-epub3/spine_item_processor.rb