0.01
No commit activity in last 3 years
No release in over 3 years
A simple utility for conditionally joining classNames together. Fork from classnames of javascript
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
~> 2.3.0
~> 10.0
 Project Readme

Gem Version Code Climate Travis

classnames-rails

Classnames for Rails - a gem package fork from classnames. A simple javascript utility for conditionally joining classNames together.

Installation

Add this line to your application's Gemfile:

gem 'classnames-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install classnames-rails

Remember!! Add the line below in your application.js

//= require classnames

If you need to use dedupe version(option)

//= require classnames-dedupe

But notice it slow(10x) than original version.

That's it and you can use classNames in Rails now.

Usage

In javascript file you can establish complexity class names together for example:

var navClass = classNames("navbar", "navbar-default");
// "navbar navbar-default"

var navClass = classNames({
  "navbar": true,
  "navbar-default": false
  "hidden": false
});
// "navbar"

// More examples...
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'

// lots of arguments of various types
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }) // => 'foo bar baz quux'

// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'

For more information please reference classNames

Development

2015-05-29 The classnames v2.1.2

Contributing

Feel free to open an issue ticket if you find something that could be improved.