0.04
Repository is archived
No commit activity in last 3 years
No release in over 3 years
CoffeeFilter is a custom haml filter for rendering coffeescript inside your haml templates. It was inspired by Ivan Nemytchenko's coffee-haml-filter but I wanted an installable gem and coffeescript as the filter name.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 4.0
 Project Readme

For Haml < 4.0¶ ↑

Haml >= 4.0 includes built-in support for coffeescript.

What is coffee-filter?¶ ↑

Coffee-filter provides a custom haml filter allowing you to inline coffeescript in your haml templates. It was inspired by Ivan Nemytchenko’s coffee-haml-filter but I wanted an installable gem and “coffeescript” as the filter name.

Example¶ ↑

Haml:

%div
  stuff
  :coffeescript
    alert 'here'

Html:

<div>
  stuff
  <script type='text/javascript'>
    //<![CDATA[
      (function() {
    alert('here');
  }).call(this);

    //]]>
  </script>
</div>

Installation¶ ↑

Add the following to your Gemfile:

gem 'coffee-filter'

Caveats¶ ↑

Using Ruby interpolation within the :coffeescript block will prevent Haml from caching the result of compilation. This means that your coffeescript block will be compiled by the coffeescript engine on runtime during every request, which is something you’ll definitely want to avoid (since it’s orders of magnitude slower).

In other words, using constructs similar to this:

:coffeescript
  @server_time = #{Time.now.to_i}

will cost you around 100ms on each request. Either use the :javascript filter for this, or embed the dynamic content in some other way in the DOM.

Copyright © 2011 Paul Nicholson, released under the MIT license