module ExtForm::Layouts::BaseLayout
Attributes
actual_width[RW]
layout[RW]
layout_config[RW]
Public Instance Methods
calc_actual_width()
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 65 def calc_actual_width raise NotImplementedError end
calculate_input_width(max_width, label_width, spacing, cols_sum, c)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 69 def calculate_input_width(max_width, label_width, spacing, cols_sum, c) raise NotImplementedError end
calculate_layout(config)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 55 def calculate_layout(config) layout = [] cols = config[:layout].split(':').map { |s| s.to_i } cols.each do |c| layout << [config[:label_width], calculate_input_width(config[:max_width], config[:label_width], config[:spacing], cols.sum, c)] end layout end
input_width(seq)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 77 def input_width(seq) self.layout[seq][1] end
label_width(seq)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 73 def label_width(seq) self.layout[seq][0] end
layout_available?(layout)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 51 def layout_available?(layout) layout && layout.match(/^\d(:\d){0,2}$/) end
measure_available?(measure)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 47 def measure_available?(measure) raise NotImplementedError end
setup_config(config)
click to toggle source
Internal: setup layout configuration and setup the default layout of form, you can change it in a particular row.
config - layout config, default nil, it must be a hash.
:layout - it's a string ,specify the scale of columns. for example: '1:1', '1:2', '1:1:1' :spacing - left and right padding of form, should be number or percentage. :label_width - label width of input, should be number or percentage. :max_width - max width of form, should be number or percentage. All width options should be all numbers or all percentages, or it will not be calculated correctly. I'm looking for a method to provide responding design. Any contribution will be appreciated.
# File lib/ext_form/layouts/base_layout.rb, line 26 def setup_config(config) self.layout_config = if config && config.is_a?(Hash) config.delete(:layout) unless layout_available?(config[:layout]) config.delete(:spacing) unless width_available?(config[:spacing]) config.delete(:label_width) unless width_available?(config[:label_width]) config.delete(:max_width) unless width_available?(config[:max_width]) config.delete(:measure) unless measure_available?(config[:measure]) config.reverse_merge(ExtForm.default_layout) else ExtForm.default_layout.dup end self.layout = calculate_layout(layout_config) self.actual_width = calc_actual_width end
width_available?(width)
click to toggle source
# File lib/ext_form/layouts/base_layout.rb, line 43 def width_available?(width) raise NotImplementedError end