public
Description: The official book for the Ramaze web framework
Homepage: http://book.ramaze.net
Clone URL: git://github.com/manveru/ramaze-book.git
Click here to lend your support to: ramaze-book and make a donation at www.pledgie.com !
lian (author)
Mon Oct 05 15:13:25 -0700 2009
manveru (committer)
Tue Oct 06 06:08:28 -0700 2009
ramaze-book / Rakefile
100644 132 lines (105 sloc) 3.269 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require 'rake/clean'
require 'fileutils'
require 'open3'
 
task :default => 'build:asciidoc-xhtml'
 
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']
 
formats = %w[chunked htmlhelp manpage pdf text xhtml dvi ps tex]
 
CLOBBER.include('chapter/source/**/*.xmp', JTR_XML)
 
OPTS = [
  "--asciidoc-opts=--conf-file=custom.conf",
  "--asciidoc-opts=--verbose",
  "--doctype=book",
  '--copy',
  '--icons',
  '--verbose',
]
 
file JTR_XML => [JTR_TXT, *CHAPTER_FILES] do
  sh('asciidoc', '-v', '-b', 'docbook', '-d', 'book', '-f', 'custom.conf', JTR_TXT)
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
 
    file(jtr_dir){ mkdir(jtr_dir) }
  end
 
  # 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)
  end
 
  desc 'Build prettier HTML directly with asciidoc'
  task 'asciidoc-xhtml' => jtr_path
end
 
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
 
    invocation = (xmp_invocation + [source_file]).join(' ')
 
    puts "Converting #{source_file} to xmp => #{xmp_file}"
    puts invocation
    original_source = File.read(source_file).strip
    xmp_source = `#{invocation}`.strip
 
    fail("XMP failed for #{source_file}") if xmp_source == original_source
 
    File.open(xmp_file, 'w+'){|xmp| xmp.write(xmp_source) }
  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
  end
end
 
rule('.css' => ['.sass']) do |t|
  sh('sass',
     '--style', 'compressed', # nested, compact, compressed, expaned
     t.source,
     t.name)
end