Created
March 18, 2015 10:57
-
-
Save namxam/0c4c8b398445c2b3457c to your computer and use it in GitHub Desktop.
Some method to generate a string of css classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def conditional_css(*elements) | |
elements.map do |element| | |
if element.kind_of?(Hash) | |
element.select { |k, v| v }.keys | |
else | |
element.to_s | |
end | |
end.compact.join(' ') | |
end | |
puts conditional_css('some-klass', :another, { valid: true, invalid: false }) | |
# => 'some-klass another valid' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment