Module: EffectiveBootstrap3Helper

Defined in:
app/helpers/effective_bootstrap3_helper.rb

Instance Method Summary collapse

Instance Method Details



18
19
20
21
22
23
24
25
26
# File 'app/helpers/effective_bootstrap3_helper.rb', line 18

def nav_dropdown(label, link_class: [], list_class: [], &block)
  raise 'expected a block' unless block_given?

  (:li, class: 'dropdown') do
    (:a, class: 'dropdown-toggle', href: '#', 'data-toggle': 'dropdown', role: 'button', 'aria-haspopup': 'true', 'aria-expanded': 'false') do
      label.html_safe + (:span, '', class: 'caret')
    end + (:ul, class: 'dropdown-menu') { yield }
  end
end

%ul.nav.navbar-nav.navbar-right

= nav_link_to 'Sign In', new_user_session_path
= nav_dropdown 'Settings' do
  = nav_link_to 'Account Settings', 
  li.divider
  = nav_link_to 'Sign In', new_user_session_path, method: :delete


12
13
14
15
16
# File 'app/helpers/effective_bootstrap3_helper.rb', line 12

def nav_link_to(label, path, opts = {})
  (:li, class: ('active' if request.fullpath.include?(path))) do
    link_to(label, path, opts)
  end
end

#tab(label, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/effective_bootstrap3_helper.rb', line 54

def tab(label, &block)
  controls = label.to_s.parameterize.gsub('_', '-')
  active = (@_tab_active == :first || @_tab_active == label)

  @_tab_active = nil if @_tab_active == :first

  if @_tab_mode == :panel # Inserting the label into the tabpanel top
    (:li, role: 'presentation', class: ('active' if active)) do
      (:a, href: '#' + controls, 'aria-controls': controls, 'data-toggle': 'tab', role: 'tab') do
        label
      end
    end
  else # Inserting the content into the tab itself
    (:div, id: controls, class: "tab-pane#{' active' if active}", role: 'tabpanel') do
      yield
    end
  end
end

#tabs(active: nil, &block) ⇒ Object

If you pass active ‘label’ it will make that tab active. Otherwise first.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/effective_bootstrap3_helper.rb', line 39

def tabs(active: nil, &block)
  raise 'expected a block' unless block_given?

  @_tab_mode = :panel
  @_tab_active = (active || :first)

  (:div, role: 'tabpanel') do
    (:ul, class: 'nav nav-tabs', role: 'tablist') { yield } # Yield to tab the first time
  end + (:div, class: 'tab-content') do
    @_tab_mode = :content
    @_tab_active = (active || :first)
    yield # Yield tot ab the second time
  end
end