Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
pageTitle : "Weld examples",
description : "Below is a list of examples",
dogfood : "This page was rendered with weld",
link: {
"@.": "foo",
"@href": "bar"
},
example : [
{
title : 'Render an object into some elements',
Expand Down Expand Up @@ -44,6 +48,7 @@ <h1 class="pageTitle">Random title</h1>
<p class="description">
This is a description about this page..
</p>
<a href="" class="link"></a>
<p class="dogfood">
here is some dogfood
</p>
Expand Down
23 changes: 23 additions & 0 deletions lib/weld.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@
obj = value[lkey];
target = ops.match(template, element, lkey, obj);

if(lkey.length > 1 && lkey[0] == '@') {
var attr = lkey.substr(1);

if(attr == '.') {

// set the element's value as normal
if(~({}).toString.call(value).indexOf('Date')) {
value[lkey] = value[lkey].toString();
}

if (value.nodeType || typeof value[lkey] !== 'object') {
ops.set(parent, element, key, value[lkey], row);
}
} else {
// set the element's attribute
element.setAttribute(attr, value[lkey]);
}

continue;
}

if (target) {
ops.traverse(template, target, lkey, obj, row);

Expand Down Expand Up @@ -444,6 +465,8 @@
return res;
},
match : function match(parent, element, key, value) {
if(key[0] == '@') return;

if(typeof config.alias[key] !== 'undefined') {
if(typeof config.alias[key] === 'function') {
key = config.alias[key](parent, element, key, value) || key;
Expand Down
2 changes: 1 addition & 1 deletion lib/weld.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.