Created
August 22, 2014 17:41
-
-
Save budu/5af79726c132202a2d46 to your computer and use it in GitHub Desktop.
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
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