fixed #34 api breaks
This commit is contained in:
parent
9d868f7466
commit
d12b61ca0b
|
@ -4,7 +4,7 @@ var fs = require('fs');
|
|||
var path = require('path');
|
||||
var chalk = require('chalk');
|
||||
var reactTemplates = require('./reactTemplates');
|
||||
var convertTemplateToReact = reactTemplates.convertTemplateToReact;
|
||||
var convertRT = reactTemplates.convertRT;
|
||||
var convertJSRTToJS = reactTemplates.convertJSRTToJS;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ function convertFile(source, target, options, context) {
|
|||
if (options.modules === 'jsrt') {
|
||||
js = convertJSRTToJS(html, context, options);
|
||||
} else {
|
||||
js = convertTemplateToReact(html, context, options);
|
||||
js = convertRT(html, context, options);
|
||||
}
|
||||
if (!options.dryRun) {
|
||||
fs.writeFileSync(target, js);
|
||||
|
|
|
@ -424,13 +424,18 @@ function validate(options, context, reportContext, node) {
|
|||
}
|
||||
}
|
||||
|
||||
function convertTemplateToReact(html, options) {
|
||||
var context = require('./context');
|
||||
return convertRT(html, context, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @param {CONTEXT} reportContext
|
||||
* @param {{modules:string,defines:*}?} options
|
||||
* @return {string}
|
||||
*/
|
||||
function convertTemplateToReact(html, reportContext, options) {
|
||||
function convertRT(html, reportContext, options) {
|
||||
var rootNode = cheerio.load(html, {lowerCaseTags: false, lowerCaseAttributeNames: false, xmlMode: true, withStartIndices: true});
|
||||
options = _.defaults({}, options, defaultOptions);
|
||||
var defines = options.defines ? options.defines : {'react/addons': 'React', lodash: '_'};
|
||||
|
@ -495,7 +500,7 @@ function convertJSRTToJS(text, reportContext, options) {
|
|||
options.modules = 'jsrt';
|
||||
var templateMatcherJSRT = /<template>([^]*?)<\/template>/gm;
|
||||
var code = text.replace(templateMatcherJSRT, function (template, html) {
|
||||
return convertTemplateToReact(html, reportContext, options).replace(/;$/, '');
|
||||
return convertRT(html, reportContext, options).replace(/;$/, '');
|
||||
});
|
||||
try {
|
||||
var tree = esprima.parse(code, {range: true, tokens: true, comment: true});
|
||||
|
@ -535,6 +540,7 @@ function normalizeName(name) {
|
|||
|
||||
module.exports = {
|
||||
convertTemplateToReact: convertTemplateToReact,
|
||||
convertRT: convertRT,
|
||||
convertJSRTToJS: convertJSRTToJS,
|
||||
RTCodeError: RTCodeError,
|
||||
normalizeName: normalizeName,
|
||||
|
|
|
@ -41,7 +41,7 @@ test('invalid tests', function (t) {
|
|||
var html = readFileNormalized(filename);
|
||||
var error = null;
|
||||
try {
|
||||
reactTemplates.convertTemplateToReact(html, context);
|
||||
reactTemplates.convertTemplateToReact(html);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ test('conversion test', function (t) {
|
|||
var html = readFileNormalized(filename);
|
||||
var expected = readFileNormalized(filename + '.js');
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var actual = reactTemplates.convertTemplateToReact(html, context).replace(/\r/g, '').trim();
|
||||
var actual = reactTemplates.convertTemplateToReact(html).replace(/\r/g, '').trim();
|
||||
compareAndWrite(t, actual, expected, filename);
|
||||
}
|
||||
});
|
||||
|
@ -143,7 +143,7 @@ test('convert div with all module types', function (t) {
|
|||
var html = readFileNormalized(filename);
|
||||
var expected = readFileNormalized(path.join(dataPath, testData.expected));
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var actual = reactTemplates.convertTemplateToReact(html, context, testData.options).replace(/\r/g, '').trim();
|
||||
var actual = reactTemplates.convertTemplateToReact(html, testData.options).replace(/\r/g, '').trim();
|
||||
compareAndWrite(t, actual, expected, filename);
|
||||
}
|
||||
});
|
||||
|
@ -186,7 +186,7 @@ test('html tests', function (t) {
|
|||
var html = fs.readFileSync(filename).toString();
|
||||
var expected = readFileNormalized(filename + '.html');
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var code = reactTemplates.convertTemplateToReact(html, context).replace(/\r/g, '');
|
||||
var code = reactTemplates.convertTemplateToReact(html).replace(/\r/g, '');
|
||||
var defineMap = {'react/addons': React, lodash: _};
|
||||
//noinspection JSUnusedLocalSymbols
|
||||
var define = function (requirementsNames, content) { //eslint-disable-line no-unused-vars
|
||||
|
|
Loading…
Reference in New Issue