https://github.com/nlight/css-class-string
Helper for creating css class strings inspired by ReactJS classSet
https://github.com/nlight/css-class-string
Last synced: 4 months ago
JSON representation
Helper for creating css class strings inspired by ReactJS classSet
- Host: GitHub
- URL: https://github.com/nlight/css-class-string
- Owner: nLight
- License: mit
- Created: 2014-06-09T07:44:36.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-17T20:21:58.000Z (almost 12 years ago)
- Last Synced: 2025-04-21T12:22:37.884Z (about 1 year ago)
- Language: Ruby
- Size: 221 KB
- Stars: 22
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CssClassString
Helper for creating css class strings inspired by ReactJS classSet
- Pass bare arguments for default classes
- Pass hash of `class => ` for conditional classes
- Use array with two classes as a `key` and first will be used for truthy and second for falsey value `[:true?, :false?] => `
## Installation
Add this line to your application's Gemfile:
gem 'css-class-string'
## Usage
```haml
// @boolvalue = true
%span{class: class_string({some: true, classy: false, [:truthy, :falsy] => @boolvalue})}
// equal to
%span{class: class_string('some', falsy: false, [:truthy, :falsy] => @boolvalue)}
// =>
```
```html+erb
```
Outside a view
```ruby
CssClassString::Helper.new({}).to_s
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request