Skip to content

Commit b235ec1

Browse files
committed
Refs #103 - Support Teacup
1 parent 1ac7052 commit b235ec1

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

lib/consolidate.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,20 +1191,20 @@ function reactBaseTmpl(data, options){
11911191
* The main render parser for React bsaed templates
11921192
*/
11931193
function reactRenderer(type){
1194-
1194+
11951195
if (require.extensions) {
1196-
1196+
11971197
// Ensure JSX is transformed on require
11981198
if (!require.extensions['.jsx']) {
11991199
require.extensions['.jsx'] = requireReact;
12001200
}
1201-
1201+
12021202
// Supporting .react extension as well as test cases
12031203
// Using .react extension is not recommended.
12041204
if (!require.extensions['.react']) {
12051205
require.extensions['.react'] = requireReact;
12061206
}
1207-
1207+
12081208
}
12091209

12101210
// Return rendering fx
@@ -1367,7 +1367,44 @@ exports.slm.render = function(str, options, fn) {
13671367
};
13681368

13691369
/**
1370-
* expose the instance of the engine
1370+
* Teacup support.
13711371
*/
1372+
exports.teacup = function(path, options, fn) {
1373+
return promisify(fn, function(fn) {
1374+
var engine = requires.teacup || (requires.teacup = require('teacup/lib/express'));
1375+
require.extensions['.teacup'] = require.extensions['.coffee'];
1376+
if (path[0] != '/') {
1377+
path = join(process.cwd(), path);
1378+
}
1379+
if (!options.cache) {
1380+
var originalFn = fn;
1381+
fn = function() {
1382+
delete require.cache[path];
1383+
originalFn.apply(this, arguments);
1384+
};
1385+
}
1386+
engine.renderFile(path, options, fn);
1387+
});
1388+
};
13721389

1373-
exports.requires = requires;
1390+
/**
1391+
* Teacup string support.
1392+
*/
1393+
exports.teacup.render = function(str, options, fn){
1394+
var coffee = require('coffee-script');
1395+
var vm = require('vm');
1396+
var sandbox = {
1397+
module: {exports: {}},
1398+
require: require
1399+
};
1400+
return promisify(fn, function(fn) {
1401+
vm.runInNewContext(coffee.compile(str), sandbox);
1402+
var tmpl = sandbox.module.exports;
1403+
fn(null, tmpl(options));
1404+
});
1405+
}
1406+
1407+
/**
1408+
* expose the instance of the engine
1409+
*/
1410+
exports.requires = requires;

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"devDependencies": {
1212
"arc-templates": "^0.5.1",
1313
"atpl": ">=0.7.6",
14+
"coffee-script": "^1.11.1",
1415
"dot": "^1.0.1",
1516
"dust": "^0.3.0",
1617
"dustjs-helpers": "^1.1.1",
@@ -42,6 +43,7 @@
4243
"should": "*",
4344
"slm": "^0.5.0",
4445
"swig": "^1.4.1",
46+
"teacup": "^2.0.0",
4547
"templayed": ">=0.2.3",
4648
"tinyliquid": "^0.2.22",
4749
"toffee": "^0.1.12",

test/consolidate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ require('./shared').test('slm');
4949
require('./shared').test('arc-templates');
5050
require('./shared/filters').test('arc-templates');
5151
require('./shared/includes').test('arc-templates');
52-
require('./shared/partials').test('arc-templates');
52+
require('./shared/partials').test('arc-templates');
53+
require('./shared').test('teacup');

test/fixtures/teacup/user.teacup

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{renderable, p} = require 'teacup'
2+
3+
module.exports = renderable ({user}) ->
4+
p user.name

0 commit comments

Comments
 (0)