Module: Anchor::DescribableInput
- Included in:
- CheckBoxComponent, RadioButtonComponent
- Defined in:
- app/components/anchor/describable_input.rb
Instance Method Summary collapse
- #aria_description ⇒ Object
- #description ⇒ Object
- #description_id ⇒ Object
- #description_text ⇒ Object
- #description_translation_html_scope ⇒ Object
- #description_translation_scope ⇒ Object
- #human_attribute_description ⇒ Object
- #human_attribute_html_description ⇒ Object
- #i18n_model_key ⇒ Object
Instance Method Details
#aria_description ⇒ Object
3 4 5 |
# File 'app/components/anchor/describable_input.rb', line 3 def aria_description { describedby: description_id } end |
#description ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/anchor/describable_input.rb', line 7 def description if object.is_a?(Hash) object[:description] elsif object.respond_to?(:description) object.description elsif I18n.exists?(description_translation_html_scope) human_attribute_html_description elsif I18n.exists?(description_translation_scope) human_attribute_description else false end end |
#description_id ⇒ Object
21 22 23 |
# File 'app/components/anchor/describable_input.rb', line 21 def description_id "#{attribute}-#{value}-description" end |
#description_text ⇒ Object
25 26 27 |
# File 'app/components/anchor/describable_input.rb', line 25 def description_text human_attribute_description end |
#description_translation_html_scope ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/components/anchor/describable_input.rb', line 29 def description_translation_html_scope [ "activerecord.values", i18n_model_key, "#{description_id.gsub('-', '.')}_html", ] end |
#description_translation_scope ⇒ Object
37 38 39 |
# File 'app/components/anchor/describable_input.rb', line 37 def description_translation_scope ["activerecord.values", i18n_model_key, description_id.gsub("-", ".")] end |
#human_attribute_description ⇒ Object
45 46 47 |
# File 'app/components/anchor/describable_input.rb', line 45 def human_attribute_description I18n.t description_translation_scope.join(".") end |
#human_attribute_html_description ⇒ Object
41 42 43 |
# File 'app/components/anchor/describable_input.rb', line 41 def human_attribute_html_description I18n.t(description_translation_html_scope.join(".")).html_safe end |
#i18n_model_key ⇒ Object
49 50 51 52 53 |
# File 'app/components/anchor/describable_input.rb', line 49 def i18n_model_key if (form_object = form_builder.object) form_object.class.model_name.i18n_key end end |