Skip to content

Commit

Permalink
Update Rakefile
Browse files Browse the repository at this point in the history
The pdf can compile better with the addition from chloerei
  • Loading branch information
jnavila committed Feb 19, 2018
1 parent cb259e6 commit 238c689
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ gem 'awesome_print'

gem 'asciidoctor-epub3', :git => 'https://github.com/asciidoctor/asciidoctor-epub3'
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
gem 'asciidoctor-pdf-cjk', '~> 0.1.3'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'

gem 'coderay'
gem 'pygments.rb'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ GEM
safe_yaml (~> 1.0.4)
thread_safe (~> 0.3.6)
treetop (= 1.5.3)
asciidoctor-pdf-cjk (0.1.3)
asciidoctor-pdf (~> 1.5.0.alpha.8)
asciidoctor-pdf-cjk-kai_gen_gothic (0.1.1)
asciidoctor-pdf-cjk (~> 0.1.2)
awesome_print (1.8.0)
coderay (1.1.2)
css_parser (1.6.0)
Expand Down Expand Up @@ -90,6 +94,8 @@ DEPENDENCIES
asciidoctor (= 1.5.6.1)
asciidoctor-epub3!
asciidoctor-pdf (= 1.5.0.alpha.16)
asciidoctor-pdf-cjk (~> 0.1.3)
asciidoctor-pdf-cjk-kai_gen_gothic (~> 0.1.1)
awesome_print
coderay
epubcheck
Expand Down
29 changes: 21 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
# coding: utf-8
require 'octokit'

def exec_or_raise(command)
puts `#{command}`
if (! $?.success?)
raise "'#{command}' failed"
end
end

namespace :book do
desc 'build basic book formats'
task :build do

puts "Generating contributors list"
`git shortlog -s --all| grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt`
exec_or_raise("git shortlog -s --all| grep -v -E '(Straub|Chacon)' | cut -f 2- | column -c 120 > book/contributors.txt")

puts "Converting to HTML..."
`bundle exec asciidoctor progit.asc`
exec_or_raise("bundle exec asciidoctor progit.asc")
puts " -- HTML output at progit.html"

puts "Converting to EPub..."
`bundle exec asciidoctor-epub3 progit.asc`
exec_or_raise("bundle exec asciidoctor-epub3 progit.asc")
puts " -- Epub output at progit.epub"

sh "epubcheck progit.epub"
exec_or_raise("epubcheck progit.epub")

puts "Converting to Mobi (kf8)..."
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc")
puts " -- Mobi output at progit.mobi"

repo = ENV['TRAVIS_REPO_SLUG']
puts "Converting to PDF... (this one takes a while)"
`bundle exec asciidoctor-pdf progit.asc 2>/dev/null`
if (repo == "progit/progit2-zh")
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN progit.asc")
else
exec_or_raise("bundle exec asciidoctor-pdf progit.asc 2>/dev/null")
end
puts " -- PDF output at progit.pdf"
end

desc 'tag the repo with the latest version'
task :tag do
api_token = ENV['GITHUB_API_TOKEN']
if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master') && !ENV['TRAVIS_TAG'])
if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master'))
repo = ENV['TRAVIS_REPO_SLUG']
@octokit = Octokit::Client.new(:access_token => api_token)
begin
Expand Down Expand Up @@ -148,7 +161,7 @@ namespace :book do
content = File.read (filename)
new_contents = content.gsub(/include::(.*?)asc/) {|match|
"include::book/#{num}-#{title}/#{$1}asc"}
`git rm #{filename}`
`git rm -f #{filename}`
File.open("#{chap}.asc", "w") {|file|
file.puts "[##{chap}]\n"
file.puts new_contents }
Expand Down

0 comments on commit 238c689

Please sign in to comment.