Module: BootstrapHelper
- Defined in:
- app/helpers/bootstrap_helper.rb
Overview
A collection of view helpers to assist with rendering bootstrap components
Instance Method Summary collapse
-
#alert(type = :default, options = {}) ⇒ Object
<div class=“alert alert-warning” role=“alert”> block_content </div>.
-
#append_class!(options, klass) ⇒ Hash
Mutates the input html_options hash to add klass to the css classes while maintaining any existing classes.
- #bs_column(size = 6, screen = 'md') ⇒ Object
- #bs_custom_panel(type, body_type, body_options, options, &block) ⇒ Object
- #bs_select(*args) ⇒ Object
- #form_collection(label, field, help = nil) ⇒ Object
-
#form_group ⇒ Object
<div class=“col-md-size form-group sqs-form”></div>.
- #link_panel(type = :default, options = {}) ⇒ Object
- #list_panel(type = :default, options = {}) ⇒ Object
-
#loading_bar(id = 'update_loader', show: false, text: 'Loading') ⇒ Object
rubocop:disable Layout/LineLength <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> rubocop:enable Layout/LineLength.
-
#page_title(title, subtitle = nil, titlecase: true, badges: []) ⇒ Object
<div class=“page-header”> <h1>Title <small>subtitle</small></h1> </div> rubocop:todo Metrics/MethodLength.
-
#pagination(collection) ⇒ Object
rubocop:enable Metrics/MethodLength.
- #panel(type = :default, options = {}) ⇒ Object
- #panel_no_body(type = :default, options = {}) ⇒ Object
-
#progress_bar(count) ⇒ Object
rubocop:todo Metrics/MethodLength.
- #render_radio_section(_form, _field_name, sections, field) ⇒ Object
- #render_section(form, field_name, sections, field) ⇒ Object
- #summary(type = :default, options = {}) ⇒ Object
Instance Method Details
#alert(type = :default, options = {}) ⇒ Object
34 35 36 37 38 |
# File 'app/helpers/bootstrap_helper.rb', line 34 def alert(type = :default, = {}, &) [:role] ||= 'alert' append_class!(, "alert alert-#{type}") tag.div(**, &) end |
#append_class!(options, klass) ⇒ Hash
Mutates the input html_options hash to add klass to the css classes while maintaining any existing classes
175 176 177 178 179 |
# File 'app/helpers/bootstrap_helper.rb', line 175 def append_class!(, klass) [:class] = Array([:class]) [:class] << klass end |
#bs_column(size = 6, screen = 'md') ⇒ Object
99 100 101 |
# File 'app/helpers/bootstrap_helper.rb', line 99 def bs_column(size = 6, screen = 'md', &) tag.div(class: "col-#{screen}-#{size}", &) end |
#bs_custom_panel(type, body_type, body_options, options, &block) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/helpers/bootstrap_helper.rb', line 22 def bs_custom_panel(type, body_type, , , &block) title = .delete(:title) append_class!(, "ss-card card-style-#{type}") tag.div(**) do concat tag.h3(title, class: 'card-header-custom') unless title.nil? concat content_tag(body_type, , &block) end end |
#bs_select(*args) ⇒ Object
158 159 160 161 162 163 |
# File 'app/helpers/bootstrap_helper.rb', line 158 def bs_select(*args) hashes = args.last(2).count { |arg| arg.respond_to?(:keys) } (2 - hashes).times { args << {} } append_class!(args.last, 'custom-select') select(*args) end |
#form_collection(label, field, help = nil) ⇒ Object
154 155 156 |
# File 'app/helpers/bootstrap_helper.rb', line 154 def form_collection(label, field, help = nil) form_group { bs_column(2, 'md') { label } << bs_column(10, 'md') { field << help_text { raw(help) } } } end |
#form_group ⇒ Object
95 96 97 |
# File 'app/helpers/bootstrap_helper.rb', line 95 def form_group(&) tag.div(class: 'form-group row sqs-form', &) end |
#link_panel(type = :default, options = {}) ⇒ Object
14 15 16 |
# File 'app/helpers/bootstrap_helper.rb', line 14 def link_panel(type = :default, = {}, &) bs_custom_panel(type, :div, { class: 'link-panel' }, , &) end |
#list_panel(type = :default, options = {}) ⇒ Object
10 11 12 |
# File 'app/helpers/bootstrap_helper.rb', line 10 def list_panel(type = :default, = {}, &) bs_custom_panel(type, :ul, { class: 'list-group list-group-flush' }, , &) end |
#loading_bar(id = 'update_loader', show: false, text: 'Loading') ⇒ Object
rubocop:disable Layout/LineLength <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> rubocop:enable Layout/LineLength
129 130 131 132 133 134 135 |
# File 'app/helpers/bootstrap_helper.rb', line 129 def (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
Title subtitle
rubocop:todo Metrics/MethodLength
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/bootstrap_helper.rb', line 69 def page_title(title, subtitle = nil, titlecase: true, badges: []) # rubocop:todo Metrics/AbcSize 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
rubocop:enable Metrics/MethodLength
90 91 92 |
# File 'app/helpers/bootstrap_helper.rb', line 90 def pagination(collection) will_paginate collection, renderer: BootstrapPagination::Rails, previous_label: '«', next_label: '»' end |
#panel(type = :default, options = {}) ⇒ Object
6 7 8 |
# File 'app/helpers/bootstrap_helper.rb', line 6 def panel(type = :default, = {}, &) bs_custom_panel(type, :div, { class: 'card-body' }, , &) end |
#panel_no_body(type = :default, options = {}) ⇒ Object
18 19 20 |
# File 'app/helpers/bootstrap_helper.rb', line 18 def panel_no_body(type = :default, = {}, &) bs_custom_panel(type, :div, {}, , &) end |
#progress_bar(count) ⇒ Object
rubocop:todo Metrics/MethodLength
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/helpers/bootstrap_helper.rb', line 103 def (count) # rubocop:todo Metrics/MethodLength 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
147 148 149 150 151 152 |
# File 'app/helpers/bootstrap_helper.rb', line 147 def render_radio_section(_form, _field_name, sections, field) label = tag.label(sections.label, **sections.) << 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
137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/bootstrap_helper.rb', line 137 def render_section(form, field_name, sections, field) label = form.label(field_name, sections.label, sections.) << tag.span( sections.edit_info, class: 'property_edit_info' ) help = sections.help form_collection(label, field, help) end |
#summary(type = :default, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/helpers/bootstrap_helper.rb', line 51 def summary(type = :default, = {}) # rubocop:todo Metrics/MethodLength [:title] ||= 'Summary' bs_custom_panel(type, :table, { class: 'table table-summary' }, ) do yield.each do |key, value| concat( tag.tr do concat tag.th(key) concat tag.td(value) end ) end end end |