Created
August 25, 2017 09:02
-
-
Save kasparsj/699b0f2ea615a35b3f770a5b7c5b76e2 to your computer and use it in GitHub Desktop.
Monkey patch for SimpleForm to be able to override bootstrap grid classes
This file contains 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
module SimpleForm | |
module Wrappers | |
class Many | |
private | |
def wrap(input, options, content) | |
return content if options[namespace] == false | |
return if defaults[:unless_blank] && content.empty? | |
tag = (namespace && options[:"#{namespace}_tag"]) || @defaults[:tag] | |
return content unless tag | |
klass = html_classes(input, options) | |
opts = html_options(options) | |
merge_classes(klass, opts[:class]) | |
opts[:class] = klass.join(' ').strip unless klass.empty? | |
input.template.content_tag(tag, content, opts) | |
end | |
def merge_classes(klass, klass2) | |
klass << klass2 unless klass2.blank? | |
['col-xs-\d+', 'col-sm-\d+', 'col-md-\d+', 'col-lg-\d+'].each do |bc| | |
matches = klass.grep(Regexp.new(bc)) | |
matches[0...(matches.size-1)].each do |match| | |
klass.delete(match) | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment