Module: BootstrapHelper

Defined in:
app/helpers/bootstrap_helper.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#alert(type = :default, options = {}, &block) ⇒ Object

<div class=“alert alert-warning” role=“alert”>

block_content

</div>


31
32
33
34
35
36
# File 'app/helpers/bootstrap_helper.rb', line 31

def alert(type = :default, options = {}, &block)
  options[:class] ||= []
  options[:role] ||= 'alert'
  options[:class] << " alert alert-#{type}"
  tag.div(options, &block)
end

#bs_column(size = 6, screen = 'md', &block) ⇒ Object


92
93
94
# File 'app/helpers/bootstrap_helper.rb', line 92

def bs_column(size = 6, screen = 'md', &block)
  tag.div(class: "col-#{screen}-#{size}", &block)
end

#bs_custom_panel(type, body_type, body_options, options, &block) ⇒ Object


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

def bs_custom_panel(type, body_type, body_options, options, &block)
  title = options.delete(:title)
  options[:class] ||= []
  options[:class] << " ss-card card-style-#{type}"
  tag.div(options) do
    concat tag.h3(title, class: 'card-header-custom') unless title.nil?
    concat (body_type, body_options, &block)
  end
end

#bs_select(*args) ⇒ Object


148
149
150
151
152
153
154
155
156
# File 'app/helpers/bootstrap_helper.rb', line 148

def bs_select(*args)
  hashes = args[-2, 2].count { |arg| arg.respond_to?(:keys) }
  (2 - hashes).times do
    args << {}
  end
  args.last[:class] ||= ''
  args.last[:class] << ' custom-select'
  select(*args)
end

#form_collection(label, field, help = nil) ⇒ Object


139
140
141
142
143
144
145
146
# File 'app/helpers/bootstrap_helper.rb', line 139

def form_collection(label, field, help = nil)
  form_group do
    bs_column(2, 'md') { label } <<
      bs_column(10, 'md') do
        field << help_text { raw(help) }
      end
  end
end

#form_group(&block) ⇒ Object

<div class=“col-md-size form-group sqs-form”></div>


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

def form_group(&block)
  tag.div(class: 'form-group row sqs-form', &block)
end

10
11
12
# File 'app/helpers/bootstrap_helper.rb', line 10

def link_panel(type = :default, options = {}, &block)
  bs_custom_panel(type, :div, { class: 'link-panel' }, options, &block)
end

#list_panel(type = :default, options = {}, &block) ⇒ Object


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

def list_panel(type = :default, options = {}, &block)
  bs_custom_panel(type, :ul, { class: 'list-group list-group-flush' }, options, &block)
end

#loading_bar(id = 'update_loader', show: false, text: 'Loading') ⇒ Object

<div class=“progress”>

<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 45%">
  <span class="sr-only">45% Complete</span>
</div>

</div>


116
117
118
119
120
121
122
# File 'app/helpers/bootstrap_helper.rb', line 116

def loading_bar(id = 'update_loader', show: false, text: 'Loading')
  tag.div(class: 'loading-bar-placeholder') do
    tag.div(id: id, class: 'loading-bar-container', style: show ? '' : 'display: none;') do
      tag.div(text, class: 'loading-bar', role: 'progressbar')
    end
  end
end

#page_title(title, subtitle = nil, titlecase: true, badges: []) ⇒ Object

<div class=“page-header”>

<h1>Title <small>subtitle</small></h1>

</div>


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/bootstrap_helper.rb', line 64

def page_title(title, subtitle = nil, titlecase: true, badges: [])
  tag.div(class: 'page-header') do
    title_class = title.length > 25 ? 'title-long' : 'title-short'
    tag.h1(class: title_class) do
      if titlecase
        concat title.titleize
      else
        concat title
      end
      concat ' '
      concat tag.span(subtitle, class: 'subtitle') if subtitle.present?
      badges.each do |badge_text|
        concat ' '
        concat badge(badge_text, type: 'title-badge')
      end
    end
  end
end

#pagination(collection) ⇒ Object


83
84
85
# File 'app/helpers/bootstrap_helper.rb', line 83

def pagination(collection)
  will_paginate collection, renderer: BootstrapPagination::Rails, previous_label: '&laquo;', next_label: '&raquo;'
end

#panel(type = :default, options = {}, &block) ⇒ Object


2
3
4
# File 'app/helpers/bootstrap_helper.rb', line 2

def panel(type = :default, options = {}, &block)
  bs_custom_panel(type, :div, { class: 'card-body' }, options, &block)
end

#panel_no_body(type = :default, options = {}, &block) ⇒ Object


14
15
16
# File 'app/helpers/bootstrap_helper.rb', line 14

def panel_no_body(type = :default, options = {}, &block)
  bs_custom_panel(type, :div, {}, options, &block)
end

#progress_bar(count) ⇒ Object


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

def progress_bar(count)
  css_class = if count < 25
                'bg-danger'
              elsif count > 99
                'bg-success'
              else
                'bg-warning'
              end
  tag.span(count, style: 'display:none') <<
    tag.div(class: 'progress') do
      tag.div("#{count}%", class: ['progress-bar', 'progress-bar-striped', css_class], role: 'progressbar',
                           style: "width: #{count}%;")
    end
end

#render_radio_section(_form, _field_name, sections, field) ⇒ Object


131
132
133
134
135
136
137
# File 'app/helpers/bootstrap_helper.rb', line 131

def render_radio_section(_form, _field_name, sections, field)
  label = tag.label(sections.label, sections.label_options) <<
          tag.span(sections.edit_info, class: 'property_edit_info')
  help = sections.help
  tag.legend(sections.label, class: 'sr-only') <<
    form_collection(label, field, help)
end

#render_section(form, field_name, sections, field) ⇒ Object


124
125
126
127
128
129
# File 'app/helpers/bootstrap_helper.rb', line 124

def render_section(form, field_name, sections, field)
  label = form.label(field_name, sections.label, sections.label_options) <<
          tag.span(sections.edit_info, class: 'property_edit_info')
  help = sections.help
  form_collection(label, field, help)
end

#summary(type = :default, options = {}) ⇒ Object

Summary composites a panel with a table to deliver a list of key-value pairs

<div class="card card-default">
  <h3 class="card-header">Summary</h3>
  <table class='table table-summary'>
    <tr>
      <th>Array[0][0]</th>
      <td>Array[0][1]</td>
    </tr>
  </table>
</div>

49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/bootstrap_helper.rb', line 49

def summary(type = :default, options = {})
  options[:title] ||= 'Summary'
  bs_custom_panel(type, :table, { class: 'table table-summary' }, options) do
    yield.each do |key, value|
      concat(tag.tr do
        concat tag.th(key)
        concat tag.td(value)
      end)
    end
  end
end