1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00

Use EnhancedHash for partial locals (#2169)

* Add failing scenario with examples of partial locals usage

```cucumber
Scenario: Partials can be passed locals                     # features/partials.feature:37
  Given the Server is running at "partials-app"             # lib/middleman-core/step_definitions/server_steps.rb:65
  When I go to "/locals.html"                               # lib/middleman-core/step_definitions/server_steps.rb:74
  Then I should see "Local vars are 'foo', 'bar' and 'baz'" # lib/middleman-core/step_definitions/server_steps.rb:90
    expected "Local vars are '', '' and 'baz'\n\n" to include "Local vars are 'foo', 'bar' and 'baz'"
    Diff:
    @@ -1,2 +1,2 @@
    -Local vars are 'foo', 'bar' and 'baz'
    +Local vars are '', '' and 'baz'
     (RSpec::Expectations::ExpectationNotMetError)
    ./lib/middleman-core/step_definitions/server_steps.rb:91:in `/^I should see "([^\"]*)"$/'
    features/partials.feature:40:in `Then I should see "Local vars are 'foo', 'bar' and 'baz'"'
```

* Use EnhancedHash when initializing hash in partial helper

To allow keys to be fetched either from symbols or strings, as before
v4.1.0.
This commit is contained in:
Tom Sabin 2018-04-10 00:39:02 +01:00 committed by Thomas Reynolds
parent b5fd32eabb
commit fb80ff93e3
4 changed files with 4 additions and 4 deletions

View file

@ -37,7 +37,7 @@ Feature: Provide Sane Defaults for Partial Behavior
Scenario: Partials can be passed locals
Given the Server is running at "partials-app"
When I go to "/locals.html"
Then I should see "Local var is bar"
Then I should see "Local vars are 'foo', 'bar' and 'baz'"
Scenario: Partial and Layout use different engines
Given the Server is running at "different-engine-partial"

View file

@ -1 +1 @@
Local var is <%= foo %>
Local vars are '<%= locals['foo'] %>', '<%= locals[:bar] %>' and '<%= baz %>'

View file

@ -1 +1 @@
<%= partial 'locals', locals: { foo: 'bar' } %>
<%= partial 'locals', locals: { foo: 'foo', 'bar' => 'bar', 'baz': 'baz' } %>

View file

@ -279,7 +279,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
end
def partial(template, options={}, &block)
including_parent_locals = {}
including_parent_locals = Middleman::Util::EnhancedHash.new
including_parent_locals.merge!(@locs || {})
including_parent_locals.merge!(options[:locals] || {})