This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRakefile
295 lines (250 loc) · 7.93 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
$LOAD_PATH.unshift 'lib'
require 'rake/clean'
require 'theme'
include FileTest
VERS = File.read('VERSION')
task 'default' => 'all'
task 'all' => [ 'stylesheets', 'site' ]
desc 'Build all examples and test files under site'
task 'site'
desc 'Build CSS for all themes'
task 'stylesheets'
desc 'Build distributable tarball under dist'
task 'dist'
# ---------------------------------------------------------------------------
# Theme CSS Generation
# ---------------------------------------------------------------------------
FileList['src/*.css'].each do |srcfile|
basename = File.basename(srcfile)
destfile = "stylesheets/#{basename}"
prereqs = (File.read(srcfile, 1024) || '').
split("\n").
grep(/@import/).
map { |line| line.match(/@import\s+url\((.*)\)\s*;/)[1] }.
map { |file| "stylesheets/#{file}" }
file destfile => [srcfile, *prereqs] do |f|
doing :css, f.name
src = File.read(srcfile)
src.gsub!(/@import\s+url\((.*)\)\s*;/) do |match|
[
"/* BEG #{match} */",
File.read("stylesheets/#{$1}"),
"/* END #{match} */"
].join("\n")
end
mkdir_p 'stylesheets'
File.open(destfile, 'wb') { |io| io.write(src) }
# set modified time to the oldest of all prerequisites
mtime = f.prerequisites.map { |fn| File.mtime(fn) }.max
File.utime(Time.now, mtime, destfile)
end
CLOBBER.include destfile
task 'stylesheets' => destfile
end
# ---------------------------------------------------------------------------
# Examples
# ---------------------------------------------------------------------------
require 'erb'
THEME_TEMPLATE = ERB.new(File.read("site/theme.txt.erb"))
INDEX_TEMPLATE = ERB.new(File.read("site/index.txt.erb"))
file 'site/src' do |f|
doing :ln, f.name
ln_s '../src', f.name, :force => true
end
task 'site' => 'site/src'
CLOBBER.include 'site/src'
file 'site/stylesheets' do |f|
doing :ln, f.name
ln_s '../stylesheets', f.name, :force => true
end
task 'site' => 'site/stylesheets'
CLOBBER.include 'site/stylesheets'
Theme.each do |theme|
prereqs = [
"src/#{theme.name}.txt",
"site/src",
"site/theme.txt.erb"
]
file "site/#{theme.name}.txt" => prereqs do |f|
doing :erb, f.name
File.open("#{f.name}+", 'wb') do |io|
io.write(THEME_TEMPLATE.result(binding))
end
mv "#{f.name}+", f.name
end
task 'site:text' => "site/#{theme.name}.txt"
CLEAN.include "site/#{theme.name}.txt+"
CLOBBER.include "site/#{theme.name}.txt"
prereqs = [
"site/#{theme.name}.txt",
'site/xhtml11-article.conf',
'site/asciidoc.conf',
"stylesheets/#{theme.name}.css",
"src/#{theme.name}.css",
"site/src",
"site/images/icons"
]
file "site/#{theme.name}.html" => prereqs do |f|
asciidoc f.prerequisites.first, f.name,
'-f', 'site/theme.conf',
:theme => theme.name,
:stylesdir => 'src', # XXX: switch to stylesheets to use full ver
:iconsdir => 'images/icons'
end
task 'site:indexes' => "site/#{theme.name}.html"
CLOBBER.include "site/#{theme.name}.html"
manprereqs = [
"site/asciidoc.1.txt",
"site/xhtml11-manpage.conf"
] + prereqs
file "site/#{theme.name}-manpage.html" => manprereqs do |f|
asciidoc manprereqs.first, f.name,
'-d', 'manpage',
:theme => theme.name,
:stylesdir => 'src'
end
task "site:manpages" => "site/#{theme.name}-manpage.html"
CLOBBER.include "site/#{theme.name}-manpage.html"
prereqs = [
"site/userguide.txt",
'site/xhtml11-article.conf',
'site/asciidoc.conf',
"src/#{theme.name}.css"
]
file "site/#{theme.name}-format.html" => prereqs do |f|
asciidoc prereqs.first, f.name,
:theme => theme.name,
:stylesdir => 'src',
:iconsdir => 'images/icons'
end
task "site:format" => "site/#{theme.name}-format.html"
CLOBBER.include "site/#{theme.name}-format.html"
end
task 'site' => %w[site:text site:indexes site:manpages site:format]
file "site/index.txt" => FileList['site/index.txt.erb','src/*.txt'] do |f|
doing :erb, f.name
File.open("#{f.name}+", 'wb') do |io|
io.write(INDEX_TEMPLATE.result(binding))
end
mv "#{f.name}+", f.name
end
task 'site:text' => "site/index.txt"
CLEAN.include "site/index.txt+"
CLOBBER.include "site/index.txt"
file 'site/index.html' => %w[site/index.txt site/stylesheets site/xhtml11-article.conf] do |f|
asciidoc 'site/index.txt', f.name,
:stylesdir => 'stylesheets',
:theme => 'bare'
end
CLOBBER.include 'site/index.html'
task 'site:indexes' => 'site/index.html'
file 'site/hacking.txt' => %w[HACKING] do |f|
ln 'HACKING', f.name, :force => true
end
CLEAN.include 'site/hacking.txt'
file 'site/hacking.html' => %w[site/hacking.txt site/stylesheets] do |f|
asciidoc 'site/hacking.txt', f.name,
:stylesdir => 'stylesheets',
:theme => 'bare'
end
CLOBBER.include 'site/hacking.html'
task 'site' => 'site/hacking.html'
directory 'site/images'
file 'site/images/icons' => %w[site/images] do |f|
rm_rf f.name
asciidoc_config =
%w[/etc/asciidoc /usr/local/etc/asciidoc /opt/local/etc/asciidoc].
detect { |dir| File.directory?(dir) }
if asciidoc_config
mkdir_p 'site/images'
doing 'ICONS', "site/images/icons (from #{asciidoc_config}/images/icons)"
cp_r "#{asciidoc_config}/images/icons", f.name, :preserve => true
else
STDERR.puts "warn: cannot copy asciidoc icons" +
"(couldn't find AsciiDoc's config directory.)"
mkdir_p f.name
end
end
task 'site' => 'site/images/icons'
CLOBBER.include 'site/images/icons'
# ---------------------------------------------------------------------------
# Shipping it out
# ---------------------------------------------------------------------------
# Push website up to tomayko.com
task 'publish' => %w[site] do |t|
doing :pub, "tomayko.com"
sh <<-EOF
rsync -aL \
--delete \
--delete-excluded \
site/ tomayko.com:/src/adoc-themes
EOF
end
TARNAME = "adoc-themes-#{VERS}"
# Build tarball under dist.
file "dist/#{TARNAME}.tar.gz" => %w[stylesheets site] do |f|
content = FileList['src/*.css','stylesheets/*.css']
content.include 'site/*.{conf,html,txt}'
content.include 'site/images/icons/***'
content.include 'README.txt', 'HACKING', 'Rakefile'
doing :tar, f.name
rm_rf "#{TARNAME}"
mkdir "#{TARNAME}"
content.each do |file|
if File.directory?(file)
mkdir_p file
else
mkdir_p "#{TARNAME}/#{File.dirname(file)}"
ln file, "#{TARNAME}/#{file}"
end
end
mkdir_p 'dist'
rm_f f.name
sh "tar", "czf", f.name, TARNAME
rm_rf TARNAME
end
task 'dist' => "dist/#{TARNAME}.tar.gz"
# Push tarball up to dist site.
task 'release' => %w[dist] do |t|
sh <<-EOF
rsync -av dist/ tomayko.com:/dist/adoc-themes
EOF
end
# ---------------------------------------------------------------------------
# Misc Environment Configuration and Helpers
# ---------------------------------------------------------------------------
# Disable verbose output by default. Invoke like this to turn on:
# $ rake V=1 task ...
# ... or ...
# $ rake verbose task ...
task('verbose') { verbose(true) }
verbose(ENV['V'] == '1')
# Give a status of what's going on (only when not in verbose mode). The
# message looks like:
#
# WHAT message ...
def doing(what, message=nil)
unless verbose
message = [ " #{what.to_s.upcase}", message ].compact.join(' ')
STDERR.puts message
end
end
# Run asciidoc with some default options and attributes.
def asciidoc(src, target, *args)
attributes =
if args.last.is_a?(Hash)
args.pop
else
{}
end
attributes = { :linkcss => '' }.merge(attributes)
doing :adoc, target
args = %W[asciidoc --unsafe -o #{target}] + args +
attributes.map { |k,v| ["-a", "#{k}=#{v}"] }.flatten +
[ (verbose ? '--verbose' : nil), src].compact
sh(*args)
end
task(:clean_doing) { doing(:clean, "#{CLEAN.length} file(s)") }
task :clean => :clean_doing
task(:clobber_doing) { doing(:clobber, "#{CLOBBER.length} file(s)") }
task :clobber => :clobber_doing