diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index c9ec754f..5dd3058b 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -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? diff --git a/middleman-core/lib/middleman-core/core_extensions.rb b/middleman-core/lib/middleman-core/core_extensions.rb index 2267cd7c..ff17629b 100644 --- a/middleman-core/lib/middleman-core/core_extensions.rb +++ b/middleman-core/lib/middleman-core/core_extensions.rb @@ -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" diff --git a/middleman-core/lib/middleman-core/core_extensions/builder.rb b/middleman-core/lib/middleman-core/core_extensions/builder.rb deleted file mode 100644 index 71c4730a..00000000 --- a/middleman-core/lib/middleman-core/core_extensions/builder.rb +++ /dev/null @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/rendering.rb b/middleman-core/lib/middleman-core/core_extensions/rendering.rb index 4bcd3456..0d687ba0 100644 --- a/middleman-core/lib/middleman-core/core_extensions/rendering.rb +++ b/middleman-core/lib/middleman-core/core_extensions/rendering.rb @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/routing.rb b/middleman-core/lib/middleman-core/core_extensions/routing.rb index d0bf6c6d..338a2a78 100644 --- a/middleman-core/lib/middleman-core/core_extensions/routing.rb +++ b/middleman-core/lib/middleman-core/core_extensions/routing.rb @@ -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 @@ -81,7 +65,6 @@ module Middleman { :options => opts, :blocks => blocks } end end - end end end end diff --git a/middleman-core/lib/middleman-core/core_extensions/ruby_encoding.rb b/middleman-core/lib/middleman-core/core_extensions/ruby_encoding.rb deleted file mode 100644 index 3ff70b13..00000000 --- a/middleman-core/lib/middleman-core/core_extensions/ruby_encoding.rb +++ /dev/null @@ -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 diff --git a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb index 8c34612a..60cac3e8 100644 --- a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb @@ -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