Merge pull request #1695 from johnnyshields/fix-sass-livereload-master

Fix SASS partial live reloading
This commit is contained in:
Thomas Reynolds 2015-11-27 13:55:15 -08:00
commit b0582bcebf

View file

@ -222,6 +222,8 @@ module Middleman
return if updated.empty? && removed.empty?
updated |= find_related_files(updated + removed)
update(updated.map { |s| Pathname(s) }, removed.map { |s| Pathname(s) })
end
@ -304,5 +306,24 @@ module Middleman
::Middleman::SourceFile.new(Pathname(relative_path), path, @directory, types)
end
# Finds files which should also be considered to be dirty when
# the given file(s) are touched.
#
# @param [Array] files The original touched file paths.
# @return [Array] All related file paths, not including the source file paths.
Contract ArrayOf[String] => ArrayOf[String]
def find_related_files(files)
files.map do |file|
related_files = []
# If any SASS file changes, reload all non-partials
if file =~ /\.(sass|scss)$/
related_files |= Dir[File.join(@directory, app.config[:css_dir], '**/[^_]*.{scss,sass}')]
end
related_files
end.flatten.uniq - files
end
end
end