Skip to content

Added ability to handle compile errors #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/haml.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,9 @@ var Haml;
eval("_$output =" + js );
return _$output; //set in eval
} catch (e) {
return "\n<pre class='error'>" + html_escape(e + "\n" + e.stack) + "</pre>\n";
var formatted = "\n<pre class='error'>" + html_escape(e + "\n" + e.stack) + "</pre>\n";
if (typeof self._err === 'function') return self._err(e,formatted);
return formatted;
}

}
Expand Down