No commit activity in last 3 years
No release in over 3 years
Erector extension for conditional classes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

>= 0.9.0
 Project Readme

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

  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