Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikker/classnames
A Ruby port of JavaScript's classnames
https://github.com/mikker/classnames
Last synced: about 2 months ago
JSON representation
A Ruby port of JavaScript's classnames
- Host: GitHub
- URL: https://github.com/mikker/classnames
- Owner: mikker
- License: mit
- Created: 2016-06-07T07:28:19.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T08:36:06.000Z (about 1 year ago)
- Last Synced: 2024-05-01T22:40:42.137Z (5 months ago)
- Language: Ruby
- Homepage:
- Size: 8.79 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# classnames
This is a port of JavaScript's [classnames](https://www.npmjs.com/package/classnames) for Ruby. The API is basically the same except with Ruby's types.
![Gem](https://img.shields.io/gem/v/classnames)
### Example usage
```ruby
module ApplicationHelper
include ClassNamesdef 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`:
```rb
gem 'classnames'
```### License
MIT