Class: Para::FormBuilder::Tabs::TabsManager

Inherits:
Object
  • Object
show all
Defined in:
lib/para/form_builder/tabs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, object, builder, options) ⇒ TabsManager

Returns a new instance of TabsManager.



15
16
17
18
19
20
# File 'lib/para/form_builder/tabs.rb', line 15

def initialize(template, object, builder, options)
  @template = template
  @object = object
  @builder = builder
  @options = options
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



13
14
15
# File 'lib/para/form_builder/tabs.rb', line 13

def builder
  @builder
end

#objectObject (readonly)

Returns the value of attribute object.



13
14
15
# File 'lib/para/form_builder/tabs.rb', line 13

def object
  @object
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/para/form_builder/tabs.rb', line 13

def options
  @options
end

#templateObject (readonly)

Returns the value of attribute template.



13
14
15
# File 'lib/para/form_builder/tabs.rb', line 13

def template
  @template
end

Instance Method Details

#affix?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/para/form_builder/tabs.rb', line 50

def affix?
  options[:affix]
end

#finalize!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/para/form_builder/tabs.rb', line 31

def finalize!
  # Set all tabs as inactive if one of the tabs was set to be active
  # manually
  if tabs.any?(&:active)
    active_already_set = false

    tabs.each do |tab|
      # Get a boolean value for the current active state of the tab
      tab_active = !!tab.active

      tab.active = !active_already_set && tab_active

      # Set the "already set" flag to true once we found one active
      # tab, forcing `active = false` for all further tabs
      active_already_set ||= tab_active
    end
  end
end

#tab(identifier, options = {}, &block) ⇒ Object



22
23
24
25
# File 'lib/para/form_builder/tabs.rb', line 22

def tab(identifier, options = {}, &block)
  tabs << Tab.new(template, object, builder, identifier, options, tabs.length, &block)
  nil
end

#tabsObject



27
28
29
# File 'lib/para/form_builder/tabs.rb', line 27

def tabs
  @tabs ||= []
end