diff --git a/Gemfile b/Gemfile index 88e504fd..d3ce6614 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 80b0c2f6..b5359fe9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 diff --git a/Rakefile b/Rakefile index af52edc6..48521853 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 }