mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
support named amd module
This commit is contained in:
parent
bd47783a0c
commit
866df02d0e
@ -26,7 +26,7 @@ function convertFile(source, target, options, context) {
|
||||
}
|
||||
|
||||
var html = fs.readFileSync(source).toString();
|
||||
if (!options.name) {
|
||||
if (options.modules === 'none' && !options.name) {
|
||||
options.name = reactTemplates.normalizeName(path.basename(source, path.extname(source))) + 'RT';
|
||||
}
|
||||
var js = convertTemplateToReact(html, options);
|
||||
|
@ -49,7 +49,6 @@ module.exports = optionator({
|
||||
}, {
|
||||
option: 'name',
|
||||
alias: 'n',
|
||||
default: 'filenameRT',
|
||||
type: 'String',
|
||||
description: 'When using globals, the name for the variable. The default is the [file name]RT'
|
||||
}, {
|
||||
|
9
test/data/div.rt.amd.js
Normal file
9
test/data/div.rt.amd.js
Normal file
@ -0,0 +1,9 @@
|
||||
define('div', [
|
||||
'react/addons',
|
||||
'lodash'
|
||||
], function (React, _) {
|
||||
'use strict';
|
||||
return function () {
|
||||
return React.createElement('div', {});
|
||||
};
|
||||
});
|
3
test/data/div.rt.globals.js
Normal file
3
test/data/div.rt.globals.js
Normal file
@ -0,0 +1,3 @@
|
||||
var div = function () {
|
||||
return React.createElement('div', {});
|
||||
};
|
@ -105,6 +105,44 @@ test('conversion test', function (t) {
|
||||
}
|
||||
});
|
||||
|
||||
test('conversion test globals', function (t) {
|
||||
var files = ['div.rt'];
|
||||
t.plan(files.length);
|
||||
|
||||
files.forEach(check);
|
||||
|
||||
function check(testFile) {
|
||||
var filename = path.join(dataPath, testFile);
|
||||
var html = readFileNormalized(filename);
|
||||
var expected = readFileNormalized(filename + '.globals.js');
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var actual = reactTemplates.convertTemplateToReact(html, {modules: 'none', name: 'div'}).replace(/\r/g, '').trim();
|
||||
t.equal(actual, expected);
|
||||
if (actual !== expected) {
|
||||
fs.writeFileSync(filename + '.actual.js', actual);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('conversion test amd with name', function (t) {
|
||||
var files = ['div.rt'];
|
||||
t.plan(files.length);
|
||||
|
||||
files.forEach(check);
|
||||
|
||||
function check(testFile) {
|
||||
var filename = path.join(dataPath, testFile);
|
||||
var html = readFileNormalized(filename);
|
||||
var expected = readFileNormalized(filename + '.amd.js');
|
||||
// var expected = fs.readFileSync(filename.replace(".html", ".js")).toString();
|
||||
var actual = reactTemplates.convertTemplateToReact(html, {modules: 'amd', name: 'div'}).replace(/\r/g, '').trim();
|
||||
t.equal(actual, expected);
|
||||
if (actual !== expected) {
|
||||
fs.writeFileSync(filename + '.actual.js', actual);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function normalizeHtml(html) {
|
||||
return cheerio.load(html, {normalizeWhitespace: true}).html()
|
||||
.replace(/\>\s+/mg, '>')
|
||||
|
Loading…
x
Reference in New Issue
Block a user