classnames

A Ruby port of JavaScript's classnames

MIT License

Downloads
62.9K
Stars
10
Committers
3

classnames

This is a port of JavaScript's classnames for Ruby. The API is basically the same except with Ruby's types.

Example usage

module ApplicationHelper
  include ClassNames

  def my_element(**opts)
    str = classnames(
      'takes',                      # string
      ['all', 'kinds'],             # array
      { of: true, not_me: false },  # hash
      ->{ 'arguments' },            # proc
      nil,                          # and ignores ...
      false,                        # ... falsey values
      opts.delete(:class)
    )
    # => "takes all kinds of arguments"

    tag.div(class: str, **opts) { 'So hot' }
  end
end

Installation

Add classnames to your Gemfile:

gem 'classnames'

License

MIT