Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

exposed str_render function; added support for consolidate.js

  • Loading branch information...
commit 8ee89cff750e31526a1b9938e3fdebe0b75ad968 1 parent 22b39a0
@malgorithms authored
Showing with 49 additions and 13 deletions.
  1. +21 −6 index.coffee
  2. +27 −6 index.js
  3. +1 −1  package.json
View
27 index.coffee
@@ -1,20 +1,35 @@
# expose the render function
-eclass = require('./lib/engine').engine
-exports.engine = eclass
+{engine} = require('./lib/engine')
+{view} = require('./lib/view')
-e = new eclass { verbose: false, prettyPrintErrors: true }
+exports.engine = engine
+
+e = new engine { verbose: false, prettyPrintErrors: true }
exports.expressEngine = e
# a pretty name for general usage
exports.render = e.run
-# express 3.x support
-exports.__express = (filename, options, cb) ->
- e.run filename, options, (err, res) ->
+# express 3.x support; by default, caching is on
+__express = exports.__express = (filename, options, cb) ->
+ cache = if options.cache? then options.cache else true
+ eng = if options.cache then e else new engine { prettyPrintErrors: true }
+ eng.run filename, options, (err, res) ->
if err
cb new Error(err)
else
cb null, res
+# consolidate.js support, which doesn't want caching on by default
+exports.__consolidate_engine_render = (filename, options, cb) ->
+ if not options.cache? then options.cache = false
+ __express filename, options, cb
+
+# consolidate.js wants this, but it might generally be useful
+exports.str_render = (template_str, options, cb) ->
+ v = new view template_str, options
+ [err, res] = v.run options
+ cb err, res
+
# express 2.x support
exports.compile = require('./lib/view').expressCompile
View
33 index.js
@@ -1,12 +1,14 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var e, eclass;
+ var e, engine, view, __express;
- eclass = require('./lib/engine').engine;
+ engine = require('./lib/engine').engine;
- exports.engine = eclass;
+ view = require('./lib/view').view;
- e = new eclass({
+ exports.engine = engine;
+
+ e = new engine({
verbose: false,
prettyPrintErrors: true
});
@@ -15,8 +17,13 @@
exports.render = e.run;
- exports.__express = function(filename, options, cb) {
- return e.run(filename, options, function(err, res) {
+ __express = exports.__express = function(filename, options, cb) {
+ var cache, eng;
+ cache = options.cache != null ? options.cache : true;
+ eng = options.cache ? e : new engine({
+ prettyPrintErrors: true
+ });
+ return eng.run(filename, options, function(err, res) {
if (err) {
return cb(new Error(err));
} else {
@@ -25,6 +32,20 @@
});
};
+ exports.__consolidate_engine_render = function(filename, options, cb) {
+ if (!(options.cache != null)) {
+ options.cache = false;
+ }
+ return __express(filename, options, cb);
+ };
+
+ exports.str_render = function(template_str, options, cb) {
+ var err, res, v, _ref;
+ v = new view(template_str, options);
+ _ref = v.run(options), err = _ref[0], res = _ref[1];
+ return cb(err, res);
+ };
+
exports.compile = require('./lib/view').expressCompile;
}).call(this);
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "toffee",
"description": "A NodeJs, Express 3.x, Express 2.x, and browser-side templating language based on CoffeeScript with slicker tokens and syntax. Built with love at OkCupid.",
- "version": "0.0.51",
+ "version": "0.0.52",
"directories": {
"lib": "./lib"
},
Please sign in to comment.
Something went wrong with that request. Please try again.