Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions lib/guard/less.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 20 additions & 3 deletions spec/guard/less_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down