diff --git a/lib/middleman.rb b/lib/middleman.rb index bef1cadc..71dc102a 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -100,6 +100,52 @@ module Middleman # Organize the sitemap as a tree autoload :SitemapTree, "middleman/extensions/sitemap_tree" + + class << self + def registered + @_registered ||= {} + end + + def register(name, namespace=nil, version=nil, &block) + # If we've already got a matching extension that passed the + # version check, bail out. + return if registered.has_key?(name.to_sym) && + !registered[name.to_sym].is_a?(String) + + if block_given? + version = namespace + end + + passed_version_check = true + if !version.nil? + requirement = ::Gem::Requirement.create(version) + if !requirement.satisfied_by?(Middleman::GEM_VERSION) + passed_version_check = false + end + end + + registered[name.to_sym] = if !passed_version_check + "== #{name} failed version check. Requested #{version}, got #{Middleman::VERSION}" + elsif block_given? + block + elsif namespace + namespace + end + end + + def load(name) + name = name.to_sym + return nil unless registered.has_key?(name) + + extension = registered[name] + if extension.is_a?(Proc) + extension = extension.call() || nil + registered[name] = extension + end + + extension + end + end end # Where to look in gems for extensions to auto-register diff --git a/lib/middleman/core_extensions/extensions.rb b/lib/middleman/core_extensions/extensions.rb index 30bfe919..6ddd1b7c 100644 --- a/lib/middleman/core_extensions/extensions.rb +++ b/lib/middleman/core_extensions/extensions.rb @@ -43,55 +43,6 @@ module Middleman::CoreExtensions::Extensions app.extend ClassMethods app.send :include, InstanceMethods - - # Setup extension API - ::Middleman::Extensions.extend API - end - end - - module API - def registered - @_registered ||= {} - end - - def register(name, namespace=nil, version=nil, &block) - # If we've already got a matching extension that passed the - # version check, bail out. - return if registered.has_key?(name.to_sym) && - !registered[name.to_sym].is_a?(String) - - if block_given? - version = namespace - end - - passed_version_check = true - if !version.nil? - requirement = ::Gem::Requirement.create(version) - if !requirement.satisfied_by?(Middleman::GEM_VERSION) - passed_version_check = false - end - end - - registered[name.to_sym] = if !passed_version_check - "== #{name} failed version check. Requested #{version}, got #{Middleman::VERSION}" - elsif block_given? - block - elsif namespace - namespace - end - end - - def load(name) - name = name.to_sym - return nil unless registered.has_key?(name) - - extension = registered[name] - if extension.is_a?(Proc) - extension = extension.call() || nil - registered[name] = extension - end - - extension end end @@ -140,7 +91,7 @@ module Middleman::CoreExtensions::Extensions # Load features before starting server def initialize super - + run_hook :before_configuration # Check for and evaluate local configuration diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index 86f2cfce..6118b559 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -4,11 +4,20 @@ require "tilt" module Middleman::CoreExtensions::FrontMatter class << self def registered(app) + app.extend ClassMethods app.send :include, InstanceMethods end alias :included :registered end + module ClassMethods + def frontmatter_changed(matcher=nil, &block) + @_frontmatter_changed ||= [] + @_frontmatter_changed << [block, matcher] if block_given? + @_frontmatter_changed + end + end + module InstanceMethods def initialize super @@ -25,7 +34,7 @@ module Middleman::CoreExtensions::FrontMatter relative_path = path.sub(source_dir, "") data = if frontmatter.has_data?(relative_path) - frontmatter.data(relative_path) + frontmatter.data(relative_path)[0] else {} end @@ -41,7 +50,18 @@ module Middleman::CoreExtensions::FrontMatter { :options => data } end + end + + def frontmatter_changed(*args, &block) + self.class.frontmatter_changed(*args, &block) + end + def frontmatter_did_change(path) + frontmatter_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 frontmatter @@ -78,9 +98,10 @@ module Middleman::CoreExtensions::FrontMatter if result file = file.sub(@app.source_dir, "") - @local_data[file] = result[0] + @local_data[file] = result path = File.join(@app.source_dir, file) @app.cache.set([:raw_template, path], result[1]) + @app.frontmatter_did_change(path) end end diff --git a/lib/middleman/sitemap/page.rb b/lib/middleman/sitemap/page.rb index 834c2761..a5557bfd 100644 --- a/lib/middleman/sitemap/page.rb +++ b/lib/middleman/sitemap/page.rb @@ -71,7 +71,7 @@ module Middleman::Sitemap def touch end - def custom_render(&block) + def custom_renderer(&block) @_custom_renderer ||= nil @_custom_renderer = block if block_given? @_custom_renderer @@ -89,7 +89,7 @@ module Middleman::Sitemap instance_exec(&block) end end - elsif !custom_render.nil? + elsif !custom_renderer.nil? params = args.dup params << block if block_given? instance_exec(*params, &custom_renderer)