Refactor some trivial extensions back into application.

This commit is contained in:
Ben Hollis 2013-04-09 22:42:04 -07:00
parent fdd52cd640
commit 283576af1a
7 changed files with 15 additions and 86 deletions

View file

@ -29,6 +29,9 @@ module Middleman
# Ready (all loading and parsing of extensions complete) hook
define_hook :ready
# Runs after the build is finished
define_hook :after_build
# Mix-in helper methods. Accepts either a list of Modules
# and/or a block to be evaluated
# @return [void]
@ -103,21 +106,19 @@ module Middleman
# @return [String, Symbold]
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
include Middleman::CoreExtensions::Extensions
# Manage Ruby string encodings
include Middleman::CoreExtensions::RubyEncoding
# Basic Rack Request Handling
register Middleman::CoreExtensions::Request
# Handle exceptions
register Middleman::CoreExtensions::ShowExceptions
# Add Builder Callbacks
register Middleman::CoreExtensions::Builder
# Add Watcher Callbacks
register Middleman::CoreExtensions::FileWatcher
@ -138,7 +139,7 @@ module Middleman
register Middleman::CoreExtensions::ExternalHelpers
# with_layout and page routing
register Middleman::CoreExtensions::Routing
include Middleman::CoreExtensions::Routing
# Initialize the Middleman project
def initialize(&block)
@ -148,6 +149,11 @@ module Middleman
# Setup the default values from calls to set before initialization
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
instance_exec(&block) if block_given?

View file

@ -4,9 +4,6 @@ require "middleman-core/core_extensions/request"
# File Change Notifier
require "middleman-core/core_extensions/file_watcher"
# Add Builder callbacks
require "middleman-core/core_extensions/builder"
# Custom Feature API
require "middleman-core/core_extensions/extensions"
@ -28,6 +25,3 @@ require "middleman-core/core_extensions/routing"
# Catch and show exceptions at the Rack level
require "middleman-core/core_extensions/show_exceptions"
# Manage Ruby string encodings
require "middleman-core/core_extensions/ruby_encoding"

View file

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

View file

@ -86,9 +86,7 @@ module Middleman
Tilt.mappings.each do |key, klasses|
begin
Tilt[".#{key}"]
rescue LoadError
Tilt.mappings.delete(key)
rescue NameError
rescue LoadError, NameError
Tilt.mappings.delete(key)
end
end

View file

@ -2,22 +2,6 @@
module Middleman
module CoreExtensions
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
#
# with_layout :admin do
@ -83,5 +67,4 @@ module Middleman
end
end
end
end
end

View file

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

View file

@ -19,17 +19,11 @@ module Middleman
app.configure :development do
# Include middlemare
if config[:show_exceptions]
use ::Middleman::CoreExtensions::ShowExceptions::Middleware
use ::Rack::ShowExceptions
end
end
end
end
# Custom exception class
# TODO: Style this ourselves
class Middleware < ::Rack::ShowExceptions
end
end
end
end