Fixes #226 - Allow placeholders in tag name

This commit is contained in:
Patrick Steele-Idem 2016-02-16 19:01:00 -07:00
parent 7d536a7c3c
commit 0c1babd588
8 changed files with 7 additions and 23 deletions

View File

@ -225,8 +225,6 @@ class CompileContext {
throw new Error('Invalid attributes');
}
ok(typeof tagName === 'string', 'Invalid "tagName"');
var node;
var elNode = builder.htmlElement(elDef);
var taglibLookup = this.taglibLookup;

View File

@ -93,6 +93,7 @@ class Parser {
var builder = context.builder;
var tagName = el.tagName;
var tagNameExpression = el.tagNameExpression;
var attributes = el.attributes;
var argument = el.argument; // e.g. For <for(color in colors)>, argument will be "color in colors"
@ -100,7 +101,9 @@ class Parser {
argument = argument.value;
}
if (tagName === 'compiler-options') {
if (tagNameExpression) {
tagName = builder.parseExpression(tagNameExpression);
} else if (tagName === 'compiler-options') {
attributes.forEach(function (attr) {
let attrName = attr.name;
let handler = COMPILER_ATTRIBUTE_HANDLERS[attrName];

View File

@ -1,14 +0,0 @@
'use strict';
module.exports = function(elNode, codegen) {
var tagName = elNode.argument;
if (!tagName) {
codegen.addError('Invalid <html-element> tag. Expected: <html-element(<tag-name-expression>) ... >');
return;
}
tagName = codegen.builder.parseExpression(tagName, { escapeXml: false });
elNode.setTagName(tagName);
return elNode;
};

View File

@ -2,8 +2,5 @@
"taglib-id": "marko-html",
"<html-comment>": {
"renderer": "./html-comment-tag.js"
},
"<html-element>": {
"code-generator": "./html-element-tag.js"
}
}

View File

@ -0,0 +1,3 @@
<hello-${data.myTagName} class="my-class" foo="bar">
My nested content
</>

View File

@ -1,3 +0,0 @@
<html-element("hello-${data.myTagName}") class="my-class" foo="bar">
My nested content
</html-element>