Changeset 10

Show
Ignore:
Timestamp:
08/29/2006 08:56:54 AM (2 years ago)
Author:
matthew
Message:

API CHANGE: Split static_* methods into static_*(:symbol) and
calculated_*(&block) variants.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/auto-admin/lib/auto_admin_simple_theme.rb

    r5 r10  
    313313      hyperlink field, options 
    314314    end 
    315     def static_text(field, options = {}, &block) # :yields: object 
    316       h html(field_content(field, options, &block), options) 
    317     end 
    318     def static_html(field = nil, options = {}) # :yields: object 
    319       html(field_content(field, options, &block), options) 
    320     end 
    321     def field_content(field = nil, options = {}) # :yields: object 
    322       raise ArgumentError, "Missing block or field name" unless field || block_given? 
    323       v = if block_given? 
    324         yield @object 
    325       else 
    326         @object.send(field) 
    327       end 
    328     end 
    329     private :field_content 
     315    def static_text(field, options = {}) 
     316      h( @object.send field ) 
     317    end 
     318    def calculated_text(options = {}) # :yields: object 
     319      h( yield @object ) 
     320    end 
     321    def static_html(field, options = {}) 
     322      @object.send field 
     323    end 
     324    def calculated_html(options = {}) # :yields: object 
     325      yield @object 
     326    end 
    330327    def html(content = nil, options = {}) # :yields: object 
    331328      raise ArgumentError, "Missing block or field name" unless content || block_given? 
     
    333330    end 
    334331 
     332    def self.calculated_helpers 
     333      BaseFormBuilder.public_instance_methods(false).select {|m| m =~ /^calculated_/ } 
     334    end 
    335335    def self.field_helpers 
    336       methods = BaseFormBuilder.public_instance_methods(false) - %w(auto_field with_object inner_fields_for table_fields_for) 
     336      methods = BaseFormBuilder.public_instance_methods(false) - calculated_helpers - %w(html auto_field with_object inner_fields_for table_fields_for) 
    337337      ends = methods.select {|m| m =~ /^end_/ } 
    338338      begins = ends.map {|m| m.sub /^end_/, '' } 
     
    392392    end 
    393393 
     394    # Calculated helpers are always read-only, so they needn't do 
     395    # anything in a FormProcessor. 
     396    AutoAdmin::BaseFormBuilder.calculated_helpers.each do |helper| 
     397      class_eval <<-end_src, __FILE__, __LINE__ 
     398        def #{helper}(options={}); end 
     399      end_src 
     400    end 
     401 
    394402    AutoAdmin::BaseFormBuilder.field_helpers.each do |helper| 
    395403      class_eval <<-end_src, __FILE__, __LINE__ 
     
    441449    end 
    442450 
    443     (field_helpers - %w(html hidden_field)).each do |helper| 
     451    calculated_helpers.each do |helper| 
     452      class_eval <<-end_src, __FILE__, __LINE__ 
     453        alias :#{helper}_without_theme :#{helper} 
     454        def #{helper}(options={}, *args, &proc) 
     455          wrap_field #{helper.to_sym.inspect}, nil, options do |*a| 
     456            a.empty? ? super(options, *args, &proc) : super(*a) 
     457          end 
     458        end 
     459      end_src 
     460    end 
     461    (field_helpers - %w(hidden_field)).each do |helper| 
    444462      class_eval <<-end_src, __FILE__, __LINE__ 
    445463        alias :#{helper}_without_theme :#{helper}