Module: NdrUi::Bootstrap::LabelTooltips
- Included in:
- NdrUi::BootstrapBuilder
- Defined in:
- app/builders/ndr_ui/bootstrap/label_tooltips.rb
Overview
This extension adds I18n based tooltips to form labels.
Instance Method Summary collapse
-
#label(method, text = nil, **options, &block) ⇒ Object
Generates a form label tag and appends a question_tooltip if an appropriate translation is found in the locale file.
Instance Method Details
#label(method, text = nil, **options, &block) ⇒ Object
Generates a form label tag and appends a question_tooltip if an appropriate translation is found in the locale file. Tooltip translation can be overriden by passing the :tooltip option with the desired text.
The content for a label_tag is sourced from either the passed block, the passed text or the tag builder’s underlying translations, in that order. We inject our own block that recreates that same logic whilst tacking on our tooltip, so that form.label continues to work as one might expect from reading the documentation. See the source code for ActionView::Helpers::Tags::Label for more.
QUESTION: Parameterise the tooltip so we’re not just bound to a question_tooltip ?
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/builders/ndr_ui/bootstrap/label_tooltips.rb', line 16 def label(method, text = nil, **, &block) tooltip_text = .delete(:tooltip) super(method, text, ) do |builder| output = block ? block.call : text output ||= builder.translation tooltip = question_tooltip(method, tooltip_text) @template.safe_join([output, tooltip].compact, ' ') end end |