creationix / haml-js

Haml ported to server-side Javascript. This is a traditional server-side templating language. Tested with node-js
MIT License
902 stars 110 forks source link

Fixed escaper initialization issue #50

Open ilich opened 12 years ago

ilich commented 12 years ago

Hi Tim,

Thank you for the great project. It is really useful and saved me a lot of time.

Yesterday I found an issue with Haml.render function. For example, if you have a document: !!! %html %head $title&= title

Then you tries to call Haml.render(doc, { locals: { title: "The test" } }); The call fails with the error of undefined function.

The issue is &= title converted to undefined(title) call what is wrong. I modified the code to initialize escaper function in the render method as well. It has been initialized only in Haml(haml, config) function before.

The second change was to fix how you process end of line characters on Windows. Unit had tests because they expected to have \r\n in a rendered content but there were just \n or \n\n. I fixed the issue: if the platform is Windows then use \r\n otherwise just \n.

I also added a possibility to run only selected tests. For example, node tests.js comments.haml.

I changed deprecated module 'sys' with 'utils' in the tests.js

Please let me know if you have questions or concerns. Otherwise please merge them to the main branch.

Best regards, Ilya

ilich commented 12 years ago

I've created a fix for a web-browser. Please, retest.