From 13a14d43d4bc1ecd8348da852c65c705be4661b1 Mon Sep 17 00:00:00 2001 From: Johnny Shields Date: Fri, 27 Nov 2015 15:20:20 +0900 Subject: [PATCH] In SourceWatcher, add a subroutine to find files which should be considered "also dirty" when a given file is touched. --- .../middleman-core/sources/source_watcher.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/middleman-core/lib/middleman-core/sources/source_watcher.rb b/middleman-core/lib/middleman-core/sources/source_watcher.rb index 129b0a8a..3f496594 100644 --- a/middleman-core/lib/middleman-core/sources/source_watcher.rb +++ b/middleman-core/lib/middleman-core/sources/source_watcher.rb @@ -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