Sha256: 0bf29e46695bee375005ef84e5b260761b468ac8fe842009021e7653a914c409

Contents?: true

Size: 1.6 KB

Versions: 8

Compression:

Stored size: 1.6 KB

Contents

module Motr
  
  module Forms #:nodoc:
    
    autoload :Base,    'motr/forms/base'
    autoload :Helpers, 'motr/forms/helpers'
    autoload :Builder, 'motr/forms/builder'
    
    # The class to be applied to the wrapper that wraps the entire field
    mattr_accessor :error_class
    @@error_class = 'field_with_errors'
    
    # The class to be applied to the error message element
    mattr_accessor :message_error_class
    @@message_error_class = 'errors_for_field'
    
    # An ERB template to be used when rendering a field with errors
    mattr_accessor :error_template
    @@error_template = %{
          <span class="<%= error_class %>">
               <%= html_tag %>
               <span class="<%= message_error_class %>"><%= [messages].flatten.join(",") %></span>
          </span>}
          
    # Setup the default form builder
    mattr_accessor :default_builder
    @@default_builder = Motr::Forms::Builder
    
    # Stub out a new default_error_proc, but create the option to override it if necessary
    mattr_accessor :field_error_proc
    @@field_error_proc = lambda{ |html_tag, instance_tag| html_tag }
    
    protected
    
    ##
    # 
    # Wrapper method to override the default field_error_proc
    # Field errors are displayed using the template defined by Motr::Forms.error_template
    #
    # @return [String]
    # 
    def self.with_custom_error_proc(&block)
      default_proc = ::ActionView::Base.field_error_proc
      ::ActionView::Base.field_error_proc = Motr::Forms.field_error_proc
      yield
    ensure
      ::ActionView::Base.field_error_proc = default_proc
    end
    
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
motr-0.1.1 lib/motr/forms.rb
motr-0.1.0 lib/motr/forms.rb
motr-0.0.9 lib/motr/forms.rb
motr-0.0.8 lib/motr/forms.rb
motr-0.0.7 lib/motr/forms.rb
motr-0.0.6 lib/motr/forms.rb
motr-0.0.5 lib/motr/forms.rb
motr-0.0.4 lib/motr/forms.rb