Move some explicitly activated extensions to be auto activate

This commit is contained in:
Ben Hollis 2014-05-23 23:55:34 -07:00
parent 5d4cae2a06
commit 67bb394852
5 changed files with 22 additions and 32 deletions

View file

@ -25,6 +25,15 @@ require 'middleman-core/config_context'
require 'middleman-core/file_renderer' require 'middleman-core/file_renderer'
require 'middleman-core/template_renderer' require 'middleman-core/template_renderer'
# Rack Request
require 'middleman-core/core_extensions/request'
# Custom Extension API and config.rb handling
require 'middleman-core/core_extensions/extensions'
# Catch and show exceptions at the Rack level
require 'middleman-core/core_extensions/show_exceptions'
# Core Middleman Class # Core Middleman Class
module Middleman module Middleman
class Application class Application
@ -168,7 +177,7 @@ module Middleman
delegate :link_to, :image_tag, :asset_path, to: :generic_template_context delegate :link_to, :image_tag, :asset_path, to: :generic_template_context
# Initialize the Middleman project # Initialize the Middleman project
def initialize(&block) def initialize
@template_context_class = Class.new(Middleman::TemplateContext) @template_context_class = Class.new(Middleman::TemplateContext)
@generic_template_context = @template_context_class.new(self) @generic_template_context = @template_context_class.new(self)
@config_context = ConfigContext.new(self, @template_context_class) @config_context = ConfigContext.new(self, @template_context_class)
@ -193,19 +202,6 @@ module Middleman
config[:source] = ENV['MM_SOURCE'] if ENV['MM_SOURCE'] config[:source] = ENV['MM_SOURCE'] if ENV['MM_SOURCE']
# Built-in extensions
activate :default_helpers
activate :lorem
begin
activate :compass
rescue LoadError
# Compass is not available, don't complain about it
end
# Evaluate a passed block if given
@config_context.instance_exec(&block) if block_given?
super super
end end

View file

@ -1,3 +1,5 @@
require 'middleman-core/core_extensions/routing'
module Middleman module Middleman
class ConfigContext class ConfigContext
# page routing # page routing

View file

@ -1,12 +1,6 @@
# Rack Request
require 'middleman-core/core_extensions/request'
# File Change Notifier # File Change Notifier
require 'middleman-core/core_extensions/file_watcher' require 'middleman-core/core_extensions/file_watcher'
# Custom Feature API
require 'middleman-core/core_extensions/extensions'
# Data looks at the data/ folder for YAML files and makes them available # Data looks at the data/ folder for YAML files and makes them available
# to dynamic requests. # to dynamic requests.
require 'middleman-core/core_extensions/data' require 'middleman-core/core_extensions/data'
@ -23,22 +17,18 @@ require 'middleman-core/core_extensions/external_helpers'
# Extended version of Padrino's rendering # Extended version of Padrino's rendering
require 'middleman-core/core_extensions/rendering' require 'middleman-core/core_extensions/rendering'
# Pass custom options to views
require 'middleman-core/core_extensions/routing'
# Catch and show exceptions at the Rack level
require 'middleman-core/core_extensions/show_exceptions'
# Setup default helpers # Setup default helpers
Middleman::Extensions.register :default_helpers do Middleman::Extensions.register :default_helpers, auto_activate_before_configuration: true do
require 'middleman-core/core_extensions/default_helpers' require 'middleman-core/core_extensions/default_helpers'
Middleman::CoreExtensions::DefaultHelpers Middleman::CoreExtensions::DefaultHelpers
end end
# Compass framework # Compass framework
Middleman::Extensions.register :compass do begin
require 'middleman-core/core_extensions/compass' require 'middleman-core/core_extensions/compass'
Middleman::CoreExtensions::Compass Middleman::Extensions.register :compass, Middleman::CoreExtensions::Compass, auto_activate_before_configuration: true
rescue LoadError
# Compass is not available, don't complain about it
end end
### ###
@ -105,7 +95,7 @@ end
# Lorem provides a handful of helpful prototyping methods to generate # Lorem provides a handful of helpful prototyping methods to generate
# words, paragraphs, fake images, names and email addresses. # words, paragraphs, fake images, names and email addresses.
Middleman::Extensions.register :lorem do Middleman::Extensions.register :lorem, auto_activate_before_configuration: true do
require 'middleman-core/extensions/lorem' require 'middleman-core/extensions/lorem'
Middleman::Extensions::Lorem Middleman::Extensions::Lorem
end end

View file

@ -76,7 +76,7 @@ module Middleman
end end
# Override application initialization to load `config.rb` and to call lifecycle hooks. # Override application initialization to load `config.rb` and to call lifecycle hooks.
def initialize def initialize(&block)
super super
self.class.inst = self self.class.inst = self
@ -99,6 +99,9 @@ module Middleman
end end
end end
# Evaluate a passed block if given
config_context.instance_exec(&block) if block_given?
run_hook :initialized run_hook :initialized
run_hook :before_configuration run_hook :before_configuration

View file

@ -1,7 +1,6 @@
require 'middleman-core/template_context' require 'middleman-core/template_context'
# Rendering extension # Rendering extension
# rubocop:disable UnderscorePrefixedVariableName
module Middleman module Middleman
module CoreExtensions module CoreExtensions
module Rendering module Rendering