I have a line of HAML:
%button.navbar-toggle.collapsed{ type: :button, 'data-toggle' => :collapse, 'data-target' => "#bs-example-navbar-collapse-1" }
that is quite ugly. I'd like to be able to just pass everything between the brackets as a ruby variable to simplify it.
Is there a way to do that? i.e. I'd rather have:
%button.navbar-toggle.collapsed{ options_hash }
If you are concerned about the 1.8 syntax (those ugly hashrockets), you could do something like this:
%button.navbar-toggle.collapsed{ type: :button, data: { toggle: :collapse, target: "#bs-example-navbar-collapse-1" } }
That's at least a bit better, right? Or you could even try this which also looks better than the old hash syntax:
%button.navbar-toggle.collapsed(type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1")
But that's not what you asked. Yeah, it's possible. Have you tried? I'm not entirely sure why you would want to do this, but this should be possible:
- options_hash = { type: :button, data: { toggle: :collapse, target: "#bs-example-navbar-collapse-1" } }
%button.navbar-toggle.collapsed{ options_hash }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With