Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blueform chapters, tutorial and reference. #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
211 changes: 102 additions & 109 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,131 +1,124 @@
require 'rake/clean'
require 'fileutils'
require 'open3'
#! /usr/bin/ruby # <-- this causes the editor to color the syntax
#
# Journey to Ramaze is the official Ramaze documentation and is written in
# O'Reilly Media, Inc. style AsciiDoc format. This Rakefile builds the final
# document formats from the AsciiDoc inputs (texts, images, and icons).
#
# authors: Michael J. Welch, Ph.D. <[email protected]>
# & Michael Fellinger <[email protected]>
#
# This Rakefile requires the following packages be installed:
# asciidoc, sass, and calibre
#
# This Rakefile requires the following Gems to be installed:
# ramaze, innate, rack, rake, rcodetools

task :default => 'build:asciidoc-xhtml'
require 'rake/clean'

JTR_TXT = "journey_to_ramaze.txt"
JTR_XML = "journey_to_ramaze.xml"
CHAPTER_FILES = Dir['chapter/*.txt']
SOURCE_FILES = FileList['chapter/source/**/*.rb']
XMP_FILES = FileList['chapter/source/**/*.xmp']
task :default => 'build:html'

formats = %w[chunked htmlhelp manpage pdf text xhtml dvi ps tex]
RUBY = ENV['RUBY']
clean = clobber = []

CLOBBER.include('chapter/source/**/*.xmp', JTR_XML)
ASCIIDOCS = ['stylesheets/asciidoc.css', 'javascripts/asciidoc.js']
clean += ASCIIDOCS

OPTS = [
"--asciidoc-opts=--conf-file=custom.conf",
"--asciidoc-opts=--verbose",
"--doctype=book",
'--copy',
'--icons',
'--verbose',
]
ASCDOC_CSS = 'stylesheets/asciidoc.css'
file ASCDOC_CSS do
sh("cp", "/etc/asciidoc/stylesheets/asciidoc.css", "stylesheets/asciidoc.css")
end

file JTR_XML => [JTR_TXT, *CHAPTER_FILES] do
sh('asciidoc', '-v', '-b', 'docbook', '-d', 'book', '-f', 'custom.conf', JTR_TXT)
ASCDOC_JS = 'javascripts/asciidoc.js'
file ASCDOC_JS do
sh("cp", "/etc/asciidoc/javascripts/asciidoc.js", "javascripts/asciidoc.js")
end

namespace :build do
# the formats going over docbook format
formats.each do |format|
jtr_dir = "#{format}/"
jtr_base = "journey_to_ramaze.#{format}"
jtr_path = File.join(jtr_dir, jtr_base)
CLOBBER.include(jtr_dir)

desc "Build #{jtr_path}"
task format => jtr_path

file jtr_path => [jtr_dir, JTR_XML] do
opts = OPTS + [
"--destination-dir=#{jtr_dir}",
"--format=#{format}",
"-s",
JTR_XML,
]

sh("a2x", *opts)

case format
when 'pdf' # doesn't heed --destination-dir
FileUtils.mv(jtr_base, jtr_path)
end
end
rule('.xmp' => ['.rb']) do |t|
xmp_invocation = "xmpfilter --annotations -r ramaze #{t.source}"
puts xmp_invocation
original_source = File.read(t.source).strip
xmp_source = `#{xmp_invocation}`.strip
fail("XMP failed for #{t.source}") if xmp_source == original_source
File.open(t.name, 'w'){|xmp| xmp.write(xmp_source) }
end

file(jtr_dir){ mkdir(jtr_dir) }
end
CHAPTER_FILES = Dir['chapter/*.txt']

# the asciidoc-xhtml

jtr_scripts = File.expand_path('javascripts')
jtr_styles = File.expand_path('stylesheets')
jtr_css = 'stylesheets/xhtml11.css'
jtr_dir = 'asciidoc-xhtml/'
jtr_base = 'journey_to_ramaze.html'
jtr_path = File.join(jtr_dir, jtr_base)

jtr_depends = [jtr_dir, JTR_TXT, jtr_css] + CHAPTER_FILES + XMP_FILES

CLOBBER.include(jtr_dir, File.join(jtr_styles, '**/*.css'))

file(jtr_dir){ mkdir(jtr_dir) }
file jtr_path => jtr_depends do
sh('asciidoc',
'--attribute', "scriptsdir=#{jtr_scripts}",
'--attribute', "stylesdir=#{jtr_styles}",
'--attribute', 'toc',
'--backend', 'xhtml11',
'--doctype', 'book',
'--out-file', jtr_path,
'--section-numbers',
'--unsafe',
'--verbose',
JTR_TXT)
XMP_FILES = []
CHAPTER_FILES.each do |chapter_file|
File.open(chapter_file){|cf| cf.grep(/^include::.*\.xmp/) }.each do |line|
XMP_FILES << 'chapter/' + line[/^include::(.*\.xmp)/, 1]
end

desc 'Build prettier HTML directly with asciidoc'
task 'asciidoc-xhtml' => jtr_path
end
desc "Make Journey to Ramaze XMP files only (for testing)"
task :"xmp-only" => XMP_FILES

namespace :xmp do
xmp_invocation = [
RUBY,
'xmpfilter.rb',
'--annotations',
'-r', 'ramaze',
'--interpreter', RUBY
]

rule('.xmp' => ['.rb']) do |t|
source_file = t.source
xmp_file = t.name
rule '.css' => '.sass' do |t|
sh 'sass', '--style', 'compressed', t.source, t.name
end

invocation = (xmp_invocation + [source_file]).join(' ')
CSS_FILES = Dir['stylesheets/*.sass'].collect { |f| f.ext('css') }
clean += XMP_FILES + CSS_FILES

def a2x(format,source)
puts "call: a2x #{format} #{source}"
opts = ["a2x",
"--asciidoc-opts=--conf-file=custom.conf",
"--asciidoc-opts=--section-numbers",
"--asciidoc-opts=--verbose",
"--doctype=book",
"--format=#{format}",
"--icons",
"--no-xmllint",
"--verbose"]
opts << "--fop" if format=="pdf"
opts << source
sh(*opts)
end

puts "Converting #{source_file} to xmp => #{xmp_file}"
puts invocation
original_source = File.read(source_file).strip
xmp_source = `#{invocation}`.strip
JTR_TXT = "journey_to_ramaze.txt"
JTR_XML = "journey_to_ramaze.xml"
JTR_EPUB = 'journey_to_ramaze.epub'
JTR_MOBI = 'journey_to_ramaze.mobi'

fail("XMP failed for #{source_file}") if xmp_source == original_source
file JTR_XML => [ASCDOC_CSS, ASCDOC_JS, *XMP_FILES, *CSS_FILES, *CHAPTER_FILES, JTR_TXT] do
a2x("docbook",JTR_TXT)
end
clean += [JTR_XML, 'docbook-xsl.css']

File.open(xmp_file, 'w+'){|xmp| xmp.write(xmp_source) }
namespace :build do
formats = {
# name format temp file(s) output(s)
:chunked => [ "chunked", [], ["chunked"] ],
:epub => [ "epub", ["epub.d"], ["epub"] ],
:html => [ "xhtml", [], ["html"] ],
:htmlhelp => [ "htmlhelp", [], ["htmlhelp"] ],
:manpage => [ "manpage", [], ["hhc","hhp"] ],
:pdf => [ "pdf", ["fo"], ["pdf"] ],
:tex => [ "tex", [], ["tex"] ],
:text => [ "text", ["text.html"], ["text"] ]
}

formats.each do |key,values|
format, clean_list, clobber_list = values
target = "journey_to_ramaze.#{key}"
file target => JTR_XML do
a2x(format, JTR_XML)
end
desc "Make Journey to Ramaze in #{format} format"
task key.to_s => target
clean_list.each { |ext| clean << "journey_to_ramaze.#{ext}" }
clobber_list.each { |ext| clobber << "journey_to_ramaze.#{ext}" }
end

CHAPTER_FILES.each do |chapter_file|
File.open(chapter_file){|cf| cf.grep(/^include::.*\.xmp/) }.each do |line|
xmp = 'chapter/' + line[/^include::(.*\.xmp)/, 1]
rb = xmp.sub(/\.xmp$/, '.rb')
file(chapter_file => xmp)
end
file JTR_MOBI => JTR_EPUB do |t|
sh 'ebook-convert', t.source, t.name, '--mobi-keep-original-images',
'--mobi-file-type=new', '--base-font-size=12', '--smarten-punctuation'
end
end
desc "Make Journey to Ramaze in mobi format"
task :mobi => JTR_MOBI
clobber << JTR_MOBI

rule('.css' => ['.sass']) do |t|
sh('sass',
'--style', 'compressed', # nested, compact, compressed, expaned
t.source,
t.name)
CLEAN.include(Dir[*clean])
CLOBBER.include(Dir[*clobber])
end
2 changes: 1 addition & 1 deletion chapter/attributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:pickaxe: http://www.rubycentral.com/book/[Programming Ruby]

// chapters
:ch-developing: <<X400,developing Ramaze>>
//:ch-developing: <<X400,developing Ramaze>>

// API links
:request-api: http://doc.ramaze.net/classes/Ramaze/Request.html[API docs for Ramaze::Request]
Expand Down
Loading