Class: TwitterBootstrap::TabsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_bootstrap_helpers/tabs_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_context, opts = {}) ⇒ TabsGenerator

Returns a new instance of TabsGenerator.



8
9
10
11
12
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 8

def initialize _context, opts={}
  self.context = _context
  self.panes = {}
  self.options = opts
end

Instance Attribute Details

#active_paneObject

unloadable include ::ActionView::Helpers::UrlHelper include ::ActionView::Helpers::TagHelper



6
7
8
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 6

def active_pane
  @active_pane
end

#contextObject

unloadable include ::ActionView::Helpers::UrlHelper include ::ActionView::Helpers::TagHelper



6
7
8
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 6

def context
  @context
end

#optionsObject

unloadable include ::ActionView::Helpers::UrlHelper include ::ActionView::Helpers::TagHelper



6
7
8
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 6

def options
  @options
end

#panesObject

unloadable include ::ActionView::Helpers::UrlHelper include ::ActionView::Helpers::TagHelper



6
7
8
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 6

def panes
  @panes
end

Instance Method Details

#generate(block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 22

def generate block
  buffer = context. :ul, :class=>'nav nav-tabs' do
    block.call(self)
  end
  buffer << generate_tab_content
  buffer

  #buffer = ''

  #if options[:position] == :belowe
    #raise 'not ready'
    #buffer << context.content_tag( :div,
                                  #(generate_tab_content + generate_tab_navs).html_safe,
                                  #:class => 'tabbable tabs-below')
  #else
    #context.content_tag :ul, :class=>'nav nav-tabs' do
      #buffer << block.call(self)
    #end
    #buffer << generate_tab_content
  #end
  #buffer.html_safe
end

#pane(id, title = nil, content_or_options = nil, options = {}, &content_block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/twitter_bootstrap_helpers/tabs_generator.rb', line 45

def pane id, title=nil, content_or_options=nil, options={}, &content_block
  pane = {}
  if block_given?
    pane[:content] = content_block
    options = content_or_options || {}
  else
    pane[:content] = content_or_options
  end

  pane[:link] = options[:link] if options.has_key?(:link)
  pane[:tooltip] = options[:tooltip]
  pane[:class] = ['tab-pane', options[:pane_class]].compact
  pane[:title] = title ||= id
  pane[:data] = options[:data]

  if active_pane == id or options[:active]
    self.active_pane = id
    pane[:class] << :active
    pane[:nav_class] ||= []
    pane[:nav_class] << :active
  end

  self.panes[id] = pane

  generate_nav_tab id, pane
end