haml/haml — pull request #801 by Iazel (2014-09-15 03:33:46+00:00)
Title: Blocks become more useful

HAML (and all the other template manager I've seen) have a big lack: blocks. Using a block should be more straightforward, and as a user, given this context:
```ruby
class Context
def em
'#{yield}'
end
end
```

I expect this code:
```haml
Hello
= em do
World
!!
```

To produce something like:
```html
Hello
World
!!
```

And not:
```html
Hello
World
Hello
World
!!
```

Yes, I know, for case like this we can use `capture_haml`, but this approach is really bad and cause a lot of issues. For example, if I use a [ViewModel](https://github.com/apotonick/cells) and want to use some pretty nice rails gem like `simple_form_for`, the only way is to clobber the actual context with all the method needed. However, if blocks work as expected, I could use the main `ActionView` object just like an helper container.
This is just some case, but I'm sure fixing this will give a lot more flexibility, plus I can't imagine a method that needs a block but doesn't use its content.

Hence, I've made this patch. If you like it, we could also *eradicate* a lot of helper method that become futile, and replace all the `capture_haml` with just a `yield` and `=`. I think this should also speed up the compiled code.

**There's only 2 test that I've skipped because I don't think they are really useful and it's quite hard to green them maintaining the same HAML source** (the same result can be achieved with a small modification of it).

Hope you find this as useful as I do :)