From b6c117b42d41230b5abced70a76b4ff708a7cd77 Mon Sep 17 00:00:00 2001 From: kubosho Date: Mon, 21 Jul 2014 19:07:28 +0900 Subject: [PATCH] =?UTF-8?q?feat(pdf):=20PDF=E3=81=A7=E5=87=BA=E5=8A=9B?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 +++ Rakefile | 26 ++++++++++++++++++++++---- bin/build-pdf | 13 +++++++++++++ bin/fopub | 1 + 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .gitmodules create mode 100755 bin/build-pdf create mode 160000 bin/fopub diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..038e2a2a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bin/fopub"] + path = bin/fopub + url = https://github.com/asciidoctor/asciidoctor-fopub.git diff --git a/Rakefile b/Rakefile index 1b19358a..bb292927 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ SRC_FILE = 'index.adoc' OUTPUT_DIRECTORY = 'build/' -OUTPUT_FILE = 'index.html' +OUTPUT_HTML_FILE = 'index.html' +OUTPUT_XML_FILE = 'steins-git.xml' REPOSITORY = if ENV['GH_TOKEN'] 'https://$GH_TOKEN@github.com/o2project/steins-git' @@ -41,11 +42,18 @@ def directory_copy(src, dist) FileUtils.copy_entry src, dist end -def build_asciidoc(src, output) +def build_asciidoc_to_html(src, output) sh "bundle exec asciidoctor -a bookversion=`node ./bin/bookversion` \ -a icons=font -o #{output} #{src}" end +def build_asciidoc_to_pdf(src, output) + sh "bundle exec asciidoctor -a lang=en -a bookversion=`node ./bin/bookversion` \ + -a icons=font -b docbook \ + -o #{output} #{src}" + sh "./bin/build-pdf #{output}" +end + def push_to_target_branch(repo, branch) sha1, _ = `git log -n 1 --oneline`.strip.split(' ') @@ -68,8 +76,18 @@ namespace :generate do directory_copy 'Ch3_HowToGit/img', "#{OUTPUT_DIRECTORY}/Ch3_HowToGit/img" puts "Done!" puts 'Generate HTML...' - build_asciidoc SRC_FILE, "#{OUTPUT_DIRECTORY}#{OUTPUT_FILE}" - puts "Done! => #{OUTPUT_FILE}" + build_asciidoc_to_html SRC_FILE, "#{OUTPUT_DIRECTORY}#{OUTPUT_HTML_FILE}" + puts "Done! => #{OUTPUT_HTML_FILE}" + end + + task :pdf do + puts 'Each section img directory recursively copy to under build directory...' + directory_copy 'Ch1_WhatsGit/img', "#{OUTPUT_DIRECTORY}/Ch1_WhatsGit/img" + directory_copy 'Ch3_HowToGit/img', "#{OUTPUT_DIRECTORY}/Ch3_HowToGit/img" + puts "Done!" + puts 'Generate PDF...' + build_asciidoc_to_pdf SRC_FILE, "#{OUTPUT_DIRECTORY}#{OUTPUT_XML_FILE}" + puts "Done!" end end diff --git a/bin/build-pdf b/bin/build-pdf new file mode 100755 index 00000000..ad0fa558 --- /dev/null +++ b/bin/build-pdf @@ -0,0 +1,13 @@ +#!/bin/bash + +declare parentDir=$(cd $(dirname $(cd $(dirname $0);pwd));pwd) +declare currentDir=$(cd $(dirname $0);pwd) +SRC_FILE=${parentDir}/$1 + +${currentDir}/fopub/fopub "${SRC_FILE}" \ +-param body.font.family VL-Gothic-Regular \ +-param dingbat.font.family VL-Gothic-Regular \ +-param monospace.font.family VL-Gothic-Regular \ +-param sans.font.family VL-Gothic-Regular \ +-param title.font.family VL-Gothic-Regular \ +-param alignment left diff --git a/bin/fopub b/bin/fopub new file mode 160000 index 00000000..03e6f0b7 --- /dev/null +++ b/bin/fopub @@ -0,0 +1 @@ +Subproject commit 03e6f0b7ab7cf95bb55c410e81318460af65a068