Module: RailsPulse::TagsHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/rails_pulse/tags_helper.rb
Instance Method Summary collapse
-
#display_tag_badges(tags) ⇒ Object
Display tags as badge elements Accepts: - Taggable objects (with tag_list method) - Raw JSON strings from aggregated queries - Arrays of tags.
Instance Method Details
#display_tag_badges(tags) ⇒ Object
Display tags as badge elements Accepts:
-
Taggable objects (with tag_list method)
-
Raw JSON strings from aggregated queries
-
Arrays of tags
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/rails_pulse/tags_helper.rb', line 8 def display_tag_badges() tag_array = case when String # Parse JSON string from database begin JSON.parse() rescue JSON::ParserError [] end when Array else # Handle Taggable objects .respond_to?(:tag_list) ? .tag_list : [] end return content_tag(:span, "-", class: "text-subtle") if tag_array.empty? safe_join(tag_array.map { |tag| content_tag(:div, tag, class: "badge") }, " ") end |