Module: SimpleTabs

Included in:
ActionView::Base
Defined in:
lib/simple_tabs.rb

Instance Method Summary collapse

Instance Method Details

#child(url) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/simple_tabs.rb', line 30

def child(url)
  return if @active
  url = url_to_string(url) unless url.is_a?(Hash)
  if url.all? { |value| value.is_a?(String) || value.is_a?(Symbol) }
    if current_page?(url)
      @active = true
    end
  else
    if params_matches?(url)
      @active = true
    end
  end
end

#tab(name, url, link_attributes = {}) ⇒ Object



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

def tab(name, url, link_attributes={})
  @active = false
  url = url_to_string(url)
  if current_page? url
    concat "<li class='#{@options[:active_class]}'>"
  else
    if block_given?
      yield
      if @active
        concat "<li class='#{@options[:active_class]}'>"
      else
        concat '<li>'
      end
    else
      concat '<li>'
    end
  end
  concat link_to_unless_current(name, url, link_attributes)
  concat '</li>'
end

#tabbed_menu(options = {}) ⇒ Object



2
3
4
5
6
7
# File 'lib/simple_tabs.rb', line 2

def tabbed_menu(options={})
  @options = options.reverse_merge(:id => 'menu', :active_class => 'active')
  concat "<ul id='#{@options[:id]}'>"
  yield if block_given?
  concat '</ul>'
end