Permalink
Browse files

Merge pull request #2 from roundlake/master

Better handling of `:root_file`: do not fail and support arrays
  • Loading branch information...
2 parents 6bddf6b + 651aadb commit c363edc78f98d7ce382086c9daf43f9b8f546bbe @rymai rymai committed Nov 14, 2012
Showing with 7 additions and 8 deletions.
  1. +1 −0 README.md
  2. +4 −7 lib/guard/sprockets.rb
  3. +2 −1 spec/guard/sprockets_spec.rb
View
@@ -56,6 +56,7 @@ Please read [Guard doc](https://github.com/guard/guard#readme) for more informat
:minify => true # minify the JavaScript files content using Uglifier, default: false
# be sure to add: "gem 'uglifier'" in your Gemfile
:root_file => 'app/js/app.js' # if set, only this file will be compiled, default: nil
+:root_file => ['one.js', 'two.js'] # root_file can be a String or an Array
```
## License
@@ -15,11 +15,11 @@ def initialize(watchers = [], options = {})
@options = options
@asset_paths = Array(@options[:asset_paths] || 'app/assets/javascripts')
@destination = @options[:destination] || 'public/javascripts'
- @root_file = @options[:root_file]
+ @root_file = Array(@options[:root_file]) if @options[:root_file]
@sprockets = ::Sprockets::Environment.new
@asset_paths.each { |p| @sprockets.append_path(p) }
- @sprockets.append_path(@root_file) if @root_file
+ @root_file.each{|f| @sprockets.append_path(Pathname.new(f).dirname) } if @root_file
if @options.delete(:minify)
begin
@@ -42,11 +42,11 @@ def start
end
def run_all
- run_on_change([@root_file]) if @root_file
+ run_on_changes []
end
def run_on_changes(paths)
- paths = [@root_file] if @root_file
+ paths = @root_file if @root_file
success = true
paths.each do |file|
@@ -60,8 +60,6 @@ def run_on_changes(paths)
def sprocketize(path)
path = Pathname.new(path)
- @sprockets.append_path(path.dirname) unless @sprockets.paths.include?(path.dirname)
-
output_filename = without_preprocessor_extension(path.basename.to_s)
output_path = Pathname.new(File.join(@destination, output_filename))
@@ -85,6 +83,5 @@ def sprocketize(path)
def without_preprocessor_extension(filename)
filename.gsub(/^(.*\.(?:js|css))\.[^.]+$/, '\1')
end
-
end
end
@@ -22,7 +22,8 @@
describe 'root_file' do
it { described_class.new.root_file.should be_nil }
- it { described_class.new([], :root_file => 'foo/bar').root_file.should eq 'foo/bar' }
+ it { described_class.new([], :root_file => 'foo/bar').root_file.should eq ['foo/bar'] }
+ it { described_class.new([], :root_file => %w(a b c)).root_file.should eq %w(a b c) }
end
end
end

0 comments on commit c363edc

Please sign in to comment.