From 36f1edfc1fdc459754f14c9ae16a2be1b50f9cca Mon Sep 17 00:00:00 2001 From: avim Date: Mon, 19 Jan 2015 16:22:42 +0200 Subject: [PATCH] support style tags - cheerio parses them as special section in the html --- src/reactTemplates.js | 8 ++++---- test/data/style.rt | 5 +++++ test/data/style.rt.html | 1 + test/src/test.js | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 test/data/style.rt create mode 100644 test/data/style.rt.html diff --git a/src/reactTemplates.js b/src/reactTemplates.js index 58bee4d..86131c1 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -57,7 +57,7 @@ _.forEach(reactSupportedAttributes, function (attributeReactName) { function concatChildren(children) { var res = ''; _.forEach(children, function (child) { - if (child.indexOf(' /*') !== 0 && child) { + if (child && child.indexOf(' /*') !== 0 ) { res += ',' + child; } else { res += child; @@ -258,7 +258,7 @@ function hasNonSimpleChildren(node) { } function convertHtmlToReact(node, context) { - if (node.type === 'tag') { + if (node.type === 'tag' || node.type === 'style') { context = { boundParams: _.clone(context.boundParams), injectedFunctions: context.injectedFunctions, @@ -302,9 +302,9 @@ function convertHtmlToReact(node, context) { if (node.attribs[ifProp]) { data.condition = node.attribs[ifProp].trim(); } - data.children = concatChildren(_.map(node.children, function (child) { + data.children = node.children ? concatChildren(_.map(node.children, function (child) { return convertHtmlToReact(child, context); - })); + })) : ''; if (hasNonSimpleChildren(node)) { data.body = shouldUseCreateElement(context) ? tagTemplateCreateElement(data) : tagTemplate(data); diff --git a/test/data/style.rt b/test/data/style.rt new file mode 100644 index 0000000..b50a71d --- /dev/null +++ b/test/data/style.rt @@ -0,0 +1,5 @@ +
+ +
\ No newline at end of file diff --git a/test/data/style.rt.html b/test/data/style.rt.html new file mode 100644 index 0000000..e830405 --- /dev/null +++ b/test/data/style.rt.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/src/test.js b/test/src/test.js index 9052f05..cbc1979 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -113,7 +113,7 @@ function normalizeHtml(html) { } test('html tests', function (t) { - var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt','custom-element.rt']; + var files = ['scope.rt', 'lambda.rt', 'eval.rt', 'props.rt', 'custom-element.rt', 'style.rt']; t.plan(files.length); files.forEach(check);