Skip to content
Myr

Hacking haml-js to work with locals and Express

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 39719af · Browse files · 4 files+7 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+7 added−7 removed

  • other:+7 added−7 removed

4 files+7 added−7 removed

modified:examples/app.js+1 added-1 removed
modified:lib/express/view.js+1 added-1 removed
modified:lib/support/ejs.js+1 added-1 removed
modified:lib/support/haml.js+4 added-4 removed
59 unmodified lines
60 }61 return JSON.stringify(json);62}63 64Haml.parse = function (text) {64Haml.parse = function (text, locals) {65 66 var empty_regex = new RegExp("^[ \t]*$"),67 indent_regex = new RegExp("^ *"),68 element_regex = new RegExp("^(?::[a-z]+|(?:[%][a-z][a-z0-9]*)?(?:[#.][a-z0-9_-]+)*)", "i"),
2 unmodified lines
71 72 // Sortof an instance_eval for Javascript73 function instance_eval(input) {74 var block;75 block = function () { with(scope) { return eval("(" + input + ")"); } };75 block = function () { with(scope, locals || {}) { return eval("(" + input + ")"); } };76 return block.call(scope);77 }78 79 function process_embedded_code(string) {
308 unmodified lines
388};389 390exports.render = function(content, options) {391 options = options || {}392 var json = Haml.parse.call(options.context || GLOBAL, content)393 p(json)392 var json = Haml.parse.call(options.context || GLOBAL, content, options.locals)393 return Haml.to_html(json).replace('\n\n', '\n')394}395