move some feature stuff into main mm file

This commit is contained in:
Thomas Reynolds 2011-12-04 11:58:45 -08:00
parent 833a229770
commit a494d782e6
4 changed files with 72 additions and 54 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)