Skip to content

Commit

Permalink
feat(template): edge.share now merges locals
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 21, 2017
1 parent 7ddbb1e commit 7402af4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/views/withlayouts/index.edge
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<h1 class="display-3">Jumbotron heading</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<p><a class="btn btn-lg btn-success" href="#" role="button">Sign up today</a></p>
@endsection
@endsection
2 changes: 1 addition & 1 deletion src/Template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Template {
* @chainable
*/
share (locals) {
this._locals = locals
_.merge(this._locals, locals)
return this
}

Expand Down
9 changes: 9 additions & 0 deletions test/unit/edge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,13 @@ test.group('Edge', (group) => {
const statement = `{{ size('foo') }}`
assert.equal(edge.renderString(statement).trim(), '3')
})

test('merge locals shared for multiple times', (assert) => {
const edge = new Edge()
const sharedInstance = edge.share({ foo: 'bar' })
sharedInstance.share({ bar: 'baz' })

const statement = `{{ foo }} {{ bar }}`
assert.equal(sharedInstance.renderString(statement).trim(), 'bar baz')
})
})

0 comments on commit 7402af4

Please sign in to comment.