Defining a class inside a .haml file and then using haml_tag, haml_concat from it?

109 views
Skip to first unread message

Fraser Murray

unread,
May 20, 2012, 11:49:29 AM5/20/12
to ha...@googlegroups.com
I'm defining a class within Haml, and I'd like to be able to use the Haml helpers within this class. For example:
- class Whatever
   - def self.write
     - haml_concat "something"

- Whatever.write

Ideally, Whatever.write would output "something" to the template, but it simply fails with undefined method 'haml_concat' for Haml::Engine::Whatever:Class.

Full stacktrace: haml_test.haml:5:in `write': undefined method `haml_concat' for Haml::Engine::Whatever:Class (NoMethodError)
from haml_test.haml:8:in `block in render'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/engine.rb:191:in `eval'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/engine.rb:191:in `render'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:281:in `process_result'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:41:in `parse'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/lib/haml/exec.rb:21:in `parse!'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/gems/haml-3.1.4/bin/haml:9:in `<top (required)>'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/bin/haml:19:in `load'
from /home/fraser/.rvm/gems/ruby-1.9.3-p125/bin/haml:19:in `<main>'



How can I get this to work properly? I've tried using both extend and include Haml::Helpers, but they both fail too. Any ideas?
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages