Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support Teacup #104

Open
wants to merge 2 commits into from

1 participant

@hurrymaplelad

Descendant of coffeecup, requested in #103.

Disabling caching currently won't work for helpers since they use the Node require cache. I could diff and purge the whole module.cache after each render, but that feels janky. Better to just use node-supervisor and friends in development.

@hurrymaplelad hurrymaplelad referenced this pull request in goodeggs/teacup
Closed

Pull into Consolidate.js #17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @hurrymaplelad

    Refs #103 - Support Teacup

    hurrymaplelad authored
  2. @hurrymaplelad
This page is out of date. Refresh to see the latest.
View
1  Readme.md
@@ -27,6 +27,7 @@
- [swig](https://github.com/paularmstrong/swig) [(website)](http://paularmstrong.github.com/swig/)
- [templayed](http://archan937.github.com/templayed.js/)
- [toffee](https://github.com/malgorithms/toffee)
+ - [teacup](https://github.com/goodeggs/teacup)
- [underscore](https://github.com/documentcloud/underscore) [(website)](http://documentcloud.github.com/underscore/)
- [walrus](https://github.com/jeremyruppel/walrus) [(website)](http://documentup.com/jeremyruppel/walrus/)
- [whiskers](https://github.com/gsf/whiskers.js/tree/)
View
38 lib/consolidate.js
@@ -702,3 +702,41 @@ exports.dot.render = function (str, options, fn) {
fn(err);
}
};
+
+/**
+ * Teacup support.
+ */
+exports.teacup = function(path, options, fn) {
+ var engine = requires['teacup/lib/express'] || (requires['teacup/lib/express'] = 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);
+};
+
+/**
+ * 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
+ };
+ try {
+ vm.runInNewContext(coffee.compile(str), sandbox);
+ var tmpl = sandbox.module.exports;
+ fn(null, tmpl(options));
+ } catch (err) {
+ fn(err);
+ }
+}
View
3  package.json
@@ -36,7 +36,8 @@
"toffee": "0.0.52",
"atpl": ">=0.5.5",
"templayed": ">=0.2.3",
- "dot": "1.0.1"
+ "dot": "1.0.1",
+ "teacup": ">=0.2.7"
},
"main": "index",
"scripts": {
View
1  test/consolidate.js
@@ -28,3 +28,4 @@ require('./shared').test('toffee');
require('./shared').test('atpl');
require('./shared').test('templayed');
require('./shared').test('dot');
+require('./shared').test('teacup');
View
4 test/fixtures/teacup/user.teacup
@@ -0,0 +1,4 @@
+{renderable, p} = require 'teacup'
+
+module.exports = renderable ({user}) ->
+ p user.name
Something went wrong with that request. Please try again.