diff --git a/Gemfile b/Gemfile index 5b69d4c..95959dd 100644 --- a/Gemfile +++ b/Gemfile @@ -6,11 +6,11 @@ gem 'rake' require 'rbconfig' -if Config::CONFIG['target_os'] =~ /darwin/i +if RbConfig::CONFIG['target_os'] =~ /darwin/i gem 'rb-fsevent', '>= 0.4.0' gem 'growl_notify', '~> 0.0.1' end -if Config::CONFIG['target_os'] =~ /linux/i +if RbConfig::CONFIG['target_os'] =~ /linux/i gem 'rb-inotify', '>= 0.8.4' gem 'libnotify', '~> 0.3.0' end diff --git a/lib/guard/less.rb b/lib/guard/less.rb index 47a9ed8..834c46e 100644 --- a/lib/guard/less.rb +++ b/lib/guard/less.rb @@ -123,12 +123,25 @@ def mtime_including_imports(file) mtimes = [mtime(file)] File.readlines(file).each do |line| if line =~ /^\s*@import ['"]([^'"]+)/ - imported = File.join(File.dirname(file), $1) - mtimes << if imported =~ /\.le?ss$/ # complete path given ? + basename = $1 + imported = File.join(File.dirname(file), basename) + import_mtime = if imported =~ /\.le?ss$/ # complete path given ? mtime(imported) else # we need to add .less or .lss [mtime("#{imported}.less"), mtime("#{imported}.lss")].max end + # Could be from one of the import paths + if import_mtime == 0 and options[:import_paths] + options[:import_paths].each do |path| + imported = File.join(path, basename) + import_mtime = [import_mtime, if imported =~ /\.le?ss$/ # complete path given ? + mtime(imported) + else # we need to add .less or .lss + [mtime("#{imported}.less"), mtime("#{imported}.lss")].max + end].max + end + end + mtimes << import_mtime end end mtimes.max diff --git a/spec/guard/less_spec.rb b/spec/guard/less_spec.rb index 3983003..9a1e98d 100644 --- a/spec/guard/less_spec.rb +++ b/spec/guard/less_spec.rb @@ -74,7 +74,7 @@ let(:guard) { Guard::Less.new([watcher]) } let(:guard_with_one_to_one_action) do - watcher.action = lambda {|m| "yep/#{m[1]}.less" } + watcher.action = lambda {|m| "yes/#{m[1]}.less" } Guard::Less.new([watcher]) end @@ -93,7 +93,7 @@ end it 'executes .run passing all watched LESS files while observing actions provided' do - guard_with_one_to_one_action.should_receive(:run).with(['yep/a.less', 'yep/b.less']) + guard_with_one_to_one_action.should_receive(:run).with(['yes/a.less', 'yes/b.less']) guard_with_one_to_one_action.run_all end @@ -127,7 +127,7 @@ end context 'if watcher misconfigured to match CSS' do - let(:guard) { Guard::Less.new([Guard::Watcher.new('^yes/.+\.css$')], :output => nil) } + let(:guard) { Guard::Less.new([Guard::Watcher.new(%r{^yes/.+\.css$})], :output => nil) } it 'does not overwrite CSS' do guard.should_not_receive(:compile) @@ -166,6 +166,23 @@ guard.run(['yes/a.less']) end end + + context 'but LESS file has an import in an import_path more recently modified than CSS' do + before do + guard.options[:import_paths] = ['lib/styles'] + write_stub_less_file('yes/a.less', import=true) + write_stub_less_file('lib/styles/b.less') + # touch with :mtime option doesn't seem to work? + FileUtils.touch(['yes/a.css', 'lib/styles/b.less']) + File.utime(Time.now - 5, Time.now - 5, 'yes/a.less') + File.utime(Time.now - 3, Time.now - 3, 'yes/a.css') + end + + it 'compiles the importing LESS file' do + guard.should_receive(:compile) + guard.run(['yes/a.less']) + end + end end context 'when CSS is out of date' do