Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed May 5, 2012
2 parents d473af5 + 929e0e0 commit fc5b92a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 100 deletions.
88 changes: 46 additions & 42 deletions lib/sass/plugin/compiler.rb
Expand Up @@ -5,7 +5,6 @@
require 'sass/callbacks'
require 'sass/plugin/configuration'
require 'sass/plugin/staleness_checker'
require 'sass/plugin/listener'

module Sass::Plugin

Expand Down Expand Up @@ -252,52 +251,57 @@ def watch(individual_files = [])
end
end

template_paths = template_locations # cache the locations
individual_files_hash = individual_files.inject({}) do |h, files|
parent = File.dirname(files.first)
(h[parent] ||= []) << files unless template_paths.include?(parent)
h
end
directories = template_paths + individual_files_hash.keys +
[{:relative_paths => true}]

# TODO: Keep better track of what depends on what
# so we don't have to run a global update every time anything changes.
Sass::Plugin::Listener.new do |l|
template_location_array.each do |template_location, css_location|
l.directory(template_location, {
:modified => lambda do |base, relative|
next if relative !~ /\.s[ac]ss$/
run_template_modified File.join(base, relative)
update_stylesheets(individual_files)
end,

:added => lambda do |base, relative|
next if relative !~ /\.s[ac]ss$/
run_template_created File.join(base, relative)
update_stylesheets(individual_files)
end,

:removed => lambda do |base, relative|
next if relative !~ /\.s[ac]ss$/
run_template_deleted File.join(base, relative)
css = File.join(css_location, relative.gsub(/\.s[ac]ss$/, '.css'))
try_delete_css css
update_stylesheets(individual_files)
end
})
listener = Listen::MultiListener.new(*directories) do |modified, added, removed|
modified.each do |f|
parent = File.dirname(f)
if files = individual_files_hash[parent]
next unless files.first == f
else
next unless f =~ /\.s[ac]ss$/
end
run_template_modified(f)
end

individual_files.each do |template, css|
l.file(template, {
:modified => lambda do
run_template_modified template
update_stylesheets(individual_files)
end,

:added => lambda do
run_template_created template
update_stylesheets(individual_files)
end,

:removed => lambda do
run_template_deleted template
try_delete_css css
update_stylesheets(individual_files)
end
})
added.each do |f|
parent = File.dirname(f)
if files = individual_files_hash[parent]
next unless files.first == f
else
next unless f =~ /\.s[ac]ss$/
end
run_template_created(f)
end

removed.each do |f|
parent = File.dirname(f)
if files = individual_files_hash[parent]
next unless files.first == f
try_delete_css files[1]
else
next unless f =~ /\.s[ac]ss$/
try_delete_css f.gsub(/\.s[ac]ss$/, '.css')
end
run_template_deleted(f)
end

update_stylesheets(individual_files)
end

begin
listener.start
rescue Exception => e
raise e unless e.is_a?(Interrupt)
end
end

Expand Down
58 changes: 0 additions & 58 deletions lib/sass/plugin/listener.rb

This file was deleted.

0 comments on commit fc5b92a

Please sign in to comment.