diff --git a/compiler/Node.js b/compiler/Node.js index 79c1679f1..8f14f2b49 100644 --- a/compiler/Node.js +++ b/compiler/Node.js @@ -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 () { diff --git a/compiler/TemplateBuilder.js b/compiler/TemplateBuilder.js index 803418dc4..781fa0e52 100644 --- a/compiler/TemplateBuilder.js +++ b/compiler/TemplateBuilder.js @@ -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 = []; diff --git a/taglibs/core/core-tag-transformer.js b/taglibs/core/core-tag-transformer.js index 5305b9497..2ef4b9c06 100644 --- a/taglibs/core/core-tag-transformer.js +++ b/taglibs/core/core-tag-transformer.js @@ -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; diff --git a/test/render-test.js b/test/render-test.js index 1eab4c91e..755024bb7 100644 --- a/test/render-test.js +++ b/test/render-test.js @@ -350,4 +350,10 @@ describe('marko/marko' , function() { name: '' }, done); }); + + it.only("should handle 'body-only-if' correctly", function(done) { + testRender("test-project/html-templates/body-only-if.marko", { + url: '/foo' + }, done); + }); }); diff --git a/test/test-project/html-templates/body-only-if.marko b/test/test-project/html-templates/body-only-if.marko new file mode 100644 index 000000000..7b50e8a79 --- /dev/null +++ b/test/test-project/html-templates/body-only-if.marko @@ -0,0 +1,6 @@ + + Some Link + + + Another Link + \ No newline at end of file diff --git a/test/test-project/html-templates/body-only-if.marko.expected.html b/test/test-project/html-templates/body-only-if.marko.expected.html new file mode 100644 index 000000000..86243dc62 --- /dev/null +++ b/test/test-project/html-templates/body-only-if.marko.expected.html @@ -0,0 +1 @@ +Some LinkAnother Link \ No newline at end of file