How would you implement the "tell don't ask" principle in HAML?
Posted
by
Enrique Ramírez Vélez
on Stack Overflow
See other posts from Stack Overflow
or by Enrique Ramírez Vélez
Published on 2012-10-03T21:35:58Z
Indexed on
2012/10/03
21:37 UTC
Read the original article
Hit count: 267
haml
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.
© Stack Overflow or respective owner