From 5becfc494751f32eb5c2be375cd9ce5f02165bbd Mon Sep 17 00:00:00 2001 From: Mathew Dixon Date: Tue, 11 Jul 2017 19:31:59 +1000 Subject: [PATCH] Added ability to handle compile errors in the template haml and documented accordingly. --- README.markdown | 2 ++ lib/haml.js | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index f16c951..02c3fd1 100644 --- a/README.markdown +++ b/README.markdown @@ -98,6 +98,8 @@ Notice how congruent static strings are merged into a single string literal when Context is the value of `this` in the template, and locals is a hash of local variables. +If `context._err` is a function it will be called with `context._err(error, formatted_error_string)` instead of returning the default formatted error string. + ### Haml.render(text, options) -> html text This is a convenience function that compiles and executes to html in one shot. Most casual users will want to use this function exclusively. diff --git a/lib/haml.js b/lib/haml.js index b726905..afd65f1 100755 --- a/lib/haml.js +++ b/lib/haml.js @@ -652,7 +652,9 @@ var Haml; eval("_$output =" + js ); return _$output; //set in eval } catch (e) { - return "\n
" + html_escape(e + "\n" + e.stack) + "
\n"; + var formatted = "\n
" + html_escape(e + "\n" + e.stack) + "
\n"; + if (typeof self._err === 'function') return self._err(e,formatted); + return formatted; } }