Module: TabsOnRails::ControllerMixin::InstanceMethods

Defined in:
lib/tabs_on_rails/controller_mixin.rb

Instance Method Summary collapse

Instance Method Details

#current_tab(namespace = nil) ⇒ Object

Returns the value for current tab in the default namespace, or nil if no tab has been set before. You can pass namespace get the value of current tab for a different namescope.

Examples

current_tab           # => nil
current_tab :menu     # => nil

set_tab :homepage
set_tab :dashboard, :menu

current_tab           # => :homepage
current_tab :menu     # => :dashboard


109
110
111
# File 'lib/tabs_on_rails/controller_mixin.rb', line 109

def current_tab(namespace = nil)
  tab_stack[namespace || :default]
end

#current_tab=(name) ⇒ Object

This method is deprecated and exists only for compatibility with version 0.2. Please use set_tab method instead of current_tab= setter method.



77
78
79
80
# File 'lib/tabs_on_rails/controller_mixin.rb', line 77

def current_tab=(name)
  ActiveSupport::Deprecation.warn("Method current_tab= is deprecated and will be removed in a future version. Please use set_tab instead.", caller)
  set_tab(name)
end

#current_tab?(name, namespace = nil) ⇒ Boolean

Returns whether the current tab in namespace matches name.

Returns:

  • (Boolean)


114
115
116
# File 'lib/tabs_on_rails/controller_mixin.rb', line 114

def current_tab?(name, namespace = nil)
  current_tab(namespace).to_s == name.to_s
end

#set_tab(name, namespace = nil) ⇒ Object

Sets the value for current tab to given name. If you need to manage multiple tabs, then you can pass an optional namespace.

Examples

set_tab :homepage
set_tab :dashboard, :menu


90
91
92
# File 'lib/tabs_on_rails/controller_mixin.rb', line 90

def set_tab(name, namespace = nil)
  tab_stack[namespace || :default] = name
end

#tab_stackObject

Initializes and/or returns the tab stack. You won’t probably need to use this method directly unless you are trying to hack the plugin architecture.



121
122
123
# File 'lib/tabs_on_rails/controller_mixin.rb', line 121

def tab_stack
  @tab_stack ||= {}
end