diff --git a/lib/middleman/core_extensions/data.rb b/lib/middleman/core_extensions/data.rb index 17345c08..4882d915 100755 --- a/lib/middleman/core_extensions/data.rb +++ b/lib/middleman/core_extensions/data.rb @@ -34,15 +34,10 @@ module Middleman::CoreExtensions::Data def initialize(app) @app = app @local_data = {} - - data_path = File.join(@app.root, @app.data_dir) - local_path = File.join(data_path, "*.{yaml,yml,json}") - Dir[local_path].each do |f| - touch_file(f) - end end def touch_file(file) + file = File.expand_path(file, @app.root) extension = File.extname(file) basename = File.basename(file, extension) @@ -54,6 +49,7 @@ module Middleman::CoreExtensions::Data return end + @app.logger.debug :data_update, Time.now, basename if @app.settings.logging? @local_data[basename] = recursively_enhance(data) end diff --git a/lib/middleman/core_extensions/features.rb b/lib/middleman/core_extensions/features.rb index 71979c01..ec445f3e 100644 --- a/lib/middleman/core_extensions/features.rb +++ b/lib/middleman/core_extensions/features.rb @@ -35,6 +35,7 @@ module Middleman::CoreExtensions::Features def registered(app) app.set :default_features, [] app.define_hook :after_configuration + app.define_hook :before_configuration app.extend ClassMethods end alias :included :registered @@ -66,6 +67,8 @@ module Middleman::CoreExtensions::Features # Load features before starting server def new! + run_hook :before_configuration + # Check for and evaluate local configuration local_config = File.join(self.root, "config.rb") if File.exists? local_config diff --git a/lib/middleman/core_extensions/file_watcher.rb b/lib/middleman/core_extensions/file_watcher.rb index b26b37fd..b275df86 100644 --- a/lib/middleman/core_extensions/file_watcher.rb +++ b/lib/middleman/core_extensions/file_watcher.rb @@ -1,8 +1,17 @@ +require "find" + module Middleman::CoreExtensions::FileWatcher class << self def registered(app) app.extend ClassMethods app.send :include, InstanceMethods + app.before_configuration do + Find.find(settings.root) do |path| + next if File.directory?(path) + file_did_change(path.sub("#{settings.root}/", "")) + end + end + end alias :included :registered end @@ -19,21 +28,31 @@ module Middleman::CoreExtensions::FileWatcher @_file_deleted << [block, matcher] if block_given? @_file_deleted end + + def file_did_change(path) + file_changed.each do |callback, matcher| + next if path.match(%r{^#{build_dir}/}) + next if !matcher.nil? && !path.match(matcher) + instance_exec(path, &callback) + end + end + + def file_did_delete(path) + file_deleted.each do |callback, matcher| + next if path.match(%r{^#{build_dir}/}) + next unless matcher.nil? || path.match(matcher) + instance_exec(path, &callback) + end + end end module InstanceMethods def file_did_change(path) - settings.file_changed.each do |callback, matcher| - next unless matcher.nil? || path.match(matcher) - settings.instance_exec(path, &callback) - end + settings.file_did_change(path) end def file_did_delete(path) - settings.file_deleted.each do |callback, matcher| - next unless matcher.nil? || path.match(matcher) - settings.instance_exec(path, &callback) - end + settings.file_did_delete(path) end end end \ No newline at end of file diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index a45a8f14..429ecc29 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -66,14 +66,6 @@ module Middleman::CoreExtensions::FrontMatter @app = app @source ||= File.expand_path(@app.views, @app.root) @local_data = {} - - Dir[File.join(@source, "**/*")].each do |file| - next if file.match(/\/\./) || - (file.match(/\/_/) && !file.match(/\/__/)) || - !file.match(self.class.matcher) - - touch_file(file.sub(@app.root, "").sub(/^\//, "")) - end end def has_data?(path) diff --git a/lib/middleman/core_extensions/sitemap.rb b/lib/middleman/core_extensions/sitemap.rb index c055a022..a9b3a1a7 100644 --- a/lib/middleman/core_extensions/sitemap.rb +++ b/lib/middleman/core_extensions/sitemap.rb @@ -49,7 +49,7 @@ module Middleman::CoreExtensions::Sitemap @generic_paths = false @proxied_paths = false - build_static_map + # build_static_map end # Check to see if we know about a specific path @@ -216,6 +216,7 @@ module Middleman::CoreExtensions::Sitemap return false if path == "layout" || path.match(/^layouts/) + @app.logger.debug :sitemap_update, Time.now, path if @app.settings.logging? set_path(path) true