mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Allow dynamic attributes for template tags
This commit is contained in:
parent
a63d15f26f
commit
f420882fdf
@ -100,10 +100,10 @@ TemplateCompiler.prototype = {
|
||||
var rootNode;
|
||||
var templateBuilder;
|
||||
function handleErrors() {
|
||||
var message = 'An error occurred while trying to compile template at path "' + filePath + '". Error(s) in template: ';
|
||||
var message = 'An error occurred while trying to compile template at path "' + filePath + '". Error(s) in template:\n';
|
||||
var errors = _this.getErrors();
|
||||
for (var i = 0, len = errors.length; i < len; i++) {
|
||||
message += + '(' + (i + 1) + ') ' + (errors[i].pos ? '[' + errors[i].pos + '] ' : '') + errors[i].message + ' ';
|
||||
message += (i + 1) + ') ' + (errors[i].pos ? '[' + errors[i].pos + '] ' : '') + errors[i].message + '\n';
|
||||
}
|
||||
var error = new Error(message);
|
||||
error.errors = _this.getErrors();
|
||||
|
||||
@ -67,8 +67,7 @@ function handleAttributes(value, parent, path) {
|
||||
attrProps = {
|
||||
type: 'string'
|
||||
};
|
||||
}
|
||||
else if (typeof attrProps === 'string') {
|
||||
} else if (typeof attrProps === 'string') {
|
||||
attrProps = {
|
||||
type: attrProps
|
||||
};
|
||||
@ -88,6 +87,13 @@ function buildTag(tagObject, path, taglib, dirname) {
|
||||
|
||||
var tag = new Taglib.Tag(taglib);
|
||||
|
||||
if (tagObject.attributes == null) {
|
||||
// allow any attributes if no attributes are declared
|
||||
tagObject.attributes = {
|
||||
'*': 'string'
|
||||
};
|
||||
}
|
||||
|
||||
propertyHandlers(tagObject, {
|
||||
name: function(value) {
|
||||
tag.name = value;
|
||||
|
||||
@ -416,8 +416,12 @@ module.exports = function transform(node, compiler, template) {
|
||||
if (attrDef.removeDashes === true) {
|
||||
name = removeDashes(name);
|
||||
}
|
||||
node.addDynamicAttribute(name, value);
|
||||
node.setDynamicAttributesProperty(attrDef.targetProperty);
|
||||
if (node.addDynamicAttribute) {
|
||||
node.addDynamicAttribute(name, value);
|
||||
node.setDynamicAttributesProperty(attrDef.targetProperty);
|
||||
} else {
|
||||
node.setProperty(name, value);
|
||||
}
|
||||
} else {
|
||||
node.setProperty(name, value);
|
||||
}
|
||||
|
||||
@ -392,4 +392,9 @@ describe('raptor-templates/rhtml' , function() {
|
||||
it("should support scanning a directory for tags", function(done) {
|
||||
testRender("test-project/rhtml-templates/scanned-tags.rhtml", {}, done);
|
||||
});
|
||||
|
||||
it("should support scanning a directory for tags", function(done) {
|
||||
testRender("test-project/rhtml-templates/template-tag-dynamic-attributes.rhtml", {}, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -80,6 +80,9 @@
|
||||
"default-value": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
"test-template-tag-dynamic-attributes": {
|
||||
"template": "./hello.rhtml"
|
||||
}
|
||||
},
|
||||
"tags-dir": "./scanned-tags"
|
||||
|
||||
@ -0,0 +1 @@
|
||||
<test-template-tag-dynamic-attributes name="Frank"/>
|
||||
@ -0,0 +1 @@
|
||||
Hello Frank!
|
||||
Loading…
x
Reference in New Issue
Block a user