Skip to content

Instantly share code, notes, and snippets.

@budu
Created August 22, 2014 17:41
Show Gist options
  • Save budu/5af79726c132202a2d46 to your computer and use it in GitHub Desktop.
Save budu/5af79726c132202a2d46 to your computer and use it in GitHub Desktop.
SimpleForm::FormBuilder.class_eval do
def input_with_bs_cols(attribute_name, options = {}, &block)
bs_cols_classes = parse_bs_cols_option(options)
if bs_cols_classes
wrapper_html_options = (options[:wrapper_html] || {})
.merge_html_attributes(class: bs_cols_classes.join(' '))
options[:wrapper_html] = wrapper_html_options
end
input_without_bs_cols(attribute_name, options, &block)
end
alias_method_chain :input, :bs_cols
def parse_bs_cols_option(options)
if layout = options[:bs_cols]
sizes = %w(xs sm md lg)
values = layout.split('-')
values.zip(sizes).map do |(value, size)|
"col-#{size}-#{value}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment