diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 6714797f..0d01c7d0 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -79,7 +79,7 @@ module Middleman::Base app.set :default_features, [ :lorem, - :sitemap_tree + #:sitemap_tree ] # Default layout name diff --git a/lib/middleman/core_extensions/features.rb b/lib/middleman/core_extensions/features.rb index 7fa963cb..8177a20f 100644 --- a/lib/middleman/core_extensions/features.rb +++ b/lib/middleman/core_extensions/features.rb @@ -63,16 +63,6 @@ module Middleman::CoreExtensions::Features register feature end - # Add a block/proc to be run after features have been setup - def before_configuration(&block) - @run_before_features ||= [] - @run_before_features << block - end - - def run_before_features - @run_before_features || [] - end - # Add a block/proc to be run after features have been setup def after_configuration(&block) @run_after_features ||= [] @@ -85,8 +75,6 @@ module Middleman::CoreExtensions::Features # Load features before starting server def new - run_before_features.each { |block| class_eval(&block) } - # 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 8da90c9a..b2c60c1f 100644 --- a/lib/middleman/core_extensions/file_watcher.rb +++ b/lib/middleman/core_extensions/file_watcher.rb @@ -1,6 +1,9 @@ module Middleman::CoreExtensions::FileWatcher class << self def registered(app) + app.set :run_after_file_change, [] + app.set :run_after_file_delete, [] + app.extend ClassMethods end alias :included :registered @@ -8,23 +11,19 @@ module Middleman::CoreExtensions::FileWatcher module ClassMethods def file_did_change(path) - @run_after_file_change ||= [] - @run_after_file_change.each { |block| block.call(path) } + settings.run_after_file_change.each { |block| block.call(path) } end def on_file_change(&block) - @run_after_file_change ||= [] - @run_after_file_change << block + settings.run_after_file_change << block end def file_did_delete(path) - @run_after_file_delete ||= [] - @run_after_file_delete.each { |block| block.call(path) } + settings.run_after_file_delete.each { |block| block.call(path) } end def on_file_delete(&block) - @run_after_file_delete ||= [] - @run_after_file_delete << block + settings.run_after_file_delete << block end end end \ No newline at end of file diff --git a/lib/middleman/core_extensions/sitemap.rb b/lib/middleman/core_extensions/sitemap.rb index b54831bd..6dbfd6f2 100644 --- a/lib/middleman/core_extensions/sitemap.rb +++ b/lib/middleman/core_extensions/sitemap.rb @@ -4,10 +4,6 @@ module Middleman::CoreExtensions::Sitemap class << self def registered(app) app.set :sitemap, SitemapStore.new(app) - - app.before_configuration do - app.sitemap.setup - end end alias :included :registered end @@ -19,19 +15,24 @@ module Middleman::CoreExtensions::Sitemap @ignored_paths = false @generic_paths = false @proxied_paths = false + + @app.on_file_change do |file| + touch_file(file) + end + + @app.on_file_delete do |file| + remove_file(file) + end + + setup + # @app.after_configuration do + # sitemap.setup + # end end def setup @source = File.expand_path(@app.views, @app.root) build_static_map - - @app.on_file_change do |file| - touch_file(file) - end - - @app.on_file_delete do |file| - remove_file(file) - end end # Check to see if we know about a specific path @@ -126,15 +127,12 @@ module Middleman::CoreExtensions::Sitemap end def touch_file(file) - touch_path(file_to_path(file)) - end - - def touch_path(path) - set_path(path) unless path_exists?(path) + add_file(file) end def remove_file(file) - remove_path(file_to_path(file)) + path = file_to_path(file) + remove_path(path) if path end def remove_path(path) @@ -150,13 +148,18 @@ module Middleman::CoreExtensions::Sitemap end def file_to_path(file) - path = file.sub(@source + "/", "") + @source ||= File.expand_path(@app.views, @app.root) + file = File.expand_path(file, @app.root) + + prefix = @source + "/" + return false unless file.include?(prefix) + + path = file.sub(prefix, "") end_of_the_line = false while !end_of_the_line file_extension = File.extname(path) - # TODO: Loop and continue popping Tilt-aware extensions if ::Tilt.mappings.has_key?(file_extension.gsub(/^\./, "")) path = path.sub(file_extension, "") else @@ -172,8 +175,10 @@ module Middleman::CoreExtensions::Sitemap file.match(/\/\./) || (file.match(/\/_/) && !file.match(/\/__/)) || File.directory?(file) - - add_path(file_to_path(file)) + + path = file_to_path(file) + + add_path(path) if path && !path_exists?(path) end def add_path(path)