1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

In SourceWatcher, add a subroutine to find files which should be considered "also dirty" when a given file is touched.

This commit is contained in:
Johnny Shields 2015-11-27 15:20:20 +09:00
parent 45939e7e93
commit 13a14d43d4

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