Module: EffectiveBootstrap3Helper

Defined in:
app/helpers/effective_bootstrap3_helper.rb

Instance Method Summary collapse

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, options = {})
  glyphicon_to('ok', path, {title: 'Approve'}.merge(options))
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, options = {})
  defaults = {title: 'Destroy', data: {method: :delete, confirm: 'Delete this item?'}}
  glyphicon_to('trash', path, defaults.merge(options))
end

#edit_icon_to(path, options = {}) ⇒ Object



81
82
83
# File 'app/helpers/effective_bootstrap3_helper.rb', line 81

def edit_icon_to(path, options = {})
  glyphicon_to('edit', path, {title: 'Edit'}.merge(options))
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, options = {})
  if icon.to_s.start_with?('glyphicon-')
    (:span, '', {class: "glyphicon #{icon}"}.merge(options))
  else
    (:span, '', {class: "glyphicon glyphicon-#{icon}"}.merge(options))
  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, options = {})
  (:a, options.merge(href: path)) do
    glyphicon_tag(icon)
  end
end


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', 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 = {})
  (: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, options = {})
  glyphicon_to('ok', path, {title: 'OK'}.merge(options))
end

#remove_icon_to(path, options = {}) ⇒ Object



102
103
104
# File 'app/helpers/effective_bootstrap3_helper.rb', line 102

def remove_icon_to(path, options = {})
  glyphicon_to('remove', path, {title: 'Remove'}.merge(options))
end

#settings_icon_to(path, options = {}) ⇒ Object



90
91
92
# File 'app/helpers/effective_bootstrap3_helper.rb', line 90

def settings_icon_to(path, options = {})
  glyphicon_to('cog', path, {title: 'Settings'}.merge(options))
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, options = {})
  glyphicon_to('eye-open', path, {title: 'Show'}.merge(options))
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, options = {}, &block)
  controls = options.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
    (: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
    classes = ['tab-pane', ('active' if active), options[:class].presence].compact.join(' ')
    (: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)

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