I'm looking to render my haml code in client side using JavaScript. There are nice haml parsers in server side like Jade or haml.js but I don't know any haml parser/decoder in client side.
Update: Jade that is pretty much haml now supports client side.
I'm looking to render my haml code in client side using JavaScript. There are nice haml parsers in server side like Jade or haml.js but I don't know any haml parser/decoder in client side.
Update: Jade that is pretty much haml now supports client side.
Share Improve this question edited Jun 21, 2012 at 21:39 Mohsen asked Dec 12, 2011 at 23:03 MohsenMohsen 65.9k36 gold badges164 silver badges187 bronze badges 1- 1 found jquery-haml - not really haml but pretty close – froderik Commented Dec 13, 2011 at 13:58
1 Answer
Reset to default 8After some googling I found the "client-side-haml-js" github project. Looks like it should meet your needs:
The clientside-haml-js is a piler written in CoffeeScript that piles text templates in HAML format into Javascript functions that generate HTML. It has been inspired by the server side haml Javascript project, and has been written to be feature patible with Ruby server side HAML, supports all major browsers (IE 7+, Firefox 3.6+, Chrome 10+, Safari), have minimal runtime dependencies (only underscore.js, underscore.string and CoffeeScript if using CoffeeScript in your templates).
NOTE: The haml piler requires a browser with a JSON parser. For browsers like IE7, you need to also include a JSON implementation. See http://www.json/ for more details. A JSON implementation is available at https://github./douglascrockford/JSON-js.
Example from their github page:
var fn = haml.pileStringToJs("%h1\n %div\n %p\n %span");
var html = fn();
Looks like it also supports a text/haml-template method similar to jquery-templates:
<script type="text/haml-template" id="simple">
%h1
%div
%p
%span
</script>
<script type="text/javascript">
var fn = haml.pileHaml('simple');
var html = fn();
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744804286a4594680.html
评论列表(0条)