Module: BootstrapConcerns::ComponentsHelper
- Defined in:
- lib/bootstrap_concerns/components_helper.rb
Constant Summary collapse
- MARGIN =
"mb-3".freeze
Instance Method Summary collapse
- #assign_icon ⇒ Object
- #boolean_false_icon ⇒ Object
- #boolean_true_icon ⇒ Object
-
#bs_anchor_to(name, anchor, **html_options) ⇒ Object
A link to a section of the current page.
- #bs_button_tag(content_or_options = nil, options = nil) ⇒ Object
- #bs_button_to(name = nil, options = nil, html_options = nil) ⇒ Object
- #bs_errors(record) ⇒ Object
- #bs_form_with(model: false, **options) ⇒ Object
- #bs_link_or_button_to(method_name, name, options, html_options) ⇒ Object
- #bs_link_to(name = nil, options = nil, html_options = nil) ⇒ Object
- #bs_search_col ⇒ Object
- #bs_search_submit_col ⇒ Object
- #bs_table ⇒ Object
- #copy_icon ⇒ Object
- #delete_icon(text = "Delete") ⇒ Object
- #download_icon ⇒ Object
- #edit_icon ⇒ Object
- #export_icon(label = "Export") ⇒ Object
- #flash_alert_color(key) ⇒ Object
- #icon(name, text = nil) ⇒ Object
- #import_icon ⇒ Object
- #new_icon(label = "New") ⇒ Object
- #rename_icon ⇒ Object
- #search_icon ⇒ Object
Instance Method Details
#assign_icon ⇒ Object
5 6 7 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 5 def assign_icon icon("box-arrow-in-left", "Assign") end |
#boolean_false_icon ⇒ Object
9 10 11 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 9 def boolean_false_icon icon("x-circle-fill") end |
#boolean_true_icon ⇒ Object
13 14 15 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 13 def boolean_true_icon icon("check-circle-fill") end |
#bs_anchor_to(name, anchor, **html_options) ⇒ Object
A link to a section of the current page. A bare fragment resolves against the address bar, so the
query string survives the click, and the link opts out of Turbo Drive, which would fetch the
document again where the browser simply scrolls. Everything else is bs_link_to's: a button unless
told button: false.
21 22 23 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 21 def bs_anchor_to(name, anchor, **) bs_link_to(name, "##{anchor}", .deep_merge(data: {turbo: false})) end |
#bs_button_tag(content_or_options = nil, options = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 25 def ( = nil, = nil, &) = if .is_a?(Hash) else ||= {} end .merge!(Option.()) (, , &) end |
#bs_button_to(name = nil, options = nil, html_options = nil) ⇒ Object
38 39 40 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 38 def (name = nil, = nil, = nil, &) (:button_to, name, , , &) end |
#bs_errors(record) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 42 def bs_errors(record) return if record.errors.empty? content_tag(:div, class: "alert alert-danger alert-dismissible fade show #{MARGIN}") do concat content_tag(:h5, "Errors") concat( content_tag(:ul, class: "mb-0") do record.errors..each do || concat content_tag(:li, ) end end ) concat content_tag(:button, nil, type: "button", class: "btn-close", data: {bs_dismiss: "alert"}) end end |
#bs_form_with(model: false, **options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 58 def bs_form_with(model: false, **, &) form_with(model: model, **) do |form| concat(bs_errors(model)) if model concat( content_tag(:div, class: "row") do content_tag(:div, class: "col-md-6") do yield(form) end end ) end end |
#bs_link_or_button_to(method_name, name, options, html_options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 71 def (method_name, name, , , &) = if block_given? ||= {} else ||= {} end = .delete(:button) { true } .merge!(Option.()) if public_send( method_name, name, , , & ) end |
#bs_link_to(name = nil, options = nil, html_options = nil) ⇒ Object
91 92 93 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 91 def bs_link_to(name = nil, = nil, = nil, &) (:link_to, name, , , &) end |
#bs_search_col ⇒ Object
95 96 97 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 95 def bs_search_col(&) content_tag(:div, class: "col-12 col-sm #{MARGIN}", &) end |
#bs_search_submit_col ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 99 def bs_search_submit_col content_tag(:div, class: "col-auto #{MARGIN}") do content_tag(:button, BootstrapConcerns::Option.) do search_icon end end end |
#bs_table ⇒ Object
155 156 157 158 159 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 155 def bs_table(&) content_tag :div, class: "table-responsive" do content_tag(:table, class: "table table-striped table-sm align-middle", &) end end |
#copy_icon ⇒ Object
107 108 109 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 107 def copy_icon icon("files", "Copy") end |
#delete_icon(text = "Delete") ⇒ Object
111 112 113 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 111 def delete_icon(text = "Delete") icon("trash", text) end |
#download_icon ⇒ Object
115 116 117 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 115 def download_icon icon("download", "Download") end |
#edit_icon ⇒ Object
119 120 121 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 119 def edit_icon icon("pencil-square", "Edit") end |
#export_icon(label = "Export") ⇒ Object
123 124 125 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 123 def export_icon(label = "Export") icon("filetype-xlsx", label) end |
#flash_alert_color(key) ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 127 def flash_alert_color(key) case key.to_s when "notice" "success" when "alert" "danger" else key end end |
#icon(name, text = nil) ⇒ Object
138 139 140 141 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 138 def icon(name, text = nil) i = content_tag("i", nil, class: "bi bi-#{name}") text ? i + content_tag(:span, text, class: "ms-1 d-none d-sm-inline") : i end |
#import_icon ⇒ Object
143 144 145 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 143 def import_icon icon("box-arrow-in-down", "Import") end |
#new_icon(label = "New") ⇒ Object
147 148 149 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 147 def new_icon(label = "New") icon("file-earmark-plus", label) end |
#rename_icon ⇒ Object
151 152 153 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 151 def rename_icon icon("input-cursor-text", "Rename") end |
#search_icon ⇒ Object
161 162 163 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 161 def search_icon icon("search", "Search") end |