最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Any client side haml parser? - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 8

After 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>
发布评论

评论列表(0)

  1. 暂无评论