Module: StandardView::BadgeHelper
- Defined in:
- app/helpers/standard_view/badge_helper.rb
Instance Method Summary collapse
- #badge(content, type: "dark", right: false, pill: false, extra_class: nil, **options) ⇒ Object
- #boolean_badge(is, **options) ⇒ Object
- #count_badge(value, type: "dark", extra_class: "ml-1", **options) ⇒ Object
- #unread_badge(value, **options) ⇒ Object
Instance Method Details
#badge(content, type: "dark", right: false, pill: false, extra_class: nil, **options) ⇒ Object
3 4 5 6 |
# File 'app/helpers/standard_view/badge_helper.rb', line 3 def badge(content, type: "dark", right: false, pill: false, extra_class: nil, **) extra = "#{"badge-pill" if pill} #{"float-right mt-1 ml-2" if right} #{extra_class}" content_tag :span, content, class: "badge badge-#{type} #{extra}", ** end |
#boolean_badge(is, **options) ⇒ Object
18 19 20 |
# File 'app/helpers/standard_view/badge_helper.rb', line 18 def boolean_badge(is, **) badge t(is ? "common.on" : "common.off"), type: is ? "success" : "danger", ** end |
#count_badge(value, type: "dark", extra_class: "ml-1", **options) ⇒ Object
8 9 10 11 12 |
# File 'app/helpers/standard_view/badge_helper.rb', line 8 def count_badge(value, type: "dark", extra_class: "ml-1", **) number = value.respond_to?(:count) ? value.count : value badge_type = block_given? ? yield(number) : type badge number_with_delimiter(number), type: badge_type, extra_class: extra_class, ** end |
#unread_badge(value, **options) ⇒ Object
14 15 16 |
# File 'app/helpers/standard_view/badge_helper.rb', line 14 def unread_badge(value, **) count_badge(value, **) { |number| number.zero? ? "dark" : "danger" } end |