-
-
Save lodestone/00c6d8a74cb15d7453778555f6a89597 to your computer and use it in GitHub Desktop.
Rake build tasks that use Asciidoctor APIs to produce common output formats for a book (or other type of publication) written in AsciiDoc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
To use this build script, first install the bundler gem: | |
$ gem install bundler | |
Then use the `bundle` command to install the dependencies into the project: | |
$ rm -rf Gemfile.lock .bundle | |
bundle config --local git.allow_insecure true | |
bundle config --local build.nokogiri --use-system-libraries | |
bundle --path=.bundle/gems | |
NOTE The gems are installed under the path .bundle/gems in the project. | |
Finally, run a named task using the `bundle exec rake` command: | |
$ bundle exec rake pdf | |
You can get a list of tasks using the following command: | |
$ bundle exec rake -T | |
=end | |
MASTER_FILENAME='book.adoc' | |
BUILD_DIR='build' | |
autoload :FileUtils, 'fileutils' | |
desc 'Build the HTML5 format' | |
task :html do | |
require 'asciidoctor' | |
Asciidoctor.convert_file MASTER_FILENAME, | |
safe: :unsafe, | |
# FIXME task should copy images instead of embedding them | |
attributes: 'data-uri', | |
to_dir: BUILD_DIR, | |
mkdirs: true | |
end | |
desc 'Build the PDF format' | |
task :pdf do | |
require 'asciidoctor-pdf' | |
Asciidoctor.convert_file MASTER_FILENAME, | |
safe: :unsafe, | |
backend: 'pdf', | |
to_dir: BUILD_DIR, | |
mkdirs: true | |
end | |
# TIP invoke using epub[ebook-validate] to validate | |
desc 'Build the EPUB3 format' | |
task :epub, [:attrs] do |_, args| | |
require 'asciidoctor-epub3' | |
Asciidoctor.convert_file MASTER_FILENAME, | |
safe: :unsafe, | |
backend: 'epub3', | |
attributes: [args[:attrs]].compact * ' ', | |
to_dir: BUILD_DIR, | |
mkdirs: true | |
end | |
desc 'Build the MOBI format' | |
task :mobi do | |
require 'asciidoctor-epub3' | |
Asciidoctor.convert_file MASTER_FILENAME, | |
safe: :unsafe, | |
backend: 'epub3', | |
attributes: 'ebook-format=kf8', | |
to_dir: BUILD_DIR, | |
mkdirs: true | |
# NOTE remove the temporary -kf8.epub file so we don't get confused | |
File.unlink %(#{BUILD_DIR}/#{File.basename MASTER_FILENAME, '.*'}-kf8.epub) | |
end | |
task kf8: :mobi | |
desc 'Build the EPUB3 and MOBI formats' | |
task ebook: [:epub, :mobi] | |
desc 'Build all formats' | |
task default: [:html, :ebook, :pdf] | |
desc 'Clean the build directory' | |
task :clean do | |
FileUtils.remove_entry_secure BUILD_DIR | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'rake', '12.0.0' | |
gem 'asciidoctor-pdf', '1.5.0.alpha.15' | |
# NOTE switch to asciidoctor-epub3 1.5.0.alpha.7 once released | |
gem 'asciidoctor-epub3', github: 'asciidoctor/asciidoctor-epub3' | |
# NOTE refer to https://github.com/packetmonkey/prawn-gmagick#amazon-ec2--elastic-beanstalk-installation for prerequisites | |
gem 'prawn-gmagick', '0.0.8' | |
gem 'pygments.rb', '1.1.1' | |
gem 'kindlegen', '3.0.3' | |
gem 'epubcheck', '3.0.1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment