mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Added support for "body-only-if"
This commit is contained in:
parent
e5498ac247
commit
ddc6cd5de8
@ -411,10 +411,9 @@ Node.prototype = {
|
||||
this.generateCodeForChildren(template);
|
||||
return;
|
||||
}
|
||||
var nextStripVarId = template.getAttribute('nextStripVarId');
|
||||
if (nextStripVarId == null) {
|
||||
nextStripVarId = template.setAttribute('nextStripVarId', 0);
|
||||
}
|
||||
var nextStripVarId = template.data.nextStripVarId || (template.data.nextStripVarId = 0);
|
||||
template.data.nextStripVarId++;
|
||||
|
||||
var varName = '__strip' + nextStripVarId++;
|
||||
template.statement('var ' + varName + ' = !(' + this.stripExpression + ');');
|
||||
template.statement('if (' + varName + ') {').indent(function () {
|
||||
|
||||
@ -242,7 +242,7 @@ function TemplateBuilder(compiler, path, rootNode) {
|
||||
this.dirname = nodePath.dirname(path);
|
||||
this.options = compiler.options || {};
|
||||
this.templateName = null;
|
||||
this.attributes = {};
|
||||
this.attributes = this.data = {};
|
||||
this.concatWrites = this.options.concatWrites !== false;
|
||||
this.writer = new CodeWriter(this.concatWrites);
|
||||
this.staticVars = [];
|
||||
|
||||
@ -142,6 +142,14 @@ var coreAttrHandlers = [
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'body-only-if', function(attr, node) {
|
||||
if (!node.setStripExpression) {
|
||||
node.addError('The c-strip directive is not allowed for target node');
|
||||
}
|
||||
node.setStripExpression(attr);
|
||||
}
|
||||
],
|
||||
[
|
||||
'c-input', function(attr, node) {
|
||||
this.inputAttr = attr;
|
||||
|
||||
@ -350,4 +350,10 @@ describe('marko/marko' , function() {
|
||||
name: '<label for="hello">Hello</label>'
|
||||
}, done);
|
||||
});
|
||||
|
||||
it.only("should handle 'body-only-if' correctly", function(done) {
|
||||
testRender("test-project/html-templates/body-only-if.marko", {
|
||||
url: '/foo'
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
6
test/test-project/html-templates/body-only-if.marko
Normal file
6
test/test-project/html-templates/body-only-if.marko
Normal file
@ -0,0 +1,6 @@
|
||||
<a href="${data.url}" body-only-if="!data.url">
|
||||
Some Link
|
||||
</a>
|
||||
<a href="${data.invalidUrl}" body-only-if="!data.invalidUrl">
|
||||
Another Link
|
||||
</a>
|
||||
@ -0,0 +1 @@
|
||||
<a href="/foo">Some Link</a>Another Link
|
||||
Loading…
x
Reference in New Issue
Block a user