Erector::ConditionalClasses
erector-conditional_classes is a rubygem that makes using the conditional application of html classes in your views nicer.
Erector provides a wonderful chain-based api for applying classes to an element:
span.foo.bar.baz "hello" # => '<span class="foo bar baz">hello</span>'
The pain comes when you need to conditionally apply classes to an element:
classes = [:foo]
classes << :bar if some_condition?
span("hello", :class => classes) # => '<span class="foo">hello</span>'
This gem provides support in the chaining API for conditionals:
#block based
span.foo.bar(:if => some_condition?){ text "hello" } # => '<span class="foo">hello</span>'
# non-block content
span("hello").foo.bar(:if => some_condition?) # => '<span class="foo">hello</span>'
Installation
Add this line to your application's Gemfile:
gem 'erector-conditional_classes'
And then execute:
$ bundle
Or install it yourself as:
$ gem install erector-conditional_classes
Usage
just:
require 'erector/conditional_classes'
and you're good to go.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request