Module: EffectiveBootstrap3Helper
- Defined in:
- app/helpers/effective_bootstrap3_helper.rb
Instance Method Summary collapse
- #approve_icon_to(path, options = {}) ⇒ Object
- #destroy_icon_to(path, options = {}) ⇒ Object
- #edit_icon_to(path, options = {}) ⇒ Object
- #glyphicon_tag(icon, options = {}) ⇒ Object
- #glyphicon_to(icon, path, options = {}) ⇒ Object (also: #bootstrap_icon_to, #glyph_icon_to)
- #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.
- #ok_icon_to(path, options = {}) ⇒ Object
- #remove_icon_to(path, options = {}) ⇒ Object
- #settings_icon_to(path, options = {}) ⇒ Object
-
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere.
- #tab(label, options = {}, &block) ⇒ Object
-
#tabs(active: nil, panel: {}, list: {}, content: {}, &block) ⇒ Object
If you pass active ‘label’ it will make that tab active.
Instance Method Details
#approve_icon_to(path, options = {}) ⇒ Object
98 99 100 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 98 def approve_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'Approve'}.merge()) end |
#destroy_icon_to(path, options = {}) ⇒ Object
85 86 87 88 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 85 def destroy_icon_to(path, = {}) defaults = {title: 'Destroy', data: {method: :delete, confirm: 'Delete this item?'}} glyphicon_to('trash', path, defaults.merge()) end |
#edit_icon_to(path, options = {}) ⇒ Object
81 82 83 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 81 def edit_icon_to(path, = {}) glyphicon_to('edit', path, {title: 'Edit'}.merge()) end |
#glyphicon_tag(icon, options = {}) ⇒ Object
106 107 108 109 110 111 112 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 106 def glyphicon_tag(icon, = {}) if icon.to_s.start_with?('glyphicon-') content_tag(:span, '', {class: "glyphicon #{icon}"}.merge()) else content_tag(:span, '', {class: "glyphicon glyphicon-#{icon}"}.merge()) end end |
#glyphicon_to(icon, path, options = {}) ⇒ Object Also known as: bootstrap_icon_to, glyph_icon_to
114 115 116 117 118 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 114 def glyphicon_to(icon, path, = {}) content_tag(:a, .merge(href: path)) do glyphicon_tag(icon) end end |
#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 |
#ok_icon_to(path, options = {}) ⇒ Object
94 95 96 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 94 def ok_icon_to(path, = {}) glyphicon_to('ok', path, {title: 'OK'}.merge()) end |
#remove_icon_to(path, options = {}) ⇒ Object
102 103 104 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 102 def remove_icon_to(path, = {}) glyphicon_to('remove', path, {title: 'Remove'}.merge()) end |
#settings_icon_to(path, options = {}) ⇒ Object
90 91 92 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 90 def settings_icon_to(path, = {}) glyphicon_to('cog', path, {title: 'Settings'}.merge()) end |
#show_icon_to(path, options = {}) ⇒ Object
Icon Helpers for actions_column or elsewhere
77 78 79 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 77 def show_icon_to(path, = {}) glyphicon_to('eye-open', path, {title: 'Show'}.merge()) end |
#tab(label, options = {}, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/effective_bootstrap3_helper.rb', line 54 def tab(label, = {}, &block) controls = .delete(:controls) || label.to_s.parameterize.gsub('_', '-') controls = controls[1..-1] if controls[0] == '#' 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 classes = ['tab-pane', ('active' if active), [:class].presence].compact.join(' ') content_tag(:div, id: controls, class: classes, role: 'tabpanel') do yield end end end |
#tabs(active: nil, panel: {}, list: {}, content: {}, &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, panel: {}, list: {}, content: {}, &block) raise 'expected a block' unless block_given? @_tab_mode = :panel @_tab_active = (active || :first) content_tag(:div, {role: 'tabpanel'}.merge(panel)) do content_tag(:ul, {class: 'nav nav-tabs', role: 'tablist'}.merge(list)) { yield } # Yield to tab the first time end + content_tag(:div, {class: 'tab-content'}.merge(content)) do @_tab_mode = :content @_tab_active = (active || :first) yield # Yield tot ab the second time end end |