-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrakefile
118 lines (92 loc) · 2.75 KB
/
rakefile
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
require 'rake/clean'
require './lib/roadmap'
require 'mustache'
## Default target - targets are "site", "book"
task :default => [:site]
## Filesets
SITE = "site/%n.html"
BOOK = "book/%n.html"
YML_SRC = FileList['src/*.yml']
SITE_INDICES = FileList['index_alpha.ham','index_type.ham'].pathmap("tmp/%p")
SITE_STATIC = FileList['static/site/*.ham']
SITE_OUT = (YML_SRC).pathmap(SITE)
BOOK_INDICES = FileList['book.ham'].pathmap("tmp/%p")
BOOK_STATIC = FileList['static/book/*.ham']
BOOK_OUT = (YML_SRC).pathmap("book/%n.html")
CLEAN.include('tmp/*')
## Helpers
def haml_indirect target, where, built
task target => built
from = built.pathmap("%{#{where},tmp}X_#{where}.ham")
haml built, from
end
def haml built, from
file built => from do
sh "haml -r ./lib/helpers.rb #{from} > #{built}" unless uptodate?(built,FileList[from])
end
end
def generate_indices which, how, view
outofdate = which.any? {|target| !uptodate?(target,(YML_SRC.add view))}
sh "ruby lib/#{how}.rb" if outofdate
end
def mustache built, from, template, fix
file built => from do
view = "views/#{template}.tmpl"
return if uptodate?(built,from) && uptodate?(built, FileList[view])
template = IO.read(view)
data = Roadmap.new("src").interpret(from)
expanded = Mustache.render template, data
File.open(built,"w") {|f| f.write(expanded)}
# Ugly hack to fix internal links for the eBook version - improve this
sh "perl -i.old -pe 's/]\\((.*?).html\\)/](\#$1)/g' #{built}" unless !fix
end
end
## Synthetic tasks
SITE_OUT.each do |built|
haml_indirect(:site,"site",built)
end
BOOK_OUT.each do |built|
rebuilt = haml_indirect(:book,"book",built)
end
SITE_STATIC.each do |from|
built = from.pathmap(SITE)
task :site => built
haml built, from
end
BOOK_STATIC.each do |from|
built = from.pathmap(BOOK)
task :book => built
haml built, from
end
SITE_INDICES.each do |from|
task from => :site_index
built = from.pathmap(SITE)
task :site => built
haml built, from
end
BOOK_INDICES.each do |from|
task from => :book_index
built = from.pathmap(BOOK)
task :book => built
haml built, from
end
YML_SRC.each do |from|
built = from.pathmap("%{src,tmp}X_book.ham")
mustache built, from, "practice-book", true
end
YML_SRC.each do |from|
built = from.pathmap("%{src,tmp}X_site.ham")
mustache built, from, "practice", false
end
## Final tasks
file "eBook.pdf" => :book do
sh "prince book/book.html -o eBook.pdf"
end
task :site => :site_index
task :book => :book_index
task :site_index => [] do |t|
generate_indices SITE_INDICES, "site", "views/index.tmpl"
end
task :book_index => [] do |t|
generate_indices BOOK_INDICES, "book", "views/book.tmpl"
end