-
Notifications
You must be signed in to change notification settings - Fork 25
/
Rakefile
63 lines (47 loc) · 1.63 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
require 'rubygems'
require 'sprockets'
require 'juicer'
require 'yui/compressor'
require 'uri'
task :default => :prep
ROOT = File.expand_path(File.dirname(__FILE__))
cssinput = File.join(ROOT, 'src', 'snoopy.css');
cssoutput = File.join(ROOT, 'snoopy.css');
cssmin = File.join(ROOT, 'snoopy-min.css');
jsinput = File.join(ROOT, 'src', 'snoopy.js');
jsoutput = File.join(ROOT, 'snoopy.js');
jsmin = File.join(ROOT, 'snoopy-min.js');
bminput = File.join(ROOT, 'src', 'bookmarklet.js');
bmoutput = File.join(ROOT, 'bookmarklet.js');
# merge
task :mergecss do
sh "juicer merge -m none #{cssinput} -o #{cssoutput} --force" # need to do this in ruby...
end
task :mergejs do
secretary = Sprockets::Secretary.new(
:source_files => [jsinput]
)
concatenation = secretary.concatenation
concatenation.save_to(jsoutput);
end
task :merge => [:mergejs, :mergecss]
# squash
task :squashcss do
cssfile = File.open(cssoutput, "r")
csscompress = YUI::CssCompressor.new
File.open(cssmin, 'w') { |file| file.write( csscompress.compress( cssfile.read ) ) }
end
task :squashjs do
jsfile = File.open(jsoutput, "r")
jscompress = YUI::JavaScriptCompressor.new
File.open(jsmin, 'w') { |file| file.write( jscompress.compress( jsfile.read ) ) }
end
task :squash => [:squashjs, :squashcss]
task :prepbookmarklet do
bmfile = File.open(bminput, "r")
bmcompress = YUI::JavaScriptCompressor.new
output = 'javascript:'+URI.escape(bmcompress.compress( bmfile.read ), Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
File.open(bmoutput, 'w') { |file| file.write( output ) }
end
# do it all!
task :prep => [:merge, :squash, :prepbookmarklet]