Module: BootstrapConcerns::ComponentsHelper

Defined in:
lib/bootstrap_concerns/components_helper.rb

Constant Summary collapse

MARGIN =
"mb-3".freeze

Instance Method Summary collapse

Instance Method Details

#assign_iconObject



5
6
7
# File 'lib/bootstrap_concerns/components_helper.rb', line 5

def assign_icon
  icon("box-arrow-in-left", "Assign")
end

#boolean_false_iconObject



9
10
11
# File 'lib/bootstrap_concerns/components_helper.rb', line 9

def boolean_false_icon
  icon("x-circle-fill")
end

#boolean_true_iconObject



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 bs_button_tag(content_or_options = nil, options = nil, &)
  normalized_options =
    if content_or_options.is_a?(Hash)
      content_or_options
    else
      options ||= {}
    end

  normalized_options.merge!(Option.options_with_button_class(normalized_options))

  button_tag(content_or_options, options, &)
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 bs_button_to(name = nil, options = nil, html_options = nil, &)
  bs_link_or_button_to(:button_to, name, options, html_options, &)
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?

  (:div, class: "alert alert-danger alert-dismissible fade show #{MARGIN}") do
    concat (:h5, "Errors")
    concat(
      (:ul, class: "mb-0") do
        record.errors.full_messages.each do |message|
          concat (:li, message)
        end
      end
    )
    concat (: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, **options, &)
  form_with(model: model, **options) do |form|
    concat(bs_errors(model)) if model
    concat(
      (:div, class: "row") do
        (:div, class: "col-md-6") do
          yield(form)
        end
      end
    )
  end
end


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 bs_link_or_button_to(method_name, name, options, html_options, &)
  normalized_html_options =
    if block_given?
      options ||= {}
    else
      html_options ||= {}
    end

  normalized_html_options.merge!(Option.options_with_button_class(normalized_html_options))

  public_send(
    method_name,
    name,
    options,
    html_options,
    &
  )
end


82
83
84
# File 'lib/bootstrap_concerns/components_helper.rb', line 82

def bs_link_to(name = nil, options = nil, html_options = nil, &)
  bs_link_or_button_to(:link_to, name, options, html_options, &)
end

#bs_search_colObject



86
87
88
# File 'lib/bootstrap_concerns/components_helper.rb', line 86

def bs_search_col(&)
  (:div, class: "col-12 col-sm #{MARGIN}", &)
end

#bs_search_submit_colObject



90
91
92
93
94
95
96
# File 'lib/bootstrap_concerns/components_helper.rb', line 90

def bs_search_submit_col
  (:div, class: "col-auto #{MARGIN}") do
    (:button, BootstrapConcerns::Option.options_with_button_class) do
      search_icon
    end
  end
end

#bs_tableObject



146
147
148
149
150
# File 'lib/bootstrap_concerns/components_helper.rb', line 146

def bs_table(&)
   :div, class: "table-responsive" do
    (:table, class: "table table-striped table-sm align-middle", &)
  end
end

#copy_iconObject



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_iconObject



106
107
108
# File 'lib/bootstrap_concerns/components_helper.rb', line 106

def download_icon
  icon("download", "Download")
end

#edit_iconObject



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 = ("i", nil, class: "bi bi-#{name}")
  text ? i + (:span, text, class: "ms-1 d-none d-sm-inline") : i
end

#import_iconObject



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_iconObject



142
143
144
# File 'lib/bootstrap_concerns/components_helper.rb', line 142

def rename_icon
  icon("input-cursor-text", "Rename")
end

#search_iconObject



152
153
154
# File 'lib/bootstrap_concerns/components_helper.rb', line 152

def search_icon
  icon("search", "Search")
end