move some feature stuff into main mm file
This commit is contained in:
parent
833a229770
commit
a494d782e6
4 changed files with 72 additions and 54 deletions
|
@ -100,6 +100,52 @@ module Middleman
|
||||||
|
|
||||||
# Organize the sitemap as a tree
|
# Organize the sitemap as a tree
|
||||||
autoload :SitemapTree, "middleman/extensions/sitemap_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
|
end
|
||||||
|
|
||||||
# Where to look in gems for extensions to auto-register
|
# Where to look in gems for extensions to auto-register
|
||||||
|
|
|
@ -43,55 +43,6 @@ module Middleman::CoreExtensions::Extensions
|
||||||
|
|
||||||
app.extend ClassMethods
|
app.extend ClassMethods
|
||||||
app.send :include, InstanceMethods
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -140,7 +91,7 @@ module Middleman::CoreExtensions::Extensions
|
||||||
# Load features before starting server
|
# Load features before starting server
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
run_hook :before_configuration
|
run_hook :before_configuration
|
||||||
|
|
||||||
# Check for and evaluate local configuration
|
# Check for and evaluate local configuration
|
||||||
|
|
|
@ -4,11 +4,20 @@ require "tilt"
|
||||||
module Middleman::CoreExtensions::FrontMatter
|
module Middleman::CoreExtensions::FrontMatter
|
||||||
class << self
|
class << self
|
||||||
def registered(app)
|
def registered(app)
|
||||||
|
app.extend ClassMethods
|
||||||
app.send :include, InstanceMethods
|
app.send :include, InstanceMethods
|
||||||
end
|
end
|
||||||
alias :included :registered
|
alias :included :registered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ClassMethods
|
||||||
|
def frontmatter_changed(matcher=nil, &block)
|
||||||
|
@_frontmatter_changed ||= []
|
||||||
|
@_frontmatter_changed << [block, matcher] if block_given?
|
||||||
|
@_frontmatter_changed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -25,7 +34,7 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
relative_path = path.sub(source_dir, "")
|
relative_path = path.sub(source_dir, "")
|
||||||
|
|
||||||
data = if frontmatter.has_data?(relative_path)
|
data = if frontmatter.has_data?(relative_path)
|
||||||
frontmatter.data(relative_path)
|
frontmatter.data(relative_path)[0]
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
@ -41,7 +50,18 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
{ :options => data }
|
{ :options => data }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def frontmatter
|
def frontmatter
|
||||||
|
@ -78,9 +98,10 @@ module Middleman::CoreExtensions::FrontMatter
|
||||||
|
|
||||||
if result
|
if result
|
||||||
file = file.sub(@app.source_dir, "")
|
file = file.sub(@app.source_dir, "")
|
||||||
@local_data[file] = result[0]
|
@local_data[file] = result
|
||||||
path = File.join(@app.source_dir, file)
|
path = File.join(@app.source_dir, file)
|
||||||
@app.cache.set([:raw_template, path], result[1])
|
@app.cache.set([:raw_template, path], result[1])
|
||||||
|
@app.frontmatter_did_change(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ module Middleman::Sitemap
|
||||||
def touch
|
def touch
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_render(&block)
|
def custom_renderer(&block)
|
||||||
@_custom_renderer ||= nil
|
@_custom_renderer ||= nil
|
||||||
@_custom_renderer = block if block_given?
|
@_custom_renderer = block if block_given?
|
||||||
@_custom_renderer
|
@_custom_renderer
|
||||||
|
@ -89,7 +89,7 @@ module Middleman::Sitemap
|
||||||
instance_exec(&block)
|
instance_exec(&block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif !custom_render.nil?
|
elsif !custom_renderer.nil?
|
||||||
params = args.dup
|
params = args.dup
|
||||||
params << block if block_given?
|
params << block if block_given?
|
||||||
instance_exec(*params, &custom_renderer)
|
instance_exec(*params, &custom_renderer)
|
||||||
|
|
Loading…
Reference in a new issue