diff --git a/middleman-core/features/extension_api_deprecations.feature b/middleman-core/features/extension_api_deprecations.feature new file mode 100644 index 00000000..8c9dd216 --- /dev/null +++ b/middleman-core/features/extension_api_deprecations.feature @@ -0,0 +1,10 @@ +Feature: Extension author could use some hooks + + Scenario: When build + Given a fixture app "extension-api-deprecations-app" + When I run `middleman build` + Then the exit status should be 0 + And the output should contain "`set :layout` is deprecated" + And the file "build/index.html" should contain "In Index" + And the file "build/index.html" should not contain "In Layout" + diff --git a/middleman-core/fixtures/extension-api-deprecations-app/config.rb b/middleman-core/fixtures/extension-api-deprecations-app/config.rb new file mode 100644 index 00000000..bcadf949 --- /dev/null +++ b/middleman-core/fixtures/extension-api-deprecations-app/config.rb @@ -0,0 +1,11 @@ +class LayoutDisabler < Middleman::Extension + def initialize(app, options_hash = {}, &block) + super + + app.set :layout, false + end +end + +::Middleman::Extensions.register(:layout_disabler, LayoutDisabler) + +activate :layout_disabler diff --git a/middleman-core/fixtures/extension-api-deprecations-app/source/index.html.erb b/middleman-core/fixtures/extension-api-deprecations-app/source/index.html.erb new file mode 100644 index 00000000..e9e81333 --- /dev/null +++ b/middleman-core/fixtures/extension-api-deprecations-app/source/index.html.erb @@ -0,0 +1 @@ +In Index diff --git a/middleman-core/fixtures/extension-api-deprecations-app/source/layouts/layout.erb b/middleman-core/fixtures/extension-api-deprecations-app/source/layouts/layout.erb new file mode 100644 index 00000000..ead9c2a9 --- /dev/null +++ b/middleman-core/fixtures/extension-api-deprecations-app/source/layouts/layout.erb @@ -0,0 +1,3 @@ +In Layout + +<%= yield %> diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 0712eed1..4e46ed82 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -391,6 +391,21 @@ module Middleman execute_callbacks(:before_shutdown) end + + # Set attributes (global variables) + # + # @deprecated Prefer accessing settings through "config". + # + # @param [Symbol] key Name of the attribue + # @param value Attribute value + # @return [void] + def set(key, value=nil, &block) + logger.warn "Warning: `set :#{key}` is deprecated. Use `config[:#{key}] =` instead." + + value = block if block_given? + config[key] = value + end + # Work around this bug: http://bugs.ruby-lang.org/issues/4521 # where Ruby will call to_s/inspect while printing exception # messages, which can take a long time (minutes at full CPU)