Module: TitleHelper
- Included in:
- ScavengerHunt::ApplicationHelper
- Defined in:
- app/helpers/title_helper.rb
Instance Method Summary collapse
-
#title_for(options = {}) ⇒ Object
Returns a title tag if a 'title' option is present.
Instance Method Details
#title_for(options = {}) ⇒ Object
Returns a title tag if a 'title' option is present. Also modifies options to point to the title tag as `aria-labelledby`.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/title_helper.rb', line 4 def title_for( = {}) title = .delete(:title) return "".html_safe unless title.present? case title when Hash = title title = title[:text] when String = {} end tag = .fetch(:tag, :h2) sr_only = .key?(:sr_only) ? .delete(:sr_only) : true id = id_for(title) # Update the options hash so that subsequent uses include the label (, aria: { labelledby: id }) # Configure the title tag = (, { class: sr_only ? 'sr-only' : nil, id: id }) content_tag(tag, ) { title } end |