Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into hurrymaplelad-teacup
  • Loading branch information
doowb committed Sep 18, 2017
2 parents e842211 + 253b661 commit e67ba6b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
6 changes: 6 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.15.0 / 2017-09-18
===================

* add plates support
* add teacup support

0.14.0 / 2016-01-24
===================

Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [react](https://github.com/facebook/react)
- [slm](https://github.com/slm-lang/slm)
- [swig (unmaintained)](https://github.com/paularmstrong/swig)
- [teacup](https://github.com/goodeggs/teacup)
- [templayed](http://archan937.github.com/templayed.js/)
- [twig](https://github.com/justjohn/twig.js)
- [liquid](https://github.com/leizongmin/tinyliquid) [(website)](http://liquidmarkup.org/)
Expand Down
41 changes: 39 additions & 2 deletions lib/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,44 @@ exports.marko.render = function(str, options, fn) {
};

/**
* expose the instance of the engine
* Teacup support.
*/
exports.teacup = function(path, options, fn) {
return promisify(fn, function(fn) {
var engine = requires.teacup || (requires.teacup = require('teacup/lib/express'));
require.extensions['.teacup'] = require.extensions['.coffee'];
if (path[0] != '/') {
path = join(process.cwd(), path);
}
if (!options.cache) {
var originalFn = fn;
fn = function() {
delete require.cache[path];
originalFn.apply(this, arguments);
};
}
engine.renderFile(path, options, fn);
});
};

exports.requires = requires;
/**
* Teacup string support.
*/
exports.teacup.render = function(str, options, fn){
var coffee = require('coffee-script');
var vm = require('vm');
var sandbox = {
module: {exports: {}},
require: require
};
return promisify(fn, function(fn) {
vm.runInNewContext(coffee.compile(str), sandbox);
var tmpl = sandbox.module.exports;
fn(null, tmpl(options));
});
}

/**
* expose the instance of the engine
*/
exports.requires = requires;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"babel-core": "^6.7.6",
"babel-preset-react": "^6.5.0",
"bracket-template": "^1.0.3",
"coffee-script": "^1.11.1",
"dot": "^1.0.1",
"dust": "^0.3.0",
"dustjs-helpers": "^1.1.1",
Expand Down Expand Up @@ -55,6 +56,7 @@
"should": "*",
"slm": "^0.5.0",
"swig": "^1.4.1",
"teacup": "^2.0.0",
"templayed": ">=0.2.3",
"tinyliquid": "^0.2.22",
"toffee": "^0.1.12",
Expand Down
1 change: 1 addition & 0 deletions test/consolidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ require('./shared/includes').test('arc-templates');
require('./shared/partials').test('arc-templates');
require('./shared').test('marko');
require('./shared').test('bracket');
require('./shared').test('teacup');
4 changes: 4 additions & 0 deletions test/fixtures/teacup/user.teacup
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{renderable, p} = require 'teacup'

module.exports = renderable ({user}) ->
p user.name

0 comments on commit e67ba6b

Please sign in to comment.