diff --git a/CHANGELOG.md b/CHANGELOG.md index f81321ad..814ca03b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ master === +# 4.1.8 + +* Let collection loops access ConfigContext for helpers. #1879 + # 4.1.7 * Upgrade fastimage to 2.0 diff --git a/middleman-core/features/collections.feature b/middleman-core/features/collections.feature index e12ca0a5..2d313a3c 100644 --- a/middleman-core/features/collections.feature +++ b/middleman-core/features/collections.feature @@ -144,6 +144,33 @@ Feature: Collections And I should see 'Article: Blog3 Another Article' And I should see 'Article: Blog2 Yet Another Article' + Scenario: Work with local helpers + Given a fixture app "collections-app" + And a file named "config.rb" with: + """ + module TestHelper + def help_me + "ok" + end + end + + include TestHelper + + data.articles.each_with_index do |a, i| + proxy "/#{i}-#{help_me}.html", a + end + """ + And a file named "data/articles.yaml" with: + """ + --- + - "/blog1/2011-01-01-new-article.html" + - "/blog2/2011-01-02-another-article.html" + """ + Given the Server is running at "collections-app" + When I go to "0-ok.html" + Then I should see 'Newer Article Content' + When I go to "1-ok.html" + Then I should see 'Another Article Content' Scenario: Collected data update with file changes Given a fixture app "collections-app" diff --git a/middleman-core/lib/middleman-core/core_extensions/collections.rb b/middleman-core/lib/middleman-core/core_extensions/collections.rb index 22e6d281..b915fffd 100644 --- a/middleman-core/lib/middleman-core/core_extensions/collections.rb +++ b/middleman-core/lib/middleman-core/core_extensions/collections.rb @@ -90,7 +90,7 @@ module Middleman pair[:root].realize!(dataset) end - ctx = StepContext.new + ctx = StepContext.new(app) StepContext.current = ctx leaves = @leaves.dup diff --git a/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb b/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb index 0b17870d..0549b826 100644 --- a/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb +++ b/middleman-core/lib/middleman-core/core_extensions/collections/step_context.rb @@ -12,17 +12,20 @@ module Middleman attr_reader :descriptors - def initialize + def initialize(app) + @app = app @descriptors = [] end def method_missing(name, *args, &block) internal = :"_internal_#{name}" - return super unless respond_to?(internal) - - send(internal, *args, &block).tap do |r| - @descriptors << r if r.respond_to?(:execute_descriptor) + if respond_to?(internal) + send(internal, *args, &block).tap do |r| + @descriptors << r if r.respond_to?(:execute_descriptor) + end + else + @app.config_context.send(name, *args, &block) end end end