-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
72 lines (60 loc) · 1.97 KB
/
Rakefile
File metadata and controls
72 lines (60 loc) · 1.97 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
# Where our Bootstrap source is installed. Can be overridden by an environment variable.
BOOTSTRAP_SOURCE = File.expand_path("../bootstrap")
# Where to find our custom LESS file.
BOOTSTRAP_CUSTOM_LESS = '_less/custom.less'
def different?(path1, path2)
require 'digest/md5'
different = false
if File.exist?(path1) && File.exist?(path2)
path1_md5 = Digest::MD5.hexdigest(File.read path1)
path2_md5 = Digest::MD5.hexdigest(File.read path2)
(path2_md5 != path1_md5)
else
true
end
end
task :bootstrap => [:bootstrap_img, :bootstrap_js, :bootstrap_css]
task :bootstrap_img do
puts "Copying IMG files"
Dir.glob(File.join(BOOTSTRAP_SOURCE, 'img', '*.png')).each do |source|
target = File.join('img', File.basename(source))
cp source, target if different?(source, target)
end
end
task :bootstrap_js do
require 'uglifier'
require 'erb'
template = ERB.new %q{
<!-- AUTOMATICALLY GENERATED. DO NOT EDIT. -->
<% paths.each do |path| %><script type="text/javascript" src="/bootstrap/js/<%= path %>"></script>
<% end %>
}
paths = []
minifier = Uglifier.new
Dir.glob(File.join(BOOTSTRAP_SOURCE, 'js', '*.js')).each do |source|
base = File.basename(source).sub(/^(.*)\.js$/, '\1.min.js')
paths << base
target = File.join('js', base)
if different?(source, target)
File.open(target, 'w') do |out|
out.write minifier.compile(File.read(source))
end
end
end
File.open('_includes/bootstrap.js.html', 'w') do |f|
f.write template.result(binding)
end
end
task :bootstrap_css do |t|
puts "Copying LESS files"
Dir.glob(File.join(BOOTSTRAP_SOURCE, 'less', '*.less')).each do |source|
target = File.join('_bootstrap/less', File.basename(source))
cp source, target if different?(source, target)
end
puts "Compiling #{BOOTSTRAP_CUSTOM_LESS}"
sh 'lessc', '--compress', BOOTSTRAP_CUSTOM_LESS, 'css/bootstrap.min.css'
end
task :default => :bootstrap #:jekyll
#task :jekyll => :bootstrap do
# sh 'jekyll'
#end