Refactor some trivial extensions back into application.
This commit is contained in:
parent
fdd52cd640
commit
283576af1a
|
@ -29,6 +29,9 @@ module Middleman
|
||||||
# Ready (all loading and parsing of extensions complete) hook
|
# Ready (all loading and parsing of extensions complete) hook
|
||||||
define_hook :ready
|
define_hook :ready
|
||||||
|
|
||||||
|
# Runs after the build is finished
|
||||||
|
define_hook :after_build
|
||||||
|
|
||||||
# Mix-in helper methods. Accepts either a list of Modules
|
# Mix-in helper methods. Accepts either a list of Modules
|
||||||
# and/or a block to be evaluated
|
# and/or a block to be evaluated
|
||||||
# @return [void]
|
# @return [void]
|
||||||
|
@ -103,21 +106,19 @@ module Middleman
|
||||||
# @return [String, Symbold]
|
# @return [String, Symbold]
|
||||||
config.define_setting :layout, :_auto_layout, 'Default layout name'
|
config.define_setting :layout, :_auto_layout, 'Default layout name'
|
||||||
|
|
||||||
|
# Default string encoding for templates and output.
|
||||||
|
# @return [String]
|
||||||
|
config.define_setting :encoding, "utf-8", 'Default string encoding for templates and output'
|
||||||
|
|
||||||
# Activate custom features and extensions
|
# Activate custom features and extensions
|
||||||
include Middleman::CoreExtensions::Extensions
|
include Middleman::CoreExtensions::Extensions
|
||||||
|
|
||||||
# Manage Ruby string encodings
|
|
||||||
include Middleman::CoreExtensions::RubyEncoding
|
|
||||||
|
|
||||||
# Basic Rack Request Handling
|
# Basic Rack Request Handling
|
||||||
register Middleman::CoreExtensions::Request
|
register Middleman::CoreExtensions::Request
|
||||||
|
|
||||||
# Handle exceptions
|
# Handle exceptions
|
||||||
register Middleman::CoreExtensions::ShowExceptions
|
register Middleman::CoreExtensions::ShowExceptions
|
||||||
|
|
||||||
# Add Builder Callbacks
|
|
||||||
register Middleman::CoreExtensions::Builder
|
|
||||||
|
|
||||||
# Add Watcher Callbacks
|
# Add Watcher Callbacks
|
||||||
register Middleman::CoreExtensions::FileWatcher
|
register Middleman::CoreExtensions::FileWatcher
|
||||||
|
|
||||||
|
@ -138,7 +139,7 @@ module Middleman
|
||||||
register Middleman::CoreExtensions::ExternalHelpers
|
register Middleman::CoreExtensions::ExternalHelpers
|
||||||
|
|
||||||
# with_layout and page routing
|
# with_layout and page routing
|
||||||
register Middleman::CoreExtensions::Routing
|
include Middleman::CoreExtensions::Routing
|
||||||
|
|
||||||
# Initialize the Middleman project
|
# Initialize the Middleman project
|
||||||
def initialize(&block)
|
def initialize(&block)
|
||||||
|
@ -148,6 +149,11 @@ module Middleman
|
||||||
# Setup the default values from calls to set before initialization
|
# Setup the default values from calls to set before initialization
|
||||||
self.class.config.load_settings(self.class.superclass.config.all_settings)
|
self.class.config.load_settings(self.class.superclass.config.all_settings)
|
||||||
|
|
||||||
|
if Object.const_defined?(:Encoding)
|
||||||
|
Encoding.default_internal = config[:encoding]
|
||||||
|
Encoding.default_external = config[:encoding]
|
||||||
|
end
|
||||||
|
|
||||||
# Evaluate a passed block if given
|
# Evaluate a passed block if given
|
||||||
instance_exec(&block) if block_given?
|
instance_exec(&block) if block_given?
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,6 @@ 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"
|
||||||
|
|
||||||
# Add Builder callbacks
|
|
||||||
require "middleman-core/core_extensions/builder"
|
|
||||||
|
|
||||||
# Custom Feature API
|
# Custom Feature API
|
||||||
require "middleman-core/core_extensions/extensions"
|
require "middleman-core/core_extensions/extensions"
|
||||||
|
|
||||||
|
@ -28,6 +25,3 @@ require "middleman-core/core_extensions/routing"
|
||||||
|
|
||||||
# Catch and show exceptions at the Rack level
|
# Catch and show exceptions at the Rack level
|
||||||
require "middleman-core/core_extensions/show_exceptions"
|
require "middleman-core/core_extensions/show_exceptions"
|
||||||
|
|
||||||
# Manage Ruby string encodings
|
|
||||||
require "middleman-core/core_extensions/ruby_encoding"
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
module Middleman
|
|
||||||
module CoreExtensions
|
|
||||||
|
|
||||||
# Convenience methods to allow config.rb to talk to the Builder
|
|
||||||
module Builder
|
|
||||||
|
|
||||||
# Extension registered
|
|
||||||
class << self
|
|
||||||
# @private
|
|
||||||
def registered(app)
|
|
||||||
app.define_hook :after_build
|
|
||||||
end
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -86,9 +86,7 @@ module Middleman
|
||||||
Tilt.mappings.each do |key, klasses|
|
Tilt.mappings.each do |key, klasses|
|
||||||
begin
|
begin
|
||||||
Tilt[".#{key}"]
|
Tilt[".#{key}"]
|
||||||
rescue LoadError
|
rescue LoadError, NameError
|
||||||
Tilt.mappings.delete(key)
|
|
||||||
rescue NameError
|
|
||||||
Tilt.mappings.delete(key)
|
Tilt.mappings.delete(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,22 +2,6 @@
|
||||||
module Middleman
|
module Middleman
|
||||||
module CoreExtensions
|
module CoreExtensions
|
||||||
module Routing
|
module Routing
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registered
|
|
||||||
def registered(app)
|
|
||||||
# Include methods
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
# Routing instance methods
|
|
||||||
module InstanceMethods
|
|
||||||
|
|
||||||
# Takes a block which allows many pages to have the same layout
|
# Takes a block which allows many pages to have the same layout
|
||||||
#
|
#
|
||||||
# with_layout :admin do
|
# with_layout :admin do
|
||||||
|
@ -81,7 +65,6 @@ module Middleman
|
||||||
{ :options => opts, :blocks => blocks }
|
{ :options => opts, :blocks => blocks }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
# Simple extension to manage Ruby encodings
|
|
||||||
module Middleman::CoreExtensions::RubyEncoding
|
|
||||||
|
|
||||||
# Setup extension
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Once registerd
|
|
||||||
def registered(app)
|
|
||||||
# Default string encoding for templates and output.
|
|
||||||
# @return [String]
|
|
||||||
app.config.define_setting :encoding, "utf-8", 'Default string encoding for templates and output'
|
|
||||||
|
|
||||||
app.send :include, InstanceMethods
|
|
||||||
end
|
|
||||||
|
|
||||||
alias :included :registered
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def initialize
|
|
||||||
if Object.const_defined?(:Encoding)
|
|
||||||
Encoding.default_internal = config[:encoding]
|
|
||||||
Encoding.default_external = config[:encoding]
|
|
||||||
end
|
|
||||||
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -19,17 +19,11 @@ module Middleman
|
||||||
app.configure :development do
|
app.configure :development do
|
||||||
# Include middlemare
|
# Include middlemare
|
||||||
if config[:show_exceptions]
|
if config[:show_exceptions]
|
||||||
use ::Middleman::CoreExtensions::ShowExceptions::Middleware
|
use ::Rack::ShowExceptions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Custom exception class
|
|
||||||
# TODO: Style this ourselves
|
|
||||||
class Middleware < ::Rack::ShowExceptions
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue