Permalink
Browse files

v0.2.1 Minor speed tweak

`Haml()` now caches the eval step so that there is no eval in executing a compiled template.  This should make things a bit faster.
  • Loading branch information...
1 parent 8128768 commit e9d2b125024d3d53eaafa10e3d51fe416de85041 @creationix committed Apr 1, 2010
Showing with 15 additions and 11 deletions.
  1. +5 −1 CHANGELOG.markdown
  2. +9 −9 lib/haml.js
  3. +1 −1 package.json
View
@@ -1,6 +1,10 @@
# HAML-JS Changelog
-- **0.2.0** - *2010-03-31* - Function based API, Safe whitespace, Code interpolation.
+- **v0.2.1** - *2010-04-01* - Minor speed tweak
+
+ `Haml()` now caches the eval step so that there is no eval in executing a compiled template. This should make things a bit faster.
+
+- **v0.2.0** - *2010-03-31* - Function based API, Safe whitespace, Code interpolation.
At the request of some users, I've removed the new insertion into the generated html. This means that most html will be on one long line, but as an added advantage you won't have that extra whitespace next to your anchor labels messing up your visual display.
View
@@ -477,15 +477,15 @@ var Haml;
Haml = function (haml) {
var js = optimize(compile(haml));
- return function (locals) {
- with(locals || {}) {
- try {
- return eval("(" + js + ")");
- } catch (e) {
- return "\n<pre class='error'>" + html_escape(e.stack) + "</pre>\n";
- }
- }
- }
+ return new Function("locals",
+ html_escape + "\n" +
+ "with(locals || {}) {\n" +
+ " try {\n" +
+ " return (" + js + ");\n" +
+ " } catch (e) {\n" +
+ " return \"\\n<pre class='error'>\" + html_escape(e.stack) + \"</pre>\\n\";\n" +
+ " }\n" +
+ "}");
}
Haml.compile = compile;
Haml.optimize = optimize;
View
@@ -3,5 +3,5 @@
"description": "Haml ported to server-side Javascript. This is a traditional server-side templating language.",
"keywords": ["haml", "template", "nodejs"],
"author": "Tim Caswell",
- "version": "0.2.0"
+ "version": "0.2.1"
}

0 comments on commit e9d2b12

Please sign in to comment.