diff --git a/index.coffee b/index.coffee index 4e04d3d..eb4ccb6 100644 --- a/index.coffee +++ b/index.coffee @@ -9,7 +9,12 @@ exports.expressEngine = e exports.render = e.run # express 3.x support -exports.__express = e.run +exports.__express = (filename, options, cb) -> + e.run filename, options, (err, res) -> + if err + cb new Error(err) + else + cb null, res # express 2.x support exports.compile = require('./lib/view').expressCompile \ No newline at end of file diff --git a/index.js b/index.js index f509006..d26a889 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,15 @@ exports.render = e.run; - exports.__express = e.run; + exports.__express = function(filename, options, cb) { + return e.run(filename, options, function(err, res) { + if (err) { + return cb(new Error(err)); + } else { + return cb(null, res); + } + }); + }; exports.compile = require('./lib/view').expressCompile; diff --git a/lib/engine.js b/lib/engine.js index 6f64e11..a27be2b 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -31,6 +31,7 @@ this.verbose = options.verbose || false; this.minimize = options.minimize || false; this.prettyPrintErrors = options.prettyPrintErrors != null ? options.prettyPrintErrors : true; + this.prettyLogErrors = options.prettyLogErrors != null ? options.prettyLogErrors : true; this.viewCache = {}; this.fsErrorCache = {}; } @@ -61,6 +62,12 @@ */ var err, k, layout_options, res, v, _ref1, _ref2, _ref3, _ref4; + if (!(options.prettyPrintErrors != null)) { + options.prettyPrintErrors = this.prettyPrintErrors; + } + if (!(options.prettyLogErrors != null)) { + options.prettyLogErrors = this.prettyLogErrors; + } if (options != null ? options.layout : void 0) { layout_options = {}; for (k in options) { @@ -197,6 +204,7 @@ fileName: filename, verbose: this.verbose, prettyPrintErrors: this.prettyPrintErrors, + prettyLogErrors: this.prettyLogErrors, minimize: this.minimize }; v = new view(txt, view_options); diff --git a/lib/errorHandler.js b/lib/errorHandler.js index e03ce87..896359a 100644 --- a/lib/errorHandler.js +++ b/lib/errorHandler.js @@ -99,7 +99,7 @@ _results = []; for (i = _i = 0, _len = stack.length; _i < _len; i = ++_i) { line = stack[i]; - rxx_pub = /Object[\.]pub[\s]\(undefined\:([0-9]+)\:[0-9]+/; + rxx_pub = /Object[\.].*?pub[\s]\(undefined\:([0-9]+)\:[0-9]+|tmpl[\.]render[\.]tmpl[\.]pub.*\(undefined\:([0-9]+)\:[0-9]+/; m = line.match(rxx_pub); in_src_file = false; lrange = [null, null]; diff --git a/lib/view.js b/lib/view.js index 1f9e966..c73b3f0 100644 --- a/lib/view.js +++ b/lib/view.js @@ -82,6 +82,7 @@ this.verbose = options.verbose || false; this.fsError = options.fsError || false; this.prettyPrintErrors = options.prettyPrintErrors != null ? options.prettyPrintErrors : true; + this.prettyLogErrors = options.prettyLogErrors != null ? options.prettyLogErrors : false; this.txt = txt; this.tokenObj = null; this.coffeeScript = null; @@ -154,7 +155,7 @@ returns [err, str] */ - var pair, res, sandbox, script; + var line, pair, res, sandbox, script, txt, _i, _len, _ref2; script = this._toScriptObj(); res = null; if (!this.error) { @@ -170,10 +171,19 @@ } } if (this.error) { + console.log("PRETTY LOG ERRORS: " + this.prettyLogErrors); + if (this.prettyLogErrors) { + txt = this.error.getPrettyPrintText(); + _ref2 = txt.split("\n"); + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + line = _ref2[_i]; + console.log("toffee err: " + line); + } + } if (this.prettyPrintErrors) { pair = [null, this.error.getPrettyPrint()]; } else { - pair = [null, this.error.getPrettyPrintText()]; + pair = [this.error.getPrettyPrintText(), null]; } if (this.error.errType === errorTypes.RUNTIME) { this.error = null; diff --git a/package.json b/package.json index 4d56d77..d9f8b38 100644 --- a/package.json +++ b/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.48", + "version": "0.0.49", "directories": { "lib": "./lib" }, diff --git a/src/engine.coffee b/src/engine.coffee index cc94e30..92f9b82 100644 --- a/src/engine.coffee +++ b/src/engine.coffee @@ -11,7 +11,10 @@ class engine options = options or {} @verbose = options.verbose or false @minimize = options.minimize or false + @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true + @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else true + @viewCache = {} # filename -> view @fsErrorCache = {} # filename -> timestamp last failed @@ -34,6 +37,9 @@ class engine __toffee.autoEscape: if set as false, don't escape output of #{} vars by default ### + if not options.prettyPrintErrors? then options.prettyPrintErrors = @prettyPrintErrors + if not options.prettyLogErrors? then options.prettyLogErrors = @prettyLogErrors + if options?.layout layout_options = {} layout_options[k] = v for k,v of options when k isnt "layout" @@ -41,7 +47,7 @@ class engine [err, res] = @runSync filename, options # if we got an error but want to pretty-print by faking ok result - if err and @prettyPrintErrors + if err and @prettyPrintErrors [err, res] = [null, err] # if we're using a layout, pub into that @@ -141,6 +147,7 @@ class engine fileName: filename verbose: @verbose prettyPrintErrors: @prettyPrintErrors + prettyLogErrors: @prettyLogErrors minimize: @minimize v = new view txt, view_options @viewCache[filename] = v diff --git a/src/errorHandler.coffee b/src/errorHandler.coffee index c86835a..0d4e962 100644 --- a/src/errorHandler.coffee +++ b/src/errorHandler.coffee @@ -78,7 +78,11 @@ class toffeeError stack = converted_err.stack for line, i in stack - rxx_pub = /// Object[\.]pub[\s]\(undefined\:([0-9]+)\:[0-9]+ /// + rxx_pub = /// + Object[\.].*?pub[\s]\(undefined\:([0-9]+)\:[0-9]+ + | + tmpl[\.]render[\.]tmpl[\.]pub.*\(undefined\:([0-9]+)\:[0-9]+ + /// m = line.match rxx_pub in_src_file = false lrange = [null, null] diff --git a/src/view.coffee b/src/view.coffee index 52fbddc..925cfae 100644 --- a/src/view.coffee +++ b/src/view.coffee @@ -159,6 +159,7 @@ class view @verbose = options.verbose or false @fsError = options.fsError or false # pass true if you could not load the view template and passed in error text @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true + @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else false @txt = txt @tokenObj = null # constructed as needed @coffeeScript = null # constructed as needed @@ -222,10 +223,14 @@ class view @error = new toffeeError @, errorTypes.RUNTIME, e if @error + if @prettyLogErrors + txt = @error.getPrettyPrintText() + for line in txt.split "\n" + console.log "toffee err: #{line}" if @prettyPrintErrors pair = [null, @error.getPrettyPrint()] else - pair = [null, @error.getPrettyPrintText()] + pair = [@error.getPrettyPrintText(), null] if @error.errType is errorTypes.RUNTIME # don't hold onto runtime errors after value returned. @error = null