Module: BadgesHelper
- Defined in:
- app/helpers/badges_helper.rb
Instance Method Summary collapse
-
#gl_badge_tag(*args, &block) ⇒ Object
Creates a GitLab UI badge.
Instance Method Details
#gl_badge_tag(*args, &block) ⇒ Object
Creates a GitLab UI badge.
Examples:
# Plain text badge
gl_badge_tag("foo")
# Danger variant
gl_badge_tag("foo", variant: :danger)
# Small size
gl_badge_tag("foo", size: :sm)
# With icon
gl_badge_tag("foo", icon: "question-o")
# Icon-only
gl_badge_tag("foo", icon: "question-o", icon_only: true)
# Badge link
gl_badge_tag("foo", nil, href: some_path)
# Custom classes
gl_badge_tag("foo", nil, class: "foo-bar")
# Block content
gl_badge_tag({ variant: :danger }, { class: "foo-bar" }) do
"foo"
end
For accessibility, ensure that the given text or block is non-empty.
See also gitlab-org.gitlab.io/gitlab-ui/?path=/story/base-badge–default.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/badges_helper.rb', line 36 def gl_badge_tag(*args, &block) # Merge the options and html_options hashes if both are present, # because the badge component wants a flat list of keyword args. args.compact! hashes, params = args.partition { |a| a.is_a? Hash } = hashes.reduce({}, :merge) if block render Pajamas::BadgeComponent.new(**), &block else render Pajamas::BadgeComponent.new(*params, **) end end |