Skip to content

Commit 19e4459

Browse files
committed
Guard seems to have better Rake integration than Watchr
Removed Watchr from the Gemfile, added Guard. * Started a simple Guardfile, that will just call Rake rules when changes in the specified directories. * The Guardfile was added in dynamic/Guardfile and soft-linked back because that's what's recommended in the sample that was created with `bundle exec guard init`. * Reorganized the Rakefile, added the one helper I wanted, and added all stubs (that I've though of so far).
1 parent 3159fce commit 19e4459

File tree

5 files changed

+191
-88
lines changed

5 files changed

+191
-88
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gem "uglifier", "~>2.7.2"
99
# gem "coderay", "~>"
1010
# gem "pygmentize", "~>"
1111

12-
gem "watchr", "~>0.7"
1312
gem "rake", "~>10.4.2"
13+
gem "guard", "~>2.13.0"
14+
gem "guard-rake", "~>1.0.0"
1415

Gemfile.lock

+32-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ GEM
22
remote: https://rubygems.org/
33
specs:
44
chunky_png (1.3.4)
5+
coderay (1.1.0)
56
coffee-script (2.4.1)
67
coffee-script-source
78
execjs
@@ -20,28 +21,57 @@ GEM
2021
sass (>= 3.2, < 3.5)
2122
execjs (2.6.0)
2223
ffi (1.9.10)
24+
formatador (0.2.5)
25+
guard (2.13.0)
26+
formatador (>= 0.2.4)
27+
listen (>= 2.7, <= 4.0)
28+
lumberjack (~> 1.0)
29+
nenv (~> 0.1)
30+
notiffany (~> 0.0)
31+
pry (>= 0.9.12)
32+
shellany (~> 0.0)
33+
thor (>= 0.18.1)
34+
guard-rake (1.0.0)
35+
guard
36+
rake
2337
json (1.8.3)
38+
listen (3.0.3)
39+
rb-fsevent (>= 0.9.3)
40+
rb-inotify (>= 0.9)
41+
lumberjack (1.0.9)
42+
method_source (0.8.2)
2443
multi_json (1.11.2)
44+
nenv (0.2.0)
45+
notiffany (0.0.8)
46+
nenv (~> 0.1)
47+
shellany (~> 0.0)
48+
pry (0.10.1)
49+
coderay (~> 1.1.0)
50+
method_source (~> 0.8.1)
51+
slop (~> 3.4)
2552
rake (10.4.2)
2653
rb-fsevent (0.9.6)
2754
rb-inotify (0.9.5)
2855
ffi (>= 0.5.0)
2956
sass (3.4.18)
57+
shellany (0.0.1)
58+
slop (3.6.0)
59+
thor (0.19.1)
3060
uglifier (2.7.2)
3161
execjs (>= 0.3.0)
3262
json (>= 1.8.0)
33-
watchr (0.7)
3463

3564
PLATFORMS
3665
ruby
3766

3867
DEPENDENCIES
3968
coffee-script (~> 2.4.1)
4069
compass (~> 1.0.3)
70+
guard (~> 2.13.0)
71+
guard-rake (~> 1.0.0)
4172
rake (~> 10.4.2)
4273
sass (~> 3.4.18)
4374
uglifier (~> 2.7.2)
44-
watchr (~> 0.7)
4575

4676
BUNDLED WITH
4777
1.10.6

Guardfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dynamic/Guardfile

Rakefile

+105-85
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,111 @@
1-
namespace :css do
2-
source = "./dynamic/css"
3-
dest = "./dynamic/compiled"
4-
5-
##########
6-
# CSS Compressed build
7-
##########
8-
desc "Compile all required CSS"
9-
task :build do
10-
# This code was largely inspired by this SO question
11-
# http://stackoverflow.com/questions/25399962/compass-from-ruby-sasscompiler-not-found
12-
# with addtional code and configuraion options drawn from:
13-
# https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/global_options_parser.rb
14-
# https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/project_options_parser.rb
15-
# NOTE(Drew): I made the choice here to start from the above SO question
16-
# and code snippets to make this call using the undocumented
17-
# Ruby API of Compass rather than building a shell call out
18-
# of a Ruby string and passing that to the OS layer. I don't
19-
# know if it's the right choice, but it's the choice I made.
20-
# Hopefully no one gets bit by it.
21-
require 'compass'
22-
require 'compass/sass_compiler'
23-
24-
Compass.configuration.add_import_path "#{source}/imports"
25-
Compass.add_configuration({
26-
:project_path => ".",
27-
:http_path => "/",
28-
:output_style => :compressed,
29-
:line_comments => false,
30-
:sass_path => source,
31-
:css_path => dest,
32-
:cache_path => "#{source}/.sass-cache",
33-
}, "basho_docs_configs")
34-
compiler = Compass.sass_compiler({
35-
:only_sass_files => Dir.glob("#{source}/*.scss")
36-
})
37-
compiler.compile!
38-
end
1+
# Rules:
2+
# build
3+
# build:css
4+
# build:js
5+
# build:debug
6+
# build:debug:css
7+
# build:debug:js
8+
# clean
9+
# clean:css
10+
# clean:js
11+
# watch
12+
# watch:css
13+
# watch:js
14+
# watch:debug
15+
# watch:debug:css
16+
# watch:debug:js
3917

40-
##########
41-
# CSS Debug build
42-
##########
43-
desc "Compile all scss with the Nested style, and load all css into /static/css"
44-
task :debug do
45-
require 'compass'
46-
require 'compass/sass_compiler'
47-
48-
#TODO(Drew): This is largely a duplicate of the above rule. Split it out
49-
# into it's own function.
50-
Compass.configuration.add_import_path "#{source}/imports"
51-
Compass.add_configuration({
52-
:project_path => ".",
53-
:http_path => "/",
54-
:output_style => :nested,
55-
:line_comments => true,
56-
:sass_path => source,
57-
:css_path => dest,
58-
:cache_path => "#{source}/.sass-cache",
59-
}, "basho_docs_configs")
60-
compiler = Compass.sass_compiler({
61-
:only_sass_files => Dir.glob("#{source}/*.scss")
62-
})
63-
compiler.compile!
64-
end
6518

66-
##########
67-
# CSS Clean
68-
##########
69-
desc "Delete generated CSS files"
70-
task :clean do
71-
#TODO(Drew): This is maybe a bit much to clear generated files. Consider
72-
# working out how to get the below dead code to work?
73-
FileUtils.rm_rf(dest)
74-
# Dir.foreach(dest) { |f|
75-
# if "#{f}" != '.' && "#{f}" != '..'
76-
# File.delete(File.join(dest, f))
77-
# puts "Cleaning #{File.join(dest, f)}"
78-
# end
79-
# }
19+
$css_source = "./dynamic/css"
20+
$css_dest = "./dynamic/compiled"
21+
22+
23+
task :clean => ['clean:js', 'clean:css']
24+
namespace :clean do
25+
26+
task :js do
27+
puts "clean:js not yet implemented."
28+
end
29+
30+
#TODO(Drew): This is maybe a bit much? Can we be more specific?
31+
task :css do
32+
FileUtils.rm_rf($css_dest)
33+
end
34+
end
35+
36+
37+
task :build => ['build:js', 'build:css']
38+
namespace :build do
39+
40+
task :js do
41+
puts "build:js not yet implemented."
42+
end
43+
44+
task :css do
45+
compass_compile({
46+
:output_style => :compressed,
47+
:line_comments => false
48+
})
49+
end
50+
51+
task :debug => ['clean', 'build:debug:js', 'build:debug:css']
52+
namespace :debug do
53+
54+
task :js do
55+
puts "build:debug:js not yet implemented."
8056
end
8157

82-
##########
83-
# CSS Watch
84-
##########
85-
desc "Spin up a Watchr process to monitor changes in the CSS files"
86-
task :watch do
87-
puts "The CSS Watchr is not yet implemented."
58+
task :css do
59+
compass_compile({
60+
:output_style => :nested,
61+
:line_comments => true
62+
})
8863
end
89-
end # of namespace :css
90-
task :css => 'css:build'
64+
end
65+
end
66+
67+
68+
task :watch do sh 'bundle exec guard -g css js'; end
69+
namespace :watch do
70+
71+
task :js do sh 'bundle exec guard -g js'; end
72+
task :css do sh 'bundle exec guard -g css'; end
73+
74+
task :debug do sh 'bundle exec guard -g debug_js debug_css'; end
75+
namespace :debug do
76+
77+
task :js do sh 'bundle exec guard -g debug_js'; end
78+
task :css do sh 'bundle exec guard -g debug_css'; end
79+
end
80+
end
81+
82+
83+
84+
# Helper functions
85+
def compass_compile(configs)
86+
# This code was largely inspired by this SO question
87+
# http://stackoverflow.com/questions/25399962/compass-from-ruby-sasscompiler-not-found
88+
# with addtional code and configuraion options drawn from:
89+
# https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/global_options_parser.rb
90+
# https://github.com/Compass/compass/blob/350bcaa544f594bca972aaa29a9bdfddceee5d4f/cli/lib/compass/exec/project_options_parser.rb
91+
# NOTE(Drew): I made the choice here to start from the above SO question
92+
# and code snippets to make this call using the undocumented
93+
# Ruby API of Compass rather than building a shell call out
94+
# of a Ruby string and passing that to the OS layer. I don't
95+
# know if it's the right choice, but it's the choice I made.
96+
# Hopefully no one gets bit by it.
97+
require 'compass'
98+
require 'compass/sass_compiler'
9199

100+
Compass.configuration.add_import_path "#{$css_source}/imports"
101+
configs[:project_path] = "."
102+
configs[:http_path] = "/"
103+
configs[:sass_path] = $css_source
104+
configs[:css_path] = $css_dest
105+
configs[:cache_path] = "#{$css_source}/.sass-cache"
106+
Compass.add_configuration(configs, "basho_docs_configs")
107+
compiler = Compass.sass_compiler({
108+
:only_sass_files => Dir.glob("#{$css_source}/*.scss")
109+
})
110+
compiler.compile!
111+
end

dynamic/Guardfile

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Uncomment and set this to only include directories you want to watch
2+
directories %w(dynamic) \
3+
.select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
4+
5+
## Note: if you are using the `directories` clause above and you are not
6+
## watching the project directory ('.'), then you will want to move
7+
## the Guardfile to a watched dir and symlink it back, e.g.
8+
#
9+
# $ mkdir config
10+
# $ mv Guardfile config/
11+
# $ ln -s config/Guardfile .
12+
#
13+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
14+
15+
# So it's been recorded, it looks like there might be an issue with guard and
16+
# OS X;
17+
# "If you are on Mac OS X and have problems with either Guard not reacting to
18+
# file changes or Pry behaving strangely, then you probably suffer under a Ruby
19+
# build that uses libedit instead of readline."
20+
# As noted on
21+
# https://github.com/guard/guard/wiki/Add-Readline-support-to-Ruby-on-Mac-OS-X
22+
23+
24+
25+
group :js do
26+
guard 'rake', :task => 'build:js' do
27+
# watch(%r{^$})
28+
end
29+
end
30+
31+
group :css do
32+
guard 'rake', :task => 'build:css' do
33+
watch(%r{^dynamic/css/.*\.css$})
34+
watch(%r{^dynamic/css/.*\.scss$})
35+
watch(%r{^dynamic/css/.*\.sass$})
36+
end
37+
end
38+
39+
group :debug_js do
40+
guard 'rake', :task => 'build:debug:js' do
41+
# watch(%r{^$})
42+
end
43+
end
44+
45+
group :debug_css do
46+
guard 'rake', :task => 'build:debug:css' do
47+
watch(%r{^dynamic/css/.*\.css$})
48+
watch(%r{^dynamic/css/.*\.scss$})
49+
watch(%r{^dynamic/css/.*\.sass$})
50+
end
51+
end

0 commit comments

Comments
 (0)