How would you implement the "tell don't ask" principle in HAML?
- by Enrique Ramírez Vélez
Here's the thing. I have a button that, depending on the scenario, will behave, look and have different text. Here's how it, roughly, looks like at the moment:
- if params[:param_A] && @statement_A
%span.button.cancel_button{attribute: "value_B"}
- if @statement_B
= t('locale_A')
- else
= t('locale_B')
- elsif params[:param_A]
%span.button.cancel_button{attribute: "value_A"}
- if @statement_B
= t('locale_A')
- else
= t('locale_B')
There's also a CSS class both buttons should have IF statement_B is true.
So it is a mess. And I recently read about the "Tell, don't ask" principle which I liked very much, so I'd love to apply it here... but I'm not sure how.
I know I could make a helper, but I'd like to stay away from them because reasons (I really have some valid reasons to do so, but those are beyond the scope of this question). I can resort to that as a last resource, but would rather find another solution.