Class: Storefront::Components::Form::Fieldset

Inherits:
Base
  • Object
show all
Defined in:
lib/storefront/components/form/fieldset.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 collapse

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 = {}) ⇒ Fieldset

Returns a new instance of Fieldset.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/storefront/components/form/fieldset.rb', line 7

def initialize(options = {})
  super

  @label      = localize(:titles, options[:label], nil, (attributes[:locale_options] || {}).merge(:allow_blank => true)) if options[:label].present?

  merge_class! attributes, *[
    config.fieldset_class
  ]

  attributes[:id] ||= label.underscore.strip.gsub(/[_\s]+/, config.separator) if label.present?
  attributes.delete(:index)
  attributes.delete(:parent_index)
  attributes.delete(:label)

  @builder     = Storefront::Components::Form::Builder.new(
    :template       => template, 
    :model          => model,
    :attribute      => attribute,
    :index          => index,
    :parent_index   => parent_index
  )
end

Dynamic Method Handling

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

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



5
6
7
# File 'lib/storefront/components/form/fieldset.rb', line 5

def builder
  @builder
end

Instance Method Details

#render(&block) ⇒ Object

form.inputs :basic_info, :locale_options => => 1, :past => true



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/storefront/components/form/fieldset.rb', line 31

def render(&block)
  template.capture_haml do
    template.haml_tag :fieldset, attributes do
      template.haml_tag :legend, :class => config.legend_class do
        template.haml_tag :span, label
      end if label.present?
      template.haml_tag config.field_list_tag, :class => config.list_class do
        builder.render(&block)
      end
    end
  end
end