From b607d70a52ff2c210085e467885505bde9caf53d Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Fri, 12 Apr 2013 19:55:44 -0700 Subject: [PATCH] Simplify configuration a bit, and make extensions raise an error if the user tries to set an invalid extension option. --- middleman-core/lib/middleman-core/configuration.rb | 8 ++------ middleman-core/lib/middleman-core/extensions.rb | 9 ++++----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/middleman-core/lib/middleman-core/configuration.rb b/middleman-core/lib/middleman-core/configuration.rb index 7d8fc8db..b75c2e8e 100644 --- a/middleman-core/lib/middleman-core/configuration.rb +++ b/middleman-core/lib/middleman-core/configuration.rb @@ -165,16 +165,12 @@ module Middleman # mode and no new settings may be defined. def finalize! @finalized = true + self end # Deep duplicate of the configuration manager def dup - copy = ConfigurationManager.new - @settings.each do |key, setting| - copy_setting = copy.define_setting(setting.key, setting.default, setting.description) - copy_setting.value = setting.value if setting.value_set? - end - copy + ConfigurationManager.new.tap {|c| c.load_settings(self.all_settings) } end # Load in a list of settings diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 64df512b..6000877a 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -114,15 +114,15 @@ module Middleman attr_accessor :app, :options - def initialize(klass, options_hash={}, &block) - @options = ::Middleman::Configuration::ConfigurationManager.new - @options.load_settings(self.class.config.all_settings) + def initialize(klass, options_hash={}) + @options = self.class.config.dup + @options.finalize! options_hash.each do |k, v| @options[k] = v end - block.call(@options) if block_given? + yield @options if block_given? ext = self klass.after_configuration do @@ -132,7 +132,6 @@ module Middleman end def after_configuration - nil end end