Class: Weaver::Tabs

Inherits:
Object
  • Object
show all
Defined in:
lib/weaver/element_types/tabs.rb

Instance Method Summary collapse

Constructor Details

#initialize(page, anchors) ⇒ Tabs

Returns a new instance of Tabs.



5
6
7
8
9
10
# File 'lib/weaver/element_types/tabs.rb', line 5

def initialize(page, anchors)
  @anchors = anchors
  @tabs = {}
  @page = page
  @orientation = :normal # :left, :right
end

Instance Method Details

#generateObject



34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
74
75
# File 'lib/weaver/element_types/tabs.rb', line 34

def generate
  tabbar = Elements.new(@page, @anchors)
  tabs = @tabs
  orientation = @orientation

  tabbar.instance_eval do
    div class: 'tabs-container' do
      div class: "tabs-#{orientation}" do
        ul class: 'nav nav-tabs' do
          cls = 'active'
          tabs.each do |anchor, value|
            li class: cls do
              a "data-toggle": 'tab', href: "##{anchor}" do
                if value[:title].is_a? Symbol
                  icon value[:title]
                else
                  text value[:title]
                end
              end
            end

            cls = ''
          end
        end

        div class: 'tab-content' do
          cls = 'tab-pane active'
          tabs.each do |anchor, value|
            div id: anchor.to_s, class: cls do
              div class: 'panel-body' do
                text value[:elem].generate
              end
            end
            cls = 'tab-pane'
          end
        end
      end
    end
  end

  tabbar.generate
end

#orientation(direction) ⇒ Object



30
31
32
# File 'lib/weaver/element_types/tabs.rb', line 30

def orientation(direction)
  @orientation = direction
end

#tab(title, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/weaver/element_types/tabs.rb', line 12

def tab(title, &block)
  @anchors['tabs'] = [] unless @anchors['tabs']

  tabArray = @anchors['tabs']

  elem = Elements.new(@page, @anchors)
  elem.instance_eval(&block)

  tabname = "tab#{tabArray.length}"
  tabArray << tabname

  @tabs[tabname] =
    {
      title: title,
      elem: elem
    }
end