0
- module TemplatedMethods
0
- include ActionView::Helpers::TextHelper
0
- include ActionView::Helpers::CaptureHelper
0
- @bypass_for_block = false
0
- ( ActionView::Helpers::FormBuilder.field_helpers - %w(check_box radio_button radio_button_list hidden_field) + %w(time_select)).each do |selector|
0
- class_eval <<-END_SRC, __FILE__, __LINE__
0
- def #{selector}(field, options = {})
0
- tabular_options = extract_tabular_options(field, options)
0
- generic_field(field, super, tabular_options )
0
- def hidden_field(field, options={})
0
- %w(check_box radio_button).each do |selector|
0
- class_eval <<-END_SRC, __FILE__, __LINE__
0
- def #{selector}(field, options = {})
0
- tabular_options = extract_tabular_options(field, options)
0
- generic_field(field, super, tabular_options.merge(:label => :after))
0
- def static(text, options = {})
0
- tabular_options = extract_tabular_options("", options)
0
- generic_field(nil, text, tabular_options)
0
- def submit(text="Submit", options = {})
0
- generic_field(nil, @template.submit_tag(text, options))
0
- def select(field, choices, options = {}, html_options = {})
0
- tabular_options = extract_tabular_options(field, options)
0
- generic_field(field, super, tabular_options )
0
- def radio_button_list(field, choices, options = {})
0
- tabular_options = extract_tabular_options(field, options)
0
- generic_field(field, super, tabular_options )
0
- def generic_field(fieldname, field_content, options = {})
0
- return field_content if @layout.nil? || @bypass_for_block
0
- field_content = options[:prefix] + field.to_s if options[:prefix]
0
- field_content = field.to_s + options[:suffix] if options[:suffix]
0
- label_text = options[:label_text]
0
- label_text = "*#{label_text}" if options[:required]
0
- @layout.field(fieldname, field_content, label_text, options)
0
- def manual(options = {}, &block)
0
- raise "manual expects a block" unless block_given?
0
- content = with_layout(nil) {capture(&block)}
0
- tabular_options = extract_tabular_options( "", options )
0
- concat( generic_field("", content, tabular_options), block.binding)
0
- alias :multiple :manual
0
- # create a new instance of the builder as a different class - helpful when wanting to convert to and from static
0
- new_builder = klass.allocate
0
- self.instance_variables.each{|instance_variable|
0
- new_builder.instance_variable_set(instance_variable, self.instance_variable_get(instance_variable))
0
- self.to(UberBuilder::StaticBuilder)
0
- is_a?(UberBuilder::StaticBuilder)
0
- UberBuilder::Layouts.constants.each do |layout|
0
- def #{layout.downcase}(html_options = {}, &block)
0
- raise "expected a block" unless block_given?
0
- layout = UberBuilder::Layouts::#{layout}.new(@template, @object_name, self)
0
- content = with_layout(layout) { capture(&block) }
0
- concat( layout.section(content, html_options), block.binding )
0
- def extract_tabular_options(field, options)
0
- :label_text => options.delete(:label) || field.to_s.humanize,
0
- :required => options.delete(:required) || false,
0
- :prefix => options.delete(:prefix),
0
- :suffix => options.delete(:suffix),
0
- :row => options.delete(:row)
0
- def with_layout(layout, &block)
0
- last_layout, @layout = @layout, layout
0
+ module TemplatedMethods
0
+ include ActionView::Helpers::TextHelper
0
+ include ActionView::Helpers::CaptureHelper
0
+ @bypass_for_block = false
0
+ ( ActionView::Helpers::FormBuilder.field_helpers - %w(check_box radio_button radio_button_list hidden_field) + %w(time_select)).each do |selector|
0
+ class_eval <<-END_SRC, __FILE__, __LINE__
0
+ def #{selector}(field, options = {})
0
+ tabular_options = extract_tabular_options(field, options)
0
+ generic_field(field, super, tabular_options )
0
+ def hidden_field(field, options={})
0
+ %w(check_box radio_button).each do |selector|
0
+ class_eval <<-END_SRC, __FILE__, __LINE__
0
+ def #{selector}(field, options = {})
0
+ tabular_options = extract_tabular_options(field, options)
0
+ generic_field(field, super, tabular_options.merge(:label => :after))
0
+ def static(text, options = {})
0
+ tabular_options = extract_tabular_options("", options)
0
+ generic_field(nil, text, tabular_options)
0
+ def submit(text="Submit", options = {})
0
+ generic_field(nil, @template.submit_tag(text, options))
0
+ def select(field, choices, options = {}, html_options = {})
0
+ tabular_options = extract_tabular_options(field, options)
0
+ generic_field(field, super, tabular_options )
0
+ def radio_button_list(field, choices, options = {})
0
+ tabular_options = extract_tabular_options(field, options)
0
+ generic_field(field, super, tabular_options )
0
+ def generic_field(fieldname, field_content, options = {})
0
+ return field_content if @layout.nil? || @bypass_for_block
0
+ field_content = options[:prefix] + field.to_s if options[:prefix]
0
+ field_content = field.to_s + options[:suffix] if options[:suffix]
0
+ label_text = options[:label_text]
0
+ label_text = "*#{label_text}" if options[:required]
0
+ @layout.field(fieldname, field_content, label_text, options)
0
+ def manual(options = {}, &block)
0
+ raise "manual expects a block" unless block_given?
0
+ content = with_layout(nil) {capture(&block)}
0
+ tabular_options = extract_tabular_options( "", options )
0
+ concat( generic_field("", content, tabular_options), block.binding)
0
+ alias :multiple :manual
0
+ # create a new instance of the builder as a different class - helpful when wanting to convert to and from static
0
+ new_builder = klass.allocate
0
+ self.instance_variables.each{|instance_variable|
0
+ new_builder.instance_variable_set(instance_variable, self.instance_variable_get(instance_variable))
0
+ self.to(UberBuilder::StaticBuilder)
0
+ is_a?(UberBuilder::StaticBuilder)
0
+ def respond_to?(method, include_private = false)
0
+ super || define_layout_method(method)
0
+ def method_missing(method, *args, &block)
0
+ respond_to?(method) ? send(method, *args, &block) : super
0
+ def define_layout_method(method)
0
+ const_name = method.to_s.classify
0
+ return false unless UberBuilder::Layouts.const_defined?(const_name)
0
+ self.class.class_eval <<-EOF
0
+ def #{method}(html_options = {}, &block)
0
+ raise "expected a block" unless block_given?
0
+ layout = UberBuilder::Layouts::#{const_name}.new(@template, @object_name, self)
0
+ content = with_layout(layout) { capture(&block) }
0
+ concat( layout.section(content, html_options), block.binding )
0
+ def extract_tabular_options(field, options)
0
+ :label_text => options.delete(:label) || field.to_s.humanize,
0
+ :required => options.delete(:required) || false,
0
+ :prefix => options.delete(:prefix),
0
+ :suffix => options.delete(:suffix),
0
+ :outer => options.delete(:outer)
0
+ def with_layout(layout, &block)
0
+ last_layout, @layout = @layout, layout
0
\ No newline at end of file
Comments
No one has commented yet.