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

Making Haml.js work on the client-side #38

Closed wintondeshong closed 13 years ago

wintondeshong commented 13 years ago

Recently my team decided to use Haml for our templates on the client-side. Out of the box the Haml.js library works for non-ie browsers, but of course we must support Internet Explorer. I was able to make a version for my team's purposes that uses underscore.js as a dependency. If I get some extra time I'll fork and make a version that doesn't depend on underscore.js. If someone else happens to get around to it before I do, below is a list of the exact changes that need to take place to get the current version of Haml.js to play nicely with IE.

  1. The primary signature for Haml needs to be "Haml = function(haml, config) {", not "Haml = function Haml(haml, config) {"
  2. Replace String.trim()
  3. Replace Array.forEach, Array.filter, Array.indexOf, and Array.map

Thanks

aaronblohowiak commented 13 years ago

Why are you running the compiler on the client side instead of precompiling your templates on the server-side ? If you pre-compile the templates on the server side then you should have faster startup times in the client and won't have to include the entire compiler in your application's js file. The compiled templates should run everywhere.

HOWEVER! If your fork works without altering the base objects (String, Array) then I'll gladly merge it in.

Please let me know if you have any issues or questions -- don't hesitate to send me a message here or drop me an email aaron.blohowiak@gmail.com

aaronblohowiak commented 13 years ago

If you put up your version that uses underscore.js then it should be pretty easy to have a local-to-Haml _ var that contains just the offending functions.

wintondeshong commented 13 years ago

Given the working arrangement with one of our clients we found it easiest to provide the Haml inline in the page. We are building the client-side of a single-page javascript web application. Building the application this way... we are able to deliver a nice package of Mocked Async requests, QUnit tests, and Haml templates for them to implement however they choose on the server.

I realize this is not the most performant option, but for our purposes it is an easy way to full-fill the build of the client-side of this particular application. I'll put up my version with the underscore.js dependency momentarily.

Thank you for your help and timely response.

aaronblohowiak commented 13 years ago

I'm going to talk with Creationix about this before merging the underscore-based version into master, will track the updates on issue #39.