fixed camelCase of style
added values of empty attributes
This commit is contained in:
parent
1ed5eb873e
commit
2afbc2bd60
|
@ -45,6 +45,10 @@ function concatChildren(children) {
|
|||
return res;
|
||||
}
|
||||
|
||||
function convertToCamelCase(str) {
|
||||
return str.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
|
||||
}
|
||||
|
||||
var curlyMap = {'{': 1, '}': -1};
|
||||
|
||||
function convertText(txt) {
|
||||
|
@ -73,6 +77,9 @@ function convertText(txt) {
|
|||
if (txt) {
|
||||
res += (first ? '' : '+') + JSON.stringify(txt);
|
||||
}
|
||||
if (res === "") {
|
||||
res = "true";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -117,15 +124,12 @@ 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;
|
||||
}));
|
||||
var styleArray = [];
|
||||
_.forEach(styleParts, function (stylePart) {
|
||||
styleArray.push(stylePart[0] + ' : ' + convertText(stylePart[1]));
|
||||
styleArray.push(convertToCamelCase(stylePart[0]) + ' : ' + convertText(stylePart[1]));
|
||||
});
|
||||
props[propKey] = '{' + styleArray.join(',') + '}';
|
||||
} else if (key === classSetProp) {
|
||||
|
|
|
@ -12,7 +12,7 @@ define([
|
|||
return React.DOM.div.apply(this, _.flatten([{}].concat([React.DOM.span.apply(this, _.flatten([{
|
||||
'style': {
|
||||
width: 'auto',
|
||||
'line-height': '5px'
|
||||
lineHeight: '5px'
|
||||
},
|
||||
'onClick': generated1.bind(this, items, itemsIndex)
|
||||
}].concat(['Mock'])))])));
|
||||
|
|
|
@ -39,10 +39,13 @@ test('html tests', function (t) {
|
|||
var expected = fs.readFileSync(filename + '.html').toString().replace(/\r/g,"");
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var code = reactTemplates.convertTemplateToReact(html).replace(/\r/g,"");
|
||||
var define = function (req,content) {
|
||||
return content(React, _);
|
||||
var defineMap = {"react":React,"lodash":_};
|
||||
var define = function (requirementsNames,content) {
|
||||
var requirements = _.map(requirementsNames,function (reqName) {
|
||||
return defineMap[reqName];
|
||||
});
|
||||
return content.apply(this,requirements);
|
||||
};
|
||||
console.log(code);
|
||||
var comp = React.createFactory(React.createClass({
|
||||
render: eval(code)
|
||||
}));
|
||||
|
@ -50,7 +53,7 @@ test('html tests', function (t) {
|
|||
console.log(actual);
|
||||
t.equal(actual, expected);
|
||||
if (actual !== expected) {
|
||||
fs.writeFileSync(filename + '.actual.js', actual);
|
||||
fs.writeFileSync(filename + '.actual.html', actual);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue