Class: Storefront::Components::Form::Label

Inherits:
Base
  • Object
show all
Defined in:
lib/storefront/components/form/label.rb

Constant Summary

Constants included from Helpers::ContentHelper

Helpers::ContentHelper::SCOPES, Helpers::ContentHelper::SCOPES_WITH_NAMESPACE, Helpers::ContentHelper::SCOPES_WITH_NAMESPACE_AND_NESTED_MODEL, Helpers::ContentHelper::SCOPES_WITH_NESTED_MODEL

Instance Attribute Summary

Attributes inherited from Base

#options, #template

Instance Method Summary collapse

Methods included from Helpers::DomHelper

#aria, #clone_attributes, #dom, #index_class, #merge_class, #merge_class!, #page, #resource_to_title, #title_widget, #title_widget_options

Methods included from Helpers::ContentHelper

#encoded_contents, #font_face_data_uri, #html5_time, #read_binary_file, #read_image_size, #rendered_text, #sanitize, #t?

Methods inherited from Base

#component_name, #extract_classes!, #extract_options!, #inside?, #pointer, #render_with_pointer, #to_s

Constructor Details

#initialize(options = {}) ⇒ Label

Returns a new instance of Label.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/storefront/components/form/label.rb', line 5

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) if config.id_enabled_on.include?("input")
  
    @value    = localize(:labels, attribute.name, options[:label].is_a?(::String) ? options[:label] : nil)
    @value    = attribute.to_label if @value.blank?
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Storefront::Components::Base

Instance Method Details

#render(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/storefront/components/form/label.rb', line 22

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