1
+ # Where our Bootstrap source is installed. Can be overridden by an environment variable.
2
+ BOOTSTRAP_SOURCE = File . expand_path ( "../bootstrap" )
3
+
4
+ # Where to find our custom LESS file.
5
+ BOOTSTRAP_CUSTOM_LESS = '_less/custom.less'
6
+
7
+ def different? ( path1 , path2 )
8
+ require 'digest/md5'
9
+ different = false
10
+ if File . exist? ( path1 ) && File . exist? ( path2 )
11
+ path1_md5 = Digest ::MD5 . hexdigest ( File . read path1 )
12
+ path2_md5 = Digest ::MD5 . hexdigest ( File . read path2 )
13
+ ( path2_md5 != path1_md5 )
14
+ else
15
+ true
16
+ end
17
+ end
18
+
19
+ task :bootstrap => [ :bootstrap_img , :bootstrap_js , :bootstrap_css ]
20
+
21
+ task :bootstrap_img do
22
+ puts "Copying IMG files"
23
+ Dir . glob ( File . join ( BOOTSTRAP_SOURCE , 'img' , '*.png' ) ) . each do |source |
24
+ target = File . join ( 'img' , File . basename ( source ) )
25
+ cp source , target if different? ( source , target )
26
+ end
27
+ end
28
+
29
+ task :bootstrap_js do
30
+ require 'uglifier'
31
+ require 'erb'
32
+
33
+ template = ERB . new %q{
34
+ <!-- AUTOMATICALLY GENERATED. DO NOT EDIT. -->
35
+ <% paths.each do |path| %>
36
+ <script type="text/javascript" src="/bootstrap/js/<%= path %>"></script>
37
+ <% end %>
38
+ }
39
+
40
+ paths = [ ]
41
+ minifier = Uglifier . new
42
+ Dir . glob ( File . join ( BOOTSTRAP_SOURCE , 'js' , '*.js' ) ) . each do |source |
43
+ base = File . basename ( source ) . sub ( /^(.*)\. js$/ , '\1.min.js' )
44
+ paths << base
45
+ target = File . join ( '_bootstrap/js' , base )
46
+ if different? ( source , target )
47
+ File . open ( target , 'w' ) do |out |
48
+ out . write minifier . compile ( File . read ( source ) )
49
+ end
50
+ end
51
+ end
52
+
53
+ File . open ( '_includes/bootstrap.js.html' , 'w' ) do |f |
54
+ f . write template . result ( binding )
55
+ end
56
+ end
57
+
58
+ task :bootstrap_css do |t |
59
+ puts "Copying LESS files"
60
+ Dir . glob ( File . join ( BOOTSTRAP_SOURCE , 'less' , '*.less' ) ) . each do |source |
61
+ target = File . join ( '_bootstrap/less' , File . basename ( source ) )
62
+ cp source , target if different? ( source , target )
63
+ end
64
+
65
+ puts "Compiling #{ BOOTSTRAP_CUSTOM_LESS } "
66
+ sh 'lessc' , '--compress' , BOOTSTRAP_CUSTOM_LESS , 'css/bootstrap.min.css'
67
+ end
68
+
69
+ task :default => :bootstrap #:jekyll
70
+
71
+ #task :jekyll => :bootstrap do
72
+ # sh 'jekyll'
73
+ #end
0 commit comments