Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Haml to stop from evaluating #{var} values inside <pre> <code> tags?

I'm using CodeRay and Haml to do syntax highlighting on some pages, and I write a lot of Ruby code. The problem is when I have something like this:

%pre
  %code.language-ruby
    :preserve
      def hello(name)
        puts "Hello #{name}!" 
      end

I keep getting errors because Haml keeps trying to evaluate the name variable inside the string, the #{var} syntax is a pretty common idiom in Ruby code and there aremany places where it is used, but I cannot use syntax highlighting of those codes because Haml wants to evaluate those variables inside the string.

Is there a way to tell Haml to not do that in some places?

like image 271
Phrozen Avatar asked Mar 26 '12 23:03

Phrozen


1 Answers

Is there a way to tell Haml to not do that in some places?

By escaping the #:

puts "Hello \#{name}!" 
like image 55
meagar Avatar answered Sep 18 '22 14:09

meagar