Sha256: 034b36c8b2c6566aaa9ebea4f222ef1400f563edf8cf41e1eb1b92395b598702

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

module Storefront
  class Form
    class Label < Storefront::Form::Base
      def initialize(options = {})
        super
        
        attributes.merge!(options[:label_html]) if options[:label_html]
        attributes.delete :label_html
        attributes.delete :label
        
        unless options[:label] == false
          merge_class! attributes, config.label_class
          attributes[:id]       ||= attribute.to_id(:type => :error, :index => index, :parent_index => parent_index) if config.id_enabled_on.include?("label")
          attributes[:for]      ||= attribute.to_id(:type => :input, :index => index, :parent_index => parent_index)
          
          @value    = localize(:labels, attribute.name, options[:label].is_a?(::String) ? options[:label] : nil)
          @value    = attribute.to_label if @value.blank?
        end
      end
      
      def render(&block)
        template.capture_haml do
          template.haml_tag :label, attributes do
            template.haml_tag :span, value
            if attribute.required?
              template.haml_tag :abbr, config.required_abbr, :title => config.required_title, :class => config.required_class
            else
              template.haml_tag :abbr, config.optional_abbr, :title => config.optional_title, :class => config.optional_class
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
storefront-0.3.2 lib/storefront/form/label.rb
storefront-0.3.1 lib/storefront/form/label.rb
storefront-0.3.0 lib/storefront/form/label.rb
storefront-0.2.8 lib/storefront/form/label.rb
storefront-0.2.7 lib/storefront/form/label.rb