0
= Frequently Asked Questions
0
+=== How do I put a punctuation mark after an element, like "<tt>I like <strong>cake</strong>!</tt>"?
0
+Expressing the structure of a document
0
+and expressing inline formatting are two very different problems.
0
+Haml is mostly designed for structure,
0
+so the best way to deal with formatting is to leave it to other languages
0
+that are designed for it.
0
+ %p I like <strong>cake</strong>!
0
+If you're inserting something that's generated by a helper, like a link,
0
+ %p== I like #{link_to 'chocolate', 'http://franschocolates.com'}!
0
+=== How do I stop Haml from indenting the contents of my +pre+ and +textarea+ tags?
0
+Because Haml automatically indents the HTML source code,
0
+the contents of whitespace-sensitive tags like +pre+ and +textarea+
0
+The solution is to replace the newlines inside these tags
0
+with HTML newline entities (<tt>
</tt>),
0
+which Haml does using the Haml::Helpers#preserve and Haml::Helpers#find_and_preserve helpers.
0
+Normally, Haml will do this for you automatically
0
+when you're using a tag that needs it
0
+(this can be customized using the <tt>:preserve</tt> option;
0
+see the Options section of the {Haml reference}(../classes/Haml.html)).
0
+ <textarea>Foo
Bar</textarea>
0
+However, if a helper is generating the tag,
0
+Haml can't detect that and so you'll have to call +find_and_preserve+ yourself.
0
+You can also use <tt>~</tt>, which is the same as <tt>=</tt>
0
+except that it automatically runs +find_and_preserve+ on its input.
0
+ %p= find_and_preserve "<textarea>Foo\nBar</textarea>"
0
+ %p~ "<textarea>Foo\nBar</textarea>"
0
+ <p><textarea>Foo
Bar</textarea></p>
0
+=== I have Haml installed. Why is Rails (only looking for <tt>.html.erb</tt> files | rendering Haml files as plain text | rendering Haml files as blank pages)?
0
+There are several reasons these things might be happening.
0
+First of all, make sure vendor/plugins/haml really exists
0
+and has an init.rb file in there.
0
+Then try restarting Mongrel or WEBrick or whatever you might be using.
0
+Finally, if none of these work,
0
+chances are you've got some localization plugin like Globalize installed.
0
+Such plugins often don't play nicely with Haml.
0
+Luckily, there's usually an easy fix.
0
+For Globalize, just edit globalize/lib/globalize/rails/action_view.rb
0
+ @@re_extension = /\.(rjs|rhtml|rxml)$/
0
+ @@re_extension = /\.(rjs|rhtml|rxml|erb|builder|haml)$/
0
+For other plugins, a little searching will probably turn up a way to fix them as well.
0
+=== Can I use a variable from my controller in my Sass file?
0
+No. Sass files aren't views.
0
+They're compiled once into static CSS files,
0
+then left along until they're changed and need to be compiled again.
0
+Not only don't you want to be running a full request cycle
0
+every time someone requests a stylesheet,
0
+but it's not a great idea to put much logic in there anyway
0
+due to how browsers handle them.
0
+If you really need some sort of dynamic CSS,
0
+the best thing to do is put only the snippet you need to dynamically set
0
+in the +head+ of your HTML document.
0
== You still haven't answered my question!
0
Sorry! Try looking at the Haml or Sass references,
Comments
No one has commented yet.