Sha256: e22c46c87af75c7017396f1cb7c2a01a83e515e0f59e8b78609a847c88ac1cc9

Contents?: true

Size: 994 Bytes

Versions: 3

Compression:

Stored size: 994 Bytes

Contents

module FormattedForm::ViewHelper
  
  def formatted_form_for(record, options = {}, &proc)
    options = options.dup
    options[:builder] ||= FormattedForm::FormBuilder
    
    options[:html] ||= { }
    options[:html][:class] ||= 'formatted'
    
    # :type option will set proper form class. Conversely having
    # proper css class will set the type that controls what html
    # wrappers are used to render form fields
    if type = options[:html][:class].match(/form-(inline|horizontal|search)/)
      options[:type] ||= type[1].try(:to_sym)
    
    elsif options[:type].present?
      form_class = case options[:type]
        when :inline      then 'form-inline'
        when :horizontal  then 'form-horizontal'
        when :search      then 'form-search'
      end
      options[:html][:class] = "#{options[:html][:class]} #{form_class}".strip
    end
    options[:type] ||= :vertical
    options[:type] = options[:type].to_sym
    
    form_for(record, options, &proc)
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formatted_form-2.1.2 lib/formatted_form/view_helper.rb
formatted_form-2.1.1 lib/formatted_form/view_helper.rb
formatted_form-2.1.0 lib/formatted_form/view_helper.rb