Marko v3: Fixes #222 - Allow open only tags to be defined in tag definition

This commit is contained in:
Patrick Steele-Idem 2016-02-11 10:53:22 -07:00
parent c78ca5f352
commit 8f9d1094af
9 changed files with 29 additions and 1 deletions

View File

@ -77,7 +77,11 @@ class HtmlJsParser {
} }
}; };
var parser = this.parser = htmljs.createParser(listeners); var parser = this.parser = htmljs.createParser(listeners, {
isOpenTagOnly: function(tagName) {
return handlers.isOpenTagOnly(tagName);
}
});
parser.parse(src); parser.parse(src);
} }
} }

View File

@ -268,6 +268,11 @@ class Parser {
return null; // Default parse state return null; // Default parse state
} }
isOpenTagOnly(tagName) {
var tagDef = this.context.getTagDef(tagName);
return tagDef && tagDef.openTagOnly;
}
} }
module.exports = Parser; module.exports = Parser;

View File

@ -50,6 +50,7 @@ class Tag{
this.isRepeated = null; this.isRepeated = null;
this.isNestedTag = false; this.isNestedTag = false;
this.parentTagName = null; this.parentTagName = null;
this.openTagOnly = null;
this.body = null; this.body = null;
this.type = null; // Only applicable for nested tags this.type = null; // Only applicable for nested tags
this._nodeFactory = undefined; this._nodeFactory = undefined;

View File

@ -426,6 +426,10 @@ TagHandlers.prototype = {
} else { } else {
throw new Error('Invalid value for "body". Allowed: "static-text", "parsed-text" or "html"'); throw new Error('Invalid value for "body". Allowed: "static-text", "parsed-text" or "html"');
} }
},
openTagOnly: function(value) {
this.tag.openTagOnly = value;
} }
}; };

View File

@ -0,0 +1,2 @@
Hello Frank!
Hello John!

View File

@ -0,0 +1,6 @@
{
"<open-tag-only>": {
"renderer": "./open-tag-only-tag.js",
"open-tag-only": true
}
}

View File

@ -0,0 +1,3 @@
module.exports = function (input, out) {
out.write('Hello ' + input.name + '!\n');
};

View File

@ -0,0 +1,2 @@
<open-tag-only name="Frank">
<open-tag-only name="John" />

View File

@ -0,0 +1 @@
exports.templateData = {};