Haml filters using Rails helpers

128 views
Skip to first unread message

Evgeny

unread,
Jan 9, 2009, 12:23:03 PM1/9/09
to Haml
Hi,

I am trying to use a rails helper in a haml filter, is it possible somehow?

Something like this maybe:

module Haml::Filters::Javascript
  def render_with_options(text,options)
    content_for(:javascript) {
      text.rstrip.gsub("\n", "\n    ")
    }
  end
end

Would love for some help, since right now it errors with
undefined method `content_for' for Haml::Filters::Javascript:Module
which is understandable ... do I need to include some kind of rails module or something?

Nathan Weizenbaum

unread,
Jan 9, 2009, 5:14:10 PM1/9/09
to ha...@googlegroups.com
Filters are handled at compile time, so it's a little tricky to access the runtime ActionView context. You'll either need to override the #compile method and generate code calling the method, or create a new ActionView::Base instance and use that. I'd suggest looking at the Haml::Filters code for examples.
Reply all
Reply to author
Forward
0 new messages