Showing posts with label Haml. Show all posts
Showing posts with label Haml. Show all posts

Monday, April 6, 2015

Removing extra whitespace from Haml

Most of the time, Haml is pretty awesome. One of the cases where it's not so awesome is around multiline mixed Ruby/HTML. For example, when trying to create a timer on the screen:

Because of reasons, Haml decides to add extra whitespace around each of the span tags. Sometimes this is desirable, but sometimes you want to remove the whitespace/extra space around Haml tags. As usual, there is a quick fix, in this case the '>' character:

Monday, March 23, 2015

undefined method `capture_haml' for RSpec

If you're using Haml in a Rails project, testing with RSpec, you might encounter the "undefined method 'capture_haml' for ..." error while trying to run your specs. I encountered this error in a view spec when trying to use Simple Form along with Haml. Fortunately, like many other obscure bugs there is a quick and dirty solution: The init_haml_helpers section is necessary to prevent other errors from happening.

Note that all lines are required. If you drop the init_haml_helpers line, you'll get the following error:
ActionView::Template::Error: undefined method `capture_position=' for nil:NilClass
and of course if you don't have any of this, you will get:
ActionView::Template::Error: undefined method `capture_haml' for #<RSpec::ExampleGroups::...