Skip to content

Instantly share code, notes, and snippets.

@kasparsj
Created August 25, 2017 09:02
Show Gist options
  • Save kasparsj/699b0f2ea615a35b3f770a5b7c5b76e2 to your computer and use it in GitHub Desktop.
Save kasparsj/699b0f2ea615a35b3f770a5b7c5b76e2 to your computer and use it in GitHub Desktop.
Monkey patch for SimpleForm to be able to override bootstrap grid classes
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