Module: EffectiveBootstrap3Helper
- Defined in:
- app/helpers/effective_bootstrap3_helper.rb
Instance Method Summary collapse
- #nav_dropdown(label, link_class: [], list_class: [], &block) ⇒ Object
-
#nav_link_to(label, path, opts = {}) ⇒ Object
%ul.nav.navbar-nav.navbar-right = nav_link_to ‘Sign In’, new_user_session_path = nav_dropdown ‘Settings’ do = nav_link_to ‘Account Settings’, user_settings_path %li.divider = nav_link_to ‘Sign In’, new_user_session_path, method: :delete.
- #tab(label, &block) ⇒ Object
-
#tabs(active: nil, &block) ⇒ Object
If you pass active ‘label’ it will make that tab active.
Instance Method Details
#nav_dropdown(label, link_class: [], list_class: [], &block) ⇒ Object
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? content_tag(:li, class: 'dropdown') do content_tag(:a, class: 'dropdown-toggle', href: '#', 'data-toggle': 'dropdown', role: 'button', 'aria-haspopup': 'true', 'aria-expanded': 'false') do label.html_safe + content_tag(:span, '', class: 'caret') end + content_tag(:ul, class: 'dropdown-menu') { yield } end end |
#nav_link_to(label, path, opts = {}) ⇒ Object
%ul.nav.navbar-nav.navbar-right
= nav_link_to 'Sign In', new_user_session_path
= nav_dropdown 'Settings' do
= nav_link_to 'Account Settings', user_settings_path
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 = {}) content_tag(: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 content_tag(:li, role: 'presentation', class: ('active' if active)) do content_tag(:a, href: '#' + controls, 'aria-controls': controls, 'data-toggle': 'tab', role: 'tab') do label end end else # Inserting the content into the tab itself content_tag(: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) content_tag(:div, role: 'tabpanel') do content_tag(:ul, class: 'nav nav-tabs', role: 'tablist') { yield } # Yield to tab the first time end + content_tag(:div, class: 'tab-content') do @_tab_mode = :content @_tab_active = (active || :first) yield # Yield tot ab the second time end end |