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_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_button_tag(content_or_options = nil, options = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 17 def ( = nil, = nil, &) = if .is_a?(Hash) else ||= {} end .merge!(Option.()) (, , &) end |
#bs_button_to(name = nil, options = nil, html_options = nil) ⇒ Object
30 31 32 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 30 def (name = nil, = nil, = nil, &) (:button_to, name, , , &) end |
#bs_errors(record) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 34 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
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 50 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 63 def (method_name, name, , , &) = if block_given? ||= {} else ||= {} end .merge!(Option.()) public_send( method_name, name, , , & ) end |
#bs_link_to(name = nil, options = nil, html_options = nil) ⇒ Object
82 83 84 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 82 def bs_link_to(name = nil, = nil, = nil, &) (:link_to, name, , , &) end |
#bs_search_col ⇒ Object
86 87 88 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 86 def bs_search_col(&) content_tag(:div, class: "col-12 col-sm #{MARGIN}", &) end |
#bs_search_submit_col ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 90 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
146 147 148 149 150 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 146 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
98 99 100 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 98 def copy_icon icon("files", "Copy") end |
#delete_icon(text = "Delete") ⇒ Object
102 103 104 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 102 def delete_icon(text = "Delete") icon("trash", text) end |
#download_icon ⇒ Object
106 107 108 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 106 def download_icon icon("download", "Download") end |
#edit_icon ⇒ Object
110 111 112 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 110 def edit_icon icon("pencil-square", "Edit") end |
#export_icon(label = "Export") ⇒ Object
114 115 116 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 114 def export_icon(label = "Export") icon("filetype-xlsx", label) end |
#flash_alert_color(key) ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 118 def flash_alert_color(key) case key.to_s when "notice" "success" when "alert" "danger" else key end end |
#icon(name, text = nil) ⇒ Object
129 130 131 132 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 129 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
134 135 136 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 134 def import_icon icon("box-arrow-in-down", "Import") end |
#new_icon(label = "New") ⇒ Object
138 139 140 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 138 def new_icon(label = "New") icon("file-earmark-plus", label) end |
#rename_icon ⇒ Object
142 143 144 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 142 def rename_icon icon("input-cursor-text", "Rename") end |
#search_icon ⇒ Object
152 153 154 |
# File 'lib/bootstrap_concerns/components_helper.rb', line 152 def search_icon icon("search", "Search") end |