Fixed style keys that have "-" in the keys

Added repeat index into the scope
This commit is contained in:
amitk 2014-11-11 00:35:09 +02:00
parent 913f4ded0c
commit 74ea6935e4
3 changed files with 21 additions and 2 deletions

View File

@ -112,6 +112,9 @@ function generateProps(node, context) {
}
var res = str.split(":");
res[0] = res[0].trim();
if (res[0].indexOf("-") != -1) {
res[0] = "\"" + res[0] + "\"";
}
res[1] = res[1].trim();
return res;
}));
@ -143,6 +146,11 @@ function defaultContext() {
};
}
function addIfNotThere(array, obj) {
if (!_.contains(array, obj)) {
array.push(obj);
}
}
function convertHtmlToReact(node, context) {
if (node.type === "tag") {
@ -155,7 +163,8 @@ function convertHtmlToReact(node, context) {
if (node.attribs[templateProp]) {
data.item = node.attribs[templateProp].split(" in ")[0].trim();
data.collection = node.attribs[templateProp].split(" in ")[1].trim();
context.boundParams.push(data.item);
addIfNotThere(context.boundParams, data.item);
addIfNotThere(context.boundParams, data.item + "Index");
}
data.props = generateProps(node, context);
if (node.attribs[ifProp]) {

6
test/data/repeat.html Normal file
View File

@ -0,0 +1,6 @@
<!doctype jsx>
<p>
<div rt-repeat="items in this.props.things">
<span style="width:auto;line-height: 5px;" onClick="(evt)=>this.happend(evt);return false;">Mock</span>
</div>
</p>

View File

@ -8,10 +8,11 @@ var path = require('path');
var dataPath = path.resolve(__dirname, '..', 'data');
test('timing test', function (t) {
t.plan(2);
t.plan(3);
check('div.html');
check('test.html');
check('repeat.html');
function check(testFile) {
var filename = path.join(dataPath, testFile);
@ -19,6 +20,9 @@ test('timing test', function (t) {
var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
var actual = reactTemplates.convertTemplateToReact(html);
t.equal(actual, expected);
if (actual !== expected) {
fs.writeFileSync("testdata.js", actual);
}
}
});