Sha256: fe73795b3d61a7b97235755778fa56929974f14267ab7a673ad0b23be7fb6f2f

Contents?: true

Size: 1.29 KB

Versions: 14

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module GoodJob
  module IconsHelper
    STATUS_ICONS = {
      discarded: "exclamation",
      succeeded: "check",
      queued: "dash_circle",
      retried: "arrow_clockwise",
      running: "play",
      scheduled: "clock",
    }.freeze

    STATUS_COLOR = {
      discarded: "danger",
      succeeded: "success",
      queued: "secondary",
      retried: "warning",
      running: "primary",
      scheduled: "secondary",
    }.freeze

    def status_badge(status)
      content_tag :span, status_icon(status, class: "text-white") + t(status, scope: 'good_job.status', count: 1),
                  class: "badge rounded-pill bg-#{STATUS_COLOR.fetch(status)} d-inline-flex gap-2 ps-1 pe-3 align-items-center"
    end

    def status_icon(status, **options)
      options[:class] ||= "text-#{STATUS_COLOR.fetch(status)}"
      icon = render_icon STATUS_ICONS.fetch(status)
      content_tag :span, icon, **options
    end

    def render_icon(name, class: nil, **options)
      tag.svg(viewBox: "0 0 16 16", class: "svg-icon #{binding.local_variable_get(:class)}", **options) do
        tag.use(fill: "currentColor", href: "#{icons_path}##{name}")
      end
    end

    def icons_path
      @_icons_path ||= frontend_static_path(:icons, format: :svg, locale: nil)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
good_job-4.8.2 app/helpers/good_job/icons_helper.rb
good_job-4.8.1 app/helpers/good_job/icons_helper.rb
good_job-4.8.0 app/helpers/good_job/icons_helper.rb
good_job-4.7.0 app/helpers/good_job/icons_helper.rb
good_job-4.6.0 app/helpers/good_job/icons_helper.rb
good_job-4.5.1 app/helpers/good_job/icons_helper.rb
good_job-4.5.0 app/helpers/good_job/icons_helper.rb
good_job-4.4.2 app/helpers/good_job/icons_helper.rb
good_job-4.4.1 app/helpers/good_job/icons_helper.rb
good_job-4.4.0 app/helpers/good_job/icons_helper.rb
good_job-4.3.0 app/helpers/good_job/icons_helper.rb
good_job-4.2.1 app/helpers/good_job/icons_helper.rb
good_job-4.2.0 app/helpers/good_job/icons_helper.rb
good_job-4.1.1 app/helpers/good_job/icons_helper.rb