From 7402af4fc20072c0b9c860cc6a65cca19f169ef2 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Wed, 21 Jun 2017 21:17:03 +0530 Subject: [PATCH] feat(template): edge.share now merges locals --- examples/views/withlayouts/index.edge | 2 +- src/Template/index.js | 2 +- test/unit/edge.spec.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/views/withlayouts/index.edge b/examples/views/withlayouts/index.edge index e53aa69..a237cb2 100644 --- a/examples/views/withlayouts/index.edge +++ b/examples/views/withlayouts/index.edge @@ -3,4 +3,4 @@

Jumbotron heading

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.

Sign up today

-@endsection +@endsection \ No newline at end of file diff --git a/src/Template/index.js b/src/Template/index.js index 6d007f1..3580581 100644 --- a/src/Template/index.js +++ b/src/Template/index.js @@ -252,7 +252,7 @@ class Template { * @chainable */ share (locals) { - this._locals = locals + _.merge(this._locals, locals) return this } diff --git a/test/unit/edge.spec.js b/test/unit/edge.spec.js index af35761..0b6e80c 100644 --- a/test/unit/edge.spec.js +++ b/test/unit/edge.spec.js @@ -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') + }) })