Skip to content

mikker/classnames

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

classnames

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

Gem

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

About

A Ruby port of JavaScript's classnames

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages