Module: BootstrapHelper

Defined in:
app/helpers/bootstrap_helper.rb

Instance Method Summary collapse

Instance Method Details

#boot_alert(*args, &block) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/bootstrap_helper.rb', line 73

def boot_alert(*args, &block)
  if block_given?
    type = args[0]
    content = capture(&block)
  else
    content = args[0]
    type    = args[1]
  end

  type ||= 'info'
  (:div, :class => "alert alert-#{boot_alert_name(type)}") do
    link_to('×'.html_safe, '#', :class => 'close', 'data-dismiss' => 'alert') + content
  end
end

#boot_alert_name(type) ⇒ Object

Messages

Map common rails flash types to bootstrap alert names.



62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/bootstrap_helper.rb', line 62

def boot_alert_name(type)
  case type
  when 'alert'
    'danger'
  when 'notice'
    'info'
  else
    type
  end
end

#boot_form_for(object, *args, &block) ⇒ Object



5
6
7
8
# File 'app/helpers/bootstrap_helper.rb', line 5

def boot_form_for(object, *args, &block)
  options = args.extract_options!
  simple_form_for(object, *(args << options.merge(builder: BootFormBuilder)), &block)
end

#boot_icon(type) ⇒ Object

Icons



36
37
38
39
# File 'app/helpers/bootstrap_helper.rb', line 36

def boot_icon(type)
  classes = I18nRailsHelpers.boot_icon_class_template % [type]
  (:i, '', :class => classes)
end

#boot_label(content, type = nil) ⇒ Object

Labels



43
44
45
46
47
48
# File 'app/helpers/bootstrap_helper.rb', line 43

def boot_label(content, type = nil)
  return "" unless content.present?

  classes = ['label', "label-#{type}"].compact.join(' ')
  (:span, content, :class => classes)
end

#boot_nav_filter(name, entries, type = :link) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'app/helpers/bootstrap_helper.rb', line 148

def boot_nav_filter(name, entries, type = :link)
  refresh_action = (type == :checkbox)

  (:ul, :class => ['nav', 'nav-list']) do
    content = []
    content << boot_nav_header(name, refresh_action)

    entries.each do |entry|
      if entry.is_a? Hash
        title = entry[:title]
        value = entry[:value]
      else
        title = value = entry
      end

      case type
      when :link
        content << boot_nav_li_link(name, value, title)
      when :checkbox
        content << boot_nav_li_checkbox(name, value, title)
      end
    end

    content.join("\n").html_safe
  end
end

#boot_nav_header(title, refresh_action = false) ⇒ Object

Navigation



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/bootstrap_helper.rb', line 94

def boot_nav_header(title, refresh_action = false)
  if title.is_a? Symbol
    title = t("#{title}.title")
  end

  (:li, :class => 'nav-header') do
    content = [title]
    if refresh_action
      content << (:button, :type => "submit", :style => 'border: none; background-color: transparent; float: right') do
        (:i, "", :class => 'icon-refresh')
      end
    end

    content.join("\n").html_safe
  end
end

#boot_nav_li_checkbox(filter_name, param_value, title = nil, param_name = filter_name, current_value = , classes = [], &content) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/helpers/bootstrap_helper.rb', line 126

def boot_nav_li_checkbox(filter_name, param_value, title = nil, param_name = filter_name, current_value = params[param_name], classes = [], &content)
  active = current_value.include? param_value.to_s
  classes << "active" if active

  title ||= param_value
  title = t("#{filter_name.to_s}.#{title}", :default => title)

  if block_given?
    (:li, :class => classes, &content)
  else
    (:li, :class => classes) do
       'label', :class => 'checkbox' do
        content = []
        content << ('input', '', :type => 'checkbox', :checked => active, :name => "#{param_name}[]", :value => param_value)
        content << title

        content.join("\n").html_safe
      end
    end
  end
end


111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/bootstrap_helper.rb', line 111

def boot_nav_li_link(filter_name, param_value, title = nil, param_name = filter_name, current_value = params[param_name], classes = [], &content)
  classes << "active" if current_value.to_s == param_value.to_s
  title ||= param_value
  title = t("#{filter_name.to_s}.#{title}", :default => title)

  if block_given?
    (:li, :class => classes, &content)
  else
    (:li, :class => classes) do
      url = url_for(params.merge({param_name => param_value}))
      link_to title, url
    end
  end
end

#boot_no_entry_alertObject



88
89
90
# File 'app/helpers/bootstrap_helper.rb', line 88

def boot_no_entry_alert
  boot_alert t('alerts.empty')
end

#boot_page_title(action_or_title = nil, model = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/bootstrap_helper.rb', line 11

def boot_page_title(action_or_title = nil, model = nil, &block)
  if block_given?
    title = capture(&block)
  else
    if action_or_title.is_a? String
      title = action_or_title
    else
      action = action_or_title || action_name
      if action.to_s == 'show' && defined?(resource) && resource.present?
        title = resource.display_name if resource.respond_to?(:display_name)
        title ||= resource.to_s
      else
        title = t_title(action, model)
      end
    end
  end

  content_for :page_title, title
  (:div, :class => 'page-header') do
    (:h1, title)
  end
end

Modal



52
53
54
55
56
57
# File 'app/helpers/bootstrap_helper.rb', line 52

def modal_header(title)
  (:div, :class => 'modal-header') do
    (:button, '&times;'.html_safe, :type => 'button', :class => 'close', 'data-dismiss' => 'modal') +
    (:h3, title)
  end
end