diff --git a/lib/middleman.rb b/lib/middleman.rb index e8219f8c..bef1cadc 100755 --- a/lib/middleman.rb +++ b/lib/middleman.rb @@ -168,7 +168,7 @@ module Middleman :AccessLog => [] } - app_class = options[:app] ||= ::Middleman.server.new + app_class = options[:app] ||= ::Middleman.server.inst opts[:app] = app_class opts[:server] = 'thin' diff --git a/lib/middleman/base.rb b/lib/middleman/base.rb index 57adc78d..f458f4fe 100644 --- a/lib/middleman/base.rb +++ b/lib/middleman/base.rb @@ -23,9 +23,6 @@ class Middleman::Base # Ready (all loading and parsing of extensions complete) hook define_hook :ready - # Initialized (after initialized() runs) - define_hook :initialized - class << self # Reset Rack setup @@ -49,7 +46,11 @@ class Middleman::Base # @private # @return [Middleman::Base] def inst(&block) - @inst ||= new(&block) + @inst ||= begin + mm = new(&block) + mm.run_hook :ready + mm + end end # Return built Rack app @@ -243,9 +244,6 @@ class Middleman::Base set :source_dir, File.join(root, source) super - - # Run initialized callbacks - run_hook :initialized end # Shared cache instance diff --git a/lib/middleman/core_extensions/default_helpers.rb b/lib/middleman/core_extensions/default_helpers.rb index fbbb81d4..db5665f2 100644 --- a/lib/middleman/core_extensions/default_helpers.rb +++ b/lib/middleman/core_extensions/default_helpers.rb @@ -23,7 +23,7 @@ module Middleman::CoreExtensions::DefaultHelpers app.helpers Helpers - app.initialized do + app.ready do ::I18n.load_path = Dir["#{File.join(root, 'locales', '*.yml')}"] end end diff --git a/lib/middleman/core_extensions/extensions.rb b/lib/middleman/core_extensions/extensions.rb index f44e07a8..d42c2085 100644 --- a/lib/middleman/core_extensions/extensions.rb +++ b/lib/middleman/core_extensions/extensions.rb @@ -40,6 +40,7 @@ module Middleman::CoreExtensions::Extensions app.define_hook :before_configuration app.define_hook :build_config app.define_hook :development_config + app.extend ClassMethods app.send :include, InstanceMethods @@ -164,8 +165,6 @@ module Middleman::CoreExtensions::Extensions puts "== Extension: #{ext}" end end - - run_hook :ready end end end diff --git a/lib/middleman/core_extensions/front_matter.rb b/lib/middleman/core_extensions/front_matter.rb index 786608bc..4523b504 100644 --- a/lib/middleman/core_extensions/front_matter.rb +++ b/lib/middleman/core_extensions/front_matter.rb @@ -11,36 +11,37 @@ module Middleman::CoreExtensions::FrontMatter module InstanceMethods def initialize + super + file_changed FrontMatter.matcher do |file| frontmatter.touch_file(file) end - + file_deleted do |file| frontmatter.remove_file(file) end - + provides_metadata FrontMatter.matcher do |path| relative_path = path.sub(source_dir, "") - + data = if frontmatter.has_data?(relative_path) frontmatter.data(relative_path).first else {} end - + # Forward remaining data to helpers data_content("page", data) - + %w(layout layout_engine).each do |opt| if data.has_key?(opt) data[opt.to_sym] = data.delete(opt) end end - + { :options => data } end - - super + end def frontmatter diff --git a/lib/middleman/core_extensions/rendering.rb b/lib/middleman/core_extensions/rendering.rb index 3970442e..3e25ed7d 100644 --- a/lib/middleman/core_extensions/rendering.rb +++ b/lib/middleman/core_extensions/rendering.rb @@ -26,12 +26,12 @@ module Middleman::CoreExtensions::Rendering module InstanceMethods def initialize + super + file_changed %r{^source/} do |file| path = File.expand_path(file, root) cache.remove(:raw_template, path) end - - super end def render_template(path, locs={}, opts={}) diff --git a/lib/middleman/core_extensions/sitemap.rb b/lib/middleman/core_extensions/sitemap.rb index ac0ff162..b58cc922 100644 --- a/lib/middleman/core_extensions/sitemap.rb +++ b/lib/middleman/core_extensions/sitemap.rb @@ -11,6 +11,8 @@ module Middleman::CoreExtensions::Sitemap module InstanceMethods def initialize + super + file_changed do |file| sitemap.touch_file(file) end @@ -18,8 +20,6 @@ module Middleman::CoreExtensions::Sitemap file_deleted do |file| sitemap.remove_file(file) end - - super end def sitemap diff --git a/lib/middleman/renderers/haml.rb b/lib/middleman/renderers/haml.rb index 825c3dbc..fdd758cd 100644 --- a/lib/middleman/renderers/haml.rb +++ b/lib/middleman/renderers/haml.rb @@ -3,15 +3,11 @@ module Middleman::Renderers::Haml def registered(app) require "haml" app.send :include, ::Haml::Helpers - app.send :include, InstanceMethods + + app.ready do + init_haml_helpers + end end alias :included :registered end - - module InstanceMethods - def initialize - super - init_haml_helpers - end - end end \ No newline at end of file