From 74ea6935e4cf92f45da48fc606141f2809d5de07 Mon Sep 17 00:00:00 2001 From: amitk Date: Tue, 11 Nov 2014 00:35:09 +0200 Subject: [PATCH] Fixed style keys that have "-" in the keys Added repeat index into the scope --- src/reactTemplates.js | 11 ++++++++++- test/data/repeat.html | 6 ++++++ test/src/test.js | 6 +++++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/data/repeat.html diff --git a/src/reactTemplates.js b/src/reactTemplates.js index d2946e2..4de2848 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -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]) { diff --git a/test/data/repeat.html b/test/data/repeat.html new file mode 100644 index 0000000..22ff667 --- /dev/null +++ b/test/data/repeat.html @@ -0,0 +1,6 @@ + +

+

+ Mock +
+

diff --git a/test/src/test.js b/test/src/test.js index aa07700..0ace142 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -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); + } } });