Sha256: dabed400dbad4ef1261e72de1c7b612be5aa78d2a6471a6051d449a8c64e3ece

Contents?: true

Size: 682 Bytes

Versions: 2

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 Yattho
  # :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

2 entries across 2 versions & 1 rubygems

Version Path
yattho_view_components-0.1.1 app/lib/yattho/class_name_helper.rb
yattho_view_components-0.0.1 app/lib/yattho/class_name_helper.rb