Skip to content

Commit

Permalink
fix(engine): do not unwrap call element (#59)
Browse files Browse the repository at this point in the history
fixes #58
  • Loading branch information
tripodsan authored May 9, 2019
1 parent 7016451 commit 8963ead
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/parser/plugins/CallPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ const OutputExpression = require('../commands/OutputExpression');
const MapLiteral = require('../htl/nodes/MapLiteral');

module.exports = class CallPlugin extends Plugin {
// eslint-disable-next-line class-methods-use-this
beforeElement(stream) {
beforeChildren(stream) {
const runtimeCall = new RuntimeCall('call', this._expression.root, [new MapLiteral(this._expression.options)]);
stream.write(new OutputExpression(runtimeCall));
stream.beginIgnore();
}

afterElement(stream) {
// eslint-disable-next-line class-methods-use-this
afterChildren(stream) {
stream.endIgnore();

const runtimeCall = new RuntimeCall('call', this._expression.root, [new MapLiteral(this._expression.options)]);
stream.write(new OutputExpression(runtimeCall));
}
};
20 changes: 10 additions & 10 deletions test/specs/call_spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
<div data-sly-call="${foo}"></div>
===

<section>Template</section>
<div><section>Template</section></div>
#
### sightly call function with empty attribute value
#
<template data-sly-template.foo=""><section>Template</section></template>
<div data-sly-call="${foo}"></div>
===

<section>Template</section>
<div><section>Template</section></div>
#
### sightly call function with parameter
#
<template data-sly-template.foo="${ @ param }"><section>${param}</section></template>
<div data-sly-call="${foo @ param='Template' }"></div>
===

<section>Template</section>
<div><section>Template</section></div>
^^^
$.out(var_0);
#
Expand All @@ -31,23 +31,23 @@
<div data-sly-call="${foo:bar @ param='Template' }"></div>
===

<section>Template</section>
<div><section>Template</section></div>
#
### sightly call function with parameter with colon
#
<template data-sly-template.foo="${ @ jcr:title }"><section>${jcr:title}</section></template>
<div data-sly-call="${foo @ jcr:title='Template' }"></div>
===

<section>Template</section>
<div><section>Template</section></div>
#
### sightly call function with missing parameter
#
<template data-sly-template.foo="${ @ param='Missing parameter' }"><section>${param}</section></template>
<div data-sly-call="${foo}"></div>
===

<section></section>
<div><section></section></div>
^^^
$.out(var_0);
#
Expand All @@ -59,14 +59,14 @@
===


<section>Template 2</section>
<div><section>Template 2</section></div>
#
### sightly call function in any order
#
<div data-sly-call="${foo}"></div>
<template data-sly-template.foo="${ @ param }"><section>Template</section></template>
===
<section>Template</section>
<div><section>Template</section></div>

#
### sightly call function receives correct scope
Expand All @@ -76,7 +76,7 @@
<template data-sly-template.foo="${ @ param }"><section>${param}</section></template>
===

<section></section>
<div><section></section></div>

^^^
$.out(var_0);
Expand All @@ -89,7 +89,7 @@
===


<section>123</section>
<div><div><section>123</section></div></div>
^^^
$.out(var_0);
#
Expand Down
10 changes: 7 additions & 3 deletions test/specs/template_spec.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#
### use external template lib and invoke 1 template
#
<div data-sly-use.lib="template_spec/templateLib.html" data-sly-call="${lib.one}"></div>
<!--/* use sly tag to suppress outer elements */-->
<sly data-sly-use.lib="template_spec/templateLib.html" data-sly-call="${lib.one}"></sly>
===

blah 1
#
### use external template lib and invoke template 2
#
<div data-sly-call="${lib.two}"></div>
<sly data-sly-use.lib="template_spec/templateLib.html"></sly>
===
blah 2
<div>blah 2</div>

#
### use external template lib and invoke template with args
#
<div data-sly-use.lib="template_spec/templateLib.html" data-sly-call="${lib.any @ jcr:title='Hello, world.'}"></div>
<!--/* use unwrap to suppress out elements */-->
<div data-sly-unwrap data-sly-use.lib="template_spec/templateLib.html" data-sly-call="${lib.any @ jcr:title='Hello, world.'}"></div>
===

blah Hello, world.
#
###

0 comments on commit 8963ead

Please sign in to comment.