Skip to content
Browse files

exposed str_render function; added support for consolidate.js

  • Loading branch information...
1 parent 8ee89cf commit 0856d5fa3d711988cd0517d54f6c6fe954143297 @malgorithms committed Nov 6, 2012
Showing with 27 additions and 15 deletions.
  1. +11 −6 index.coffee
  2. +16 −9 index.js
View
17 index.coffee
@@ -10,20 +10,25 @@ exports.expressEngine = e
# a pretty name for general usage
exports.render = e.run
-# express 3.x support; by default, caching is on
+# express 3.x support;
__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) ->
+ e.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
+ if (options.cache?) and options.cache
+ eng = e
+ else
+ eng = new engine { verbose: false, prettyPrintErrors: true }
+ eng.run filename, options, (err, res) ->
+ if err
+ cb new Error(err)
+ else
+ cb null, res
# consolidate.js wants this, but it might generally be useful
exports.str_render = (template_str, options, cb) ->
View
25 index.js
@@ -18,12 +18,7 @@
exports.render = e.run;
__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) {
+ return e.run(filename, options, function(err, res) {
if (err) {
return cb(new Error(err));
} else {
@@ -33,10 +28,22 @@
};
exports.__consolidate_engine_render = function(filename, options, cb) {
- if (!(options.cache != null)) {
- options.cache = false;
+ var eng;
+ if ((options.cache != null) && options.cache) {
+ eng = e;
+ } else {
+ eng = new engine({
+ verbose: false,
+ prettyPrintErrors: true
+ });
}
- return __express(filename, options, cb);
+ return eng.run(filename, options, function(err, res) {
+ if (err) {
+ return cb(new Error(err));
+ } else {
+ return cb(null, res);
+ }
+ });
};
exports.str_render = function(template_str, options, cb) {

0 comments on commit 0856d5f

Please sign in to comment.
Something went wrong with that request. Please try again.