From bcbdb7bf515763084ef7d07d529723bb99fca2d1 Mon Sep 17 00:00:00 2001 From: Marat Radchenko Date: Tue, 27 Apr 2021 10:31:45 +0300 Subject: [PATCH] resolve #363: reenable dependency on kindlegen gem This commit also drops support for Ruby < 2.4 This reverts commit 33e27eeb21fb62f1e82767f9957a0a03fa35c722. --- .github/workflows/ci.yml | 2 +- CHANGELOG.adoc | 2 ++ Gemfile | 1 + asciidoctor-epub3.gemspec | 2 +- lib/asciidoctor-epub3/converter.rb | 11 +++++++++-- spec/spec_helper.rb | 7 ++++++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a967f197..c9c9ab3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: needs: activate strategy: matrix: - ruby: [jruby, '2.3', '2.4', '2.5', '2.6', '2.7', '3.0'] + ruby: ['jruby', '2.4', '2.5', '2.6', '2.7', '3.0'] os: [ubuntu-latest, windows-latest] asciidoctor: [''] include: diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index d2e8d85c..8bc8dfda 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -11,6 +11,8 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * use CSS for image size scaling instead of `width` attribute. #382 * use pygments.rb 2.0.0 in CI * add support for `:back-cover-image:` document attribute (#396) +* reenable Kindlegen support (#363) +* drop support for Ruby older than 2.4 == 1.5.0.alpha.19 (2020-10-21) - @slonopotamus diff --git a/Gemfile b/Gemfile index 1d2d335c..8d1e6364 100644 --- a/Gemfile +++ b/Gemfile @@ -14,4 +14,5 @@ end group :optional do # epubcheck-ruby might be safe to be converted into runtime dependency, but could have issues when packaged into asciidoctorj-epub3 gem 'epubcheck-ruby', '~> 4.2.5.0' + gem 'kindlegen', '~> 3.1.0' end diff --git a/asciidoctor-epub3.gemspec b/asciidoctor-epub3.gemspec index d1d70ca1..e32ad46a 100644 --- a/asciidoctor-epub3.gemspec +++ b/asciidoctor-epub3.gemspec @@ -17,7 +17,7 @@ An extension for Asciidoctor that converts AsciiDoc documents to EPUB3 and KF8/M s.homepage = 'https://github.com/asciidoctor/asciidoctor-epub3' s.license = 'MIT' - s.required_ruby_version = '>= 2.3.0' + s.required_ruby_version = '>= 2.4.0' files = begin (result = Open3.popen3('git ls-files -z') {|_, out| out.read }.split %(\0)).empty? ? Dir['**/*'] : result diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index 4ab339bd..03b955bf 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -1658,8 +1658,15 @@ def get_kindlegen_command return [result] end - logger.debug 'Using KindleGen from PATH' - [%(kindlegen#{::Gem.win_platform? ? '.exe' : ''})] + begin + require 'kindlegen' unless defined? ::Kindlegen + result = ::Kindlegen.command.to_s + logger.debug %(Using KindleGen from gem: #{result}) + [result] + rescue LoadError => e + logger.debug %(#{e}; Using KindleGen from PATH) + [%(kindlegen#{::Gem.win_platform? ? '.exe' : ''})] + end end def distill_epub_to_mobi epub_file, target, compress diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0caa5583..8cc113c5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -69,8 +69,13 @@ def skip_unless_has_logger skip 'Logger is unavailable on Asciidoctor < 1.5.7' unless has_logger? end + def darwin_platform? + RbConfig::CONFIG['host_os'] =~ /darwin/ + end + def skip_unless_has_kindlegen - skip 'KindleGen is gone: https://github.com/asciidoctor/asciidoctor-epub3/issues/363' + # TODO: https://github.com/asciidoctor/asciidoctor-epub3/issues/236 + skip '#236: Kindlegen is unavailable for 64-bit MacOS' if darwin_platform? end def convert input, opts = {}