class Tabulous::Tab
Attributes
declared_to_have_subtabs[RW]
enabled_when[W]
http_verb[W]
kind[RW]
link_path[W]
name[RW]
parent[R]
subtabs[RW]
text[W]
visible_when[W]
Public Class Methods
new()
click to toggle source
# File lib/tabulous/tab.rb, line 8 def initialize @subtabs = [] @active_actions = {} @kind = :primary_tab @declared_to_have_subtabs = false @http_verb = :get end
Public Instance Methods
active?(view)
click to toggle source
# File lib/tabulous/tab.rb, line 93 def active?(view) current_controller = view.controller_path.to_s current_action = view.action_name.to_s active_actions = @active_actions[current_controller] return true if active_actions && (active_actions.include?('any') || active_actions.include?(current_action)) return true if @subtabs.any? { |subtab| subtab.active?(view) } false end
active_actions_overlap?(tab)
click to toggle source
# File lib/tabulous/tab.rb, line 102 def active_actions_overlap?(tab) for controller in @active_actions.keys other_actions = tab.active_actions[controller] if other_actions these_actions = @active_actions[controller] if (!(other_actions & these_actions).empty?) || other_actions.include?('any') || these_actions.include?('any') return true end end end false end
add_active_actions(controller, actions)
click to toggle source
controller actions that make this tab active
# File lib/tabulous/tab.rb, line 84 def add_active_actions(controller, actions) controller = controller.to_s actions = [actions] if !actions.is_a?(Array) for action in actions @active_actions[controller] ||= [] @active_actions[controller] << action.to_s end end
clickable?(view)
click to toggle source
# File lib/tabulous/tab.rb, line 79 def clickable?(view) enabled?(view) && (!active?(view) || Config.active_tab_clickable) end
enabled?(view=nil)
click to toggle source
# File lib/tabulous/tab.rb, line 71 def enabled?(view=nil) if @enabled_when.respond_to?(:call) view.instance_exec(&@enabled_when) else @enabled_when end end
http_verb(view=nil)
click to toggle source
# File lib/tabulous/tab.rb, line 50 def http_verb(view=nil) value = if @http_verb.respond_to?(:call) view.instance_exec(&@http_verb) else @http_verb end value = value.to_s.downcase.to_sym unless [:get, :post, :delete, :patch, :put].include?(value) raise ImproperValueError, "The http_verb of tab '#{self.name}' must be :get, :post, :delete, :patch or :put." end value end
link_path(view=nil)
click to toggle source
# File lib/tabulous/tab.rb, line 38 def link_path(view=nil) value = if @link_path.respond_to?(:call) view.instance_exec(&@link_path) else @link_path end unless value.is_a?(String) raise ImproperValueError, "The link_path of tab '#{self.name}' needs to be a string." end value end
parent=(tab)
click to toggle source
# File lib/tabulous/tab.rb, line 16 def parent=(tab) raise "only subtabs can have parents" unless subtab? @parent = tab @parent.subtabs = @parent.subtabs + [self] end
subtab?()
click to toggle source
# File lib/tabulous/tab.rb, line 22 def subtab? @kind == :subtab end
text(view=nil)
click to toggle source
# File lib/tabulous/tab.rb, line 26 def text(view=nil) value = if @text.respond_to?(:call) view.instance_exec(&@text) else @text end unless value.is_a?(String) raise ImproperValueError, "The text of tab '#{self.name}' needs to be a string." end value end
visible?(view=nil)
click to toggle source
# File lib/tabulous/tab.rb, line 63 def visible?(view=nil) if @visible_when.respond_to?(:call) view.instance_exec(&@visible_when) else @visible_when end end
Protected Instance Methods
active_actions()
click to toggle source
# File lib/tabulous/tab.rb, line 119 def active_actions @active_actions end