Class: Felt::Help
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Felt::Help
- Defined in:
- lib/help.rb
Overview
Renders a help element for a form input.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#classes ⇒ Object
Returns the classes to use for the help element.
-
#initialize(attribute:, form:, classes: nil, text: nil, **options) ⇒ Help
constructor
-
classes: Classes to add to the help element.
-
- #render? ⇒ Boolean
-
#text ⇒ Object
Returns the text to render in the help.
-
#text? ⇒ Boolean
Returns true if the input group has a help text configured.
Constructor Details
#initialize(attribute:, form:, classes: nil, text: nil, **options) ⇒ Help
-
classes: Classes to add to the help element.
-
text: The help text to show. If not provided, the text will be looked up in the ‘forms.<object_name>.<attribute>` translation. See #help for more details. To disable the help, pass an empty string.
All remaining keyword arguments are passed to the help element. See ActionView::Helpers::FormBuilder#help for details.
24 25 26 27 28 29 30 |
# File 'lib/help.rb', line 24 def initialize(attribute:, form:, classes: nil, text: nil, **) @attribute = attribute @classes = classes @form = form @text = text @options = end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
8 9 10 |
# File 'lib/help.rb', line 8 def attribute @attribute end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
8 9 10 |
# File 'lib/help.rb', line 8 def form @form end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/help.rb', line 8 def @options end |
Instance Method Details
#classes ⇒ Object
Returns the classes to use for the help element
11 12 13 14 |
# File 'lib/help.rb', line 11 def classes @classes || Felt.configuration.classes.dig(:help, :default, :default) end |
#render? ⇒ Boolean
32 33 34 |
# File 'lib/help.rb', line 32 def render? text.present? end |
#text ⇒ Object
Returns the text to render in the help. If no text is configured, returns nil.
Help texts are looked up in the following order:
-
The text argument passed to the component.
-
The ‘help` key in the `forms.<object_name>.<attribute>` translation.
-
The translation value found under ‘helpers.help.<modelname>.<attribute>` (like with ActionView::Helpers::FormBuilder#help).
46 47 48 |
# File 'lib/help.rb', line 46 def text @text ||= translate("help") end |
#text? ⇒ Boolean
Returns true if the input group has a help text configured
51 52 53 |
# File 'lib/help.rb', line 51 def text? text.present? end |