Sha256: d07cba058f08a3f6b3d3b7a7ffb1c0577901eb9f7ac6bfd50d639fa15c1a7687

Contents?: true

Size: 682 Bytes

Versions: 207

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

# Inspired by https://github.com/JedWatson/classnames
#
# Helps build a list of conditional class names
module Primer
  # :nodoc:
  module ClassNameHelper
    def class_names(*args)
      [].tap do |classes|
        args.each do |class_name|
          case class_name
          when String
            classes << class_name if class_name.present?
          when Hash
            class_name.each do |key, val|
              classes << key if val
            end
          when Array
            classes << class_names(*class_name).presence
          end
        end

        classes.compact!
        classes.uniq!
      end.join(" ")
    end
  end
end

Version data entries

207 entries across 207 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.52.2 app/lib/primer/class_name_helper.rb
primer_view_components-0.36.4 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.52.1 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.52.0 app/lib/primer/class_name_helper.rb
primer_view_components-0.36.3 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.51.0 app/lib/primer/class_name_helper.rb
primer_view_components-0.36.2 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.50.1 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.50.0 app/lib/primer/class_name_helper.rb
primer_view_components-0.36.1 app/lib/primer/class_name_helper.rb
primer_view_components-0.36.0 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.49.2 app/lib/primer/class_name_helper.rb
primer_view_components-0.35.2 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.49.1 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.49.0 app/lib/primer/class_name_helper.rb
primer_view_components-0.35.1 app/lib/primer/class_name_helper.rb
primer_view_components-0.35.0 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.48.2 app/lib/primer/class_name_helper.rb
openproject-primer_view_components-0.48.1 app/lib/primer/class_name_helper.rb