Appease the dog overlords

This commit is contained in:
Andreas Nedbal 2023-01-04 17:22:06 +01:00 committed by Andreas Nedbal
parent 0e97c7c80a
commit c9b39ad1e5
1 changed files with 23 additions and 18 deletions

View File

@ -1,10 +1,12 @@
# frozen_string_literal: true
module BootstrapHelper module BootstrapHelper
def nav_entry(body, path, options = {}) def nav_entry(body, path, options = {})
options = { options = {
badge: nil, badge: nil,
badge_color: nil, badge_color: nil,
icon: nil, icon: nil,
class: '' class: ""
}.merge(options) }.merge(options)
classes = [ classes = [
@ -14,16 +16,19 @@ module BootstrapHelper
].compact.join(" ") ].compact.join(" ")
unless options[:icon].nil? unless options[:icon].nil?
if options[:icon_only] body = if options[:icon_only]
body = "#{content_tag(:i, '', class: "fa fa-#{options[:icon]}", title: body)}" content_tag(:i, "", class: "fa fa-#{options[:icon]}", title: body).to_s
else else
body = "#{content_tag(:i, '', class: "fa fa-#{options[:icon]}")} #{body}" "#{content_tag(:i, '', class: "fa fa-#{options[:icon]}")} #{body}"
end end
end end
unless options[:badge].nil? unless options[:badge].nil?
badge_class = "badge" badge_class = [
badge_class << " badge-#{options[:badge_color]}" unless options[:badge_color].nil? "badge",
badge_class << " badge-pill" if options[:badge_pill] ("badge-#{options[:badge_color]}" unless options[:badge_color].nil?),
("badge-pill" if options[:badge_pill])
].compact.join(" ")
body += " #{content_tag(:span, options[:badge], class: badge_class)}" body += " #{content_tag(:span, options[:badge], class: badge_class)}"
end end
@ -32,9 +37,9 @@ module BootstrapHelper
def list_group_item(body, path, options = {}) def list_group_item(body, path, options = {})
options = { options = {
badge: nil, badge: nil,
badge_color: nil, badge_color: nil,
class: '' class: ""
}.merge(options) }.merge(options)
classes = [ classes = [
@ -44,19 +49,19 @@ module BootstrapHelper
options[:class] options[:class]
].compact.join(" ") ].compact.join(" ")
unless options[:badge].nil? or options[:badge] == 0 unless options[:badge].nil? || (options[:badge]).zero?
# TODO: make this prettier? # TODO: make this prettier?
body << " #{ body << " #{
content_tag(:span, options[:badge], class: ("badge#{ content_tag(:span, options[:badge], class: "badge#{
" badge-#{options[:badge_color]}" unless options[:badge_color].nil? " badge-#{options[:badge_color]}" unless options[:badge_color].nil?
}"))}" }")}"
end end
content_tag(:a, body.html_safe, href: path, class: classes) content_tag(:a, body.html_safe, href: path, class: classes)
end end
def tooltip(body, tooltip_content, placement = "bottom") def tooltip(body, tooltip_content, placement = "bottom")
content_tag(:span, body, {title: tooltip_content, "data-bs-toggle" => "tooltip", "data-bs-placement" => placement} ) content_tag(:span, body, { :title => tooltip_content, "data-bs-toggle" => "tooltip", "data-bs-placement" => placement })
end end
def time_tooltip(subject, placement = "bottom") def time_tooltip(subject, placement = "bottom")
@ -69,7 +74,7 @@ module BootstrapHelper
## ##
# #
def bootstrap_color c def bootstrap_color(c)
case c case c
when "error", "alert" when "error", "alert"
"danger" "danger"