-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(engine): implement support for data-sly-unwrap
fixes #55 Thanks @znikolovski
- Loading branch information
1 parent
0ccc218
commit 2956097
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2018 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
const Plugin = require('../html/Plugin'); | ||
const VariableBinding = require('../commands/VariableBinding'); | ||
const Conditional = require('../commands/Conditional'); | ||
const BooleanConstant = require('../htl/nodes/BooleanConstant'); | ||
const StringConstant = require('../htl/nodes/StringConstant'); | ||
|
||
module.exports = class UnwrapPlugin extends Plugin { | ||
|
||
beforeElement(stream/* , tagName */) { | ||
const ctx = this.pluginContext; | ||
this.variableName = this._signature.getVariableName(null); | ||
this._useGlobalBinding = this.variableName != null; | ||
if (this.variableName == null) { | ||
this.variableName = ctx.generateVariable('unwrapCondition'); | ||
} | ||
|
||
this.unwrapTest = new Conditional.Start(this.variableName, true); | ||
|
||
if (this._useGlobalBinding) { | ||
stream.write(new VariableBinding.Global(this.variableName, this.expression.root)); | ||
} else { | ||
stream.write(new VariableBinding.Start(this.variableName, this.testRoot())); | ||
} | ||
} | ||
|
||
beforeTagOpen(stream) { | ||
stream.write(this.unwrapTest); | ||
} | ||
|
||
afterTagOpen(stream) { | ||
stream.write(Conditional.END); | ||
} | ||
|
||
beforeTagClose(stream) { | ||
stream.write(this.unwrapTest); | ||
} | ||
|
||
afterTagClose(stream) { | ||
stream.write(Conditional.END); | ||
} | ||
|
||
afterElement(stream) { | ||
if (!this._useGlobalBinding) { | ||
stream.write(VariableBinding.END); | ||
} | ||
} | ||
|
||
testRoot() { | ||
let testNode = this.expression.root instanceof StringConstant && this.expression.root.text.length == 0; | ||
return testNode ? BooleanConstant.TRUE : this.expression.root; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2018 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
module.exports = { | ||
properties: { | ||
unwrap: true, | ||
url: 'url', | ||
title: 'yes' | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
### unwrap with value and variable | ||
# | ||
<a href="${properties.url}" data-sly-unwrap.unwrapTest="${properties.unwrap}"> | ||
<span>${properties.title}</span> | ||
</a> | ||
=== | ||
|
||
<span>yes</span> | ||
|
||
# | ||
### unwrap with value no variable | ||
# | ||
<a href="${properties.url}" data-sly-unwrap="${properties.unwrap}"> | ||
<span>${properties.title}</span> | ||
</a> | ||
=== | ||
|
||
<span>yes</span> | ||
|
||
# | ||
### unwrap | ||
# | ||
<a href="${properties.url}" data-sly-unwrap><span>${properties.title}</span></a> | ||
=== | ||
<span>yes</span> | ||
# | ||
### |