formstrap 0.4.10 → 0.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/app/assets/javascripts/formstrap/controllers/media_controller.js +8 -4
  4. data/app/assets/javascripts/formstrap/controllers/nested_preview_controller.js +8 -1
  5. data/app/assets/javascripts/formstrap.js +12 -5
  6. data/app/models/concerns/formstrap/labelable.rb +2 -1
  7. data/app/views/formstrap/_association.html.erb +1 -0
  8. data/app/views/formstrap/_checkbox.html.erb +1 -0
  9. data/app/views/formstrap/_color.html.erb +1 -0
  10. data/app/views/formstrap/_date.html.erb +1 -0
  11. data/app/views/formstrap/_email.html.erb +1 -0
  12. data/app/views/formstrap/_file.html.erb +1 -0
  13. data/app/views/formstrap/_label.html.erb +5 -0
  14. data/app/views/formstrap/_media.html.erb +2 -1
  15. data/app/views/formstrap/_number.html.erb +1 -0
  16. data/app/views/formstrap/_password.html.erb +1 -0
  17. data/app/views/formstrap/_redactor.html.erb +1 -0
  18. data/app/views/formstrap/_select.html.erb +1 -0
  19. data/app/views/formstrap/_switch.html.erb +2 -1
  20. data/app/views/formstrap/_text.html.erb +2 -1
  21. data/app/views/formstrap/_textarea.html.erb +1 -0
  22. data/app/views/formstrap/_wysiwyg.html.erb +1 -0
  23. data/config/locales/formstrap/de.yml +2 -0
  24. data/config/locales/formstrap/en.yml +2 -0
  25. data/config/locales/formstrap/fr.yml +2 -0
  26. data/config/locales/formstrap/nl.yml +2 -0
  27. data/lib/formstrap/form_builder.rb +1 -1
  28. data/lib/formstrap/version.rb +1 -1
  29. data/lib/formstrap.rb +3 -0
  30. data/lib/generators/install/install_generator.rb +14 -0
  31. data/lib/generators/install/templates/formstrap.rb +6 -0
  32. data/package.json +1 -1
  33. metadata +4 -3
  34. data/app/views/formstrap/shared/_notifications.html.erb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18486c2d275d4a29d8744839fd0838cca5ab46afbe68791cca9df7bc0b0ce77a
4
- data.tar.gz: d446454040507486d85d3bebfe1ddf8894cb0ceead8aa976394b1c74b03ea3ac
3
+ metadata.gz: 1855b6369bcf6ebc3997fd2905d02d6d02c96f2504046b61c76054ecf631f416
4
+ data.tar.gz: 13dc3e27e2105731f56142c0b43ec196d22f06ea4013b036c014a637dbfe2820
5
5
  SHA512:
6
- metadata.gz: 51dc8c2510a3ecde2f41a11d1d80d2ec4cfa59efea121df2ee05ed53226081be53ffed346a8405a8ea0f2256b439964e83b253adab573c10cb3dc755dd924edf
7
- data.tar.gz: 799f3f2070b303d70443b824fc2f808b64248416b04f70230494785762ffc7fd1e4381eca0af3526fd78e12f3970a44f4b0ddb18b54f9af596cba3c9d748e46d
6
+ metadata.gz: bf871cf6c6c50aafd80abaebcdf1756cfa1122657abcedafb4000da51956055f43177d5f3ec74276f1b477c67753464e8eab64aa73714b11da302040f53cf963
7
+ data.tar.gz: 471256a9097d3546d43d69b89f5ea870ca534e22f720b81d99704a51d282f5fa68efce72b4f7406906c8282d7f3969888d9c69ad077851f62dfdcdb18f8d981b
data/README.md CHANGED
@@ -16,6 +16,12 @@ Afterwards, run:
16
16
  bundle
17
17
  ```
18
18
 
19
+ In order to setup the initializer, run the following command:
20
+ ```bash
21
+ rails generate formstrap:install
22
+ ```
23
+
24
+
19
25
  ## Usage
20
26
 
21
27
  ### Getting started
@@ -175,10 +175,12 @@ export default class extends Controller {
175
175
  }
176
176
 
177
177
  togglePlaceholder () {
178
- if (this.activeItems().length > 0) {
179
- this.hidePlaceholder()
180
- } else {
178
+ const count = this.activeItems().length
179
+
180
+ if (count < this.maxActiveItems()) {
181
181
  this.showPlaceholder()
182
+ } else {
183
+ this.hidePlaceholder()
182
184
  }
183
185
  }
184
186
 
@@ -199,7 +201,9 @@ export default class extends Controller {
199
201
  // Copy template
200
202
  let templateHtml = this.templateTarget
201
203
  templateHtml = this.randomizeIds(templateHtml)
202
- this.thumbnailsTarget.insertAdjacentHTML('beforeend', templateHtml)
204
+
205
+ // Add new thumbnail before the last element (thumbnail)
206
+ this.thumbnailsTarget.children[this.thumbnailsTarget.children.length - 1].insertAdjacentHTML('beforebegin', templateHtml)
203
207
 
204
208
  // Set new values
205
209
  const newItem = this.itemTargets.pop()
@@ -133,6 +133,7 @@ export default class extends Controller {
133
133
  const currentName = element.getAttribute('name')
134
134
  const newName = currentName.replace(regex, '$1')
135
135
  const values = this.readValues(element)
136
+
136
137
  values.forEach((value) => {
137
138
  formData.append(newName, value)
138
139
  })
@@ -148,6 +149,12 @@ export default class extends Controller {
148
149
  // Check if the element is a select with multiple selection
149
150
  if (element.tagName.toLowerCase() === 'select' && element.multiple) {
150
151
  return [...element.selectedOptions].map(option => option.value)
152
+ } else if (element.tagName.toLowerCase() === 'input' && element.type === 'checkbox') {
153
+ if (element.checked) {
154
+ return [element.value]
155
+ } else {
156
+ return []
157
+ }
151
158
  } else {
152
159
  return [element.value]
153
160
  }
@@ -162,7 +169,7 @@ export default class extends Controller {
162
169
  opacity: 0;
163
170
  transform-origin: 0 0;
164
171
  width: ${100 / scaleFactor}%;
165
- `
172
+ `
166
173
  this.iframeTarget.setAttribute('style', style)
167
174
  }
168
175
 
@@ -11204,10 +11204,11 @@ var media_controller_default = class extends Controller {
11204
11204
  }
11205
11205
  }
11206
11206
  togglePlaceholder() {
11207
- if (this.activeItems().length > 0) {
11208
- this.hidePlaceholder();
11209
- } else {
11207
+ const count = this.activeItems().length;
11208
+ if (count < this.maxActiveItems()) {
11210
11209
  this.showPlaceholder();
11210
+ } else {
11211
+ this.hidePlaceholder();
11211
11212
  }
11212
11213
  }
11213
11214
  showPlaceholder() {
@@ -11223,7 +11224,7 @@ var media_controller_default = class extends Controller {
11223
11224
  createItem(item) {
11224
11225
  let templateHtml = this.templateTarget;
11225
11226
  templateHtml = this.randomizeIds(templateHtml);
11226
- this.thumbnailsTarget.insertAdjacentHTML("beforeend", templateHtml);
11227
+ this.thumbnailsTarget.children[this.thumbnailsTarget.children.length - 1].insertAdjacentHTML("beforebegin", templateHtml);
11227
11228
  const newItem = this.itemTargets.pop();
11228
11229
  newItem.querySelector('input[name*="[blob_id]"]').value = item.blobId;
11229
11230
  newItem.querySelector('input[name*="[_destroy]"]').value = false;
@@ -11554,6 +11555,12 @@ var nested_preview_controller_default = class extends Controller {
11554
11555
  readValues(element) {
11555
11556
  if (element.tagName.toLowerCase() === "select" && element.multiple) {
11556
11557
  return [...element.selectedOptions].map((option2) => option2.value);
11558
+ } else if (element.tagName.toLowerCase() === "input" && element.type === "checkbox") {
11559
+ if (element.checked) {
11560
+ return [element.value];
11561
+ } else {
11562
+ return [];
11563
+ }
11557
11564
  } else {
11558
11565
  return [element.value];
11559
11566
  }
@@ -11565,7 +11572,7 @@ var nested_preview_controller_default = class extends Controller {
11565
11572
  opacity: 0;
11566
11573
  transform-origin: 0 0;
11567
11574
  width: ${100 / scaleFactor}%;
11568
- `;
11575
+ `;
11569
11576
  this.iframeTarget.setAttribute("style", style);
11570
11577
  }
11571
11578
  scaleFactor() {
@@ -23,7 +23,8 @@ module Formstrap
23
23
  attribute: attribute,
24
24
  form: form,
25
25
  required: required,
26
- text: label
26
+ text: label,
27
+ translatable: translatable
27
28
  }
28
29
  end
29
30
  end
@@ -15,6 +15,7 @@
15
15
  # * +prepend+ - Display as input group with text on the left-hand side
16
16
  # * +remote+ - Hash with all options for remote data fetching
17
17
  # * +wrapper+ - Hash with all options for the surrounding html tag
18
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
18
19
  #
19
20
  # ==== Remote options
20
21
  # * +url+ -- JSON endpoint to fetch data from
@@ -11,6 +11,7 @@
11
11
  # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
12
12
  # * +unchecked_value+ - Value for unchecked state
13
13
  # * +wrapper+ - Hash with all options for the surrounding html tag
14
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
14
15
  #
15
16
  # ==== References
16
17
  # https://headmin.dev/docs/forms/checkbox
@@ -9,6 +9,7 @@
9
9
  # * +hint+ - Informative text to assist with data input. HTML markup is allowed.
10
10
  # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
11
11
  # * +wrapper+ - Hash with all options for the surrounding html tag
12
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
12
13
  #
13
14
  # ==== References
14
15
  # https://headmin.dev/docs/forms/color
@@ -14,6 +14,7 @@
14
14
  # * +plaintext+ - Render input as plain text.
15
15
  # * +prepend+ - Display as input group with text on the left-hand side
16
16
  # * +wrapper+ - Hash with all options for the surrounding html tag
17
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
17
18
  #
18
19
  # ==== References
19
20
  # https://headmin.dev/docs/forms/date
@@ -15,6 +15,7 @@
15
15
  # * +plaintext+ - Render input as plain text.
16
16
  # * +prepend+ - Display as input group with text on the left-hand side
17
17
  # * +wrapper+ - Hash with all options for the surrounding html tag
18
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
18
19
  #
19
20
  # ==== References
20
21
  # https://headmin.dev/docs/forms/email
@@ -15,6 +15,7 @@
15
15
  # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
16
16
  # * +prepend+ - Display as input group with text on the left-hand side
17
17
  # * +wrapper+ - Hash with all options for the surrounding html tag
18
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
18
19
  #
19
20
  # ==== References
20
21
  # https://headmin.dev/docs/forms/file
@@ -1,9 +1,11 @@
1
1
  <%
2
2
  # name: formstrap/label
3
3
  #
4
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
4
5
  # ==== Required parameters
5
6
  # * +form+ - Form object
6
7
  # * +attribute+ - Name of the attribute of the form model
8
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
7
9
  #
8
10
  # ==== Optional parameters
9
11
  # * +text+ - Custom label to be used instead of the attribute
@@ -20,3 +22,6 @@
20
22
 
21
23
  <% label = Formstrap::LabelView.new(local_assigns) %>
22
24
  <%= form.label label.attribute, label.text, label.options %>
25
+ <% if label.translatable %>
26
+ <%= bootstrap_icon "translate", class: "ms-1 text-black text-opacity-50", title: t(".translatable_tooltip") %>
27
+ <% end %>
@@ -17,6 +17,7 @@
17
17
  # * +height+ - Height of the thumbnail
18
18
  # * +exclude_models+ - Array of model names to exclude from selection (e.g. ["User", "Company"])
19
19
  # * +edit_url+ - Placeholder link for the edit page of the attachment. Needs to contain a ":id" part, e.g. "admin_media_edit_url(":id"). This url be opened in a modal
20
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
20
21
  #
21
22
  # ==== References
22
23
  # https://headmin.dev/docs/forms/media
@@ -41,7 +42,7 @@
41
42
  <% end %>
42
43
 
43
44
  <!-- Placeholder -->
44
- <div class="<%= "d-none" if media.attachments.any? %>" data-media-target="placeholder">
45
+ <div data-media-target="placeholder">
45
46
  <a href="<%= media.modal_url %>" data-turbo-frame="modal" data-media-target="modalButton">
46
47
  <%= render "formstrap/shared/thumbnail", media.thumbnail_options %>
47
48
  </a>
@@ -14,6 +14,7 @@
14
14
  # * +plaintext+ - Render input as plain text.
15
15
  # * +prepend+ - Display as input group with text on the left-hand side
16
16
  # * +wrapper+ - Hash with all options for the surrounding html tag
17
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
17
18
  #
18
19
  # ==== References
19
20
  # https://headmin.dev/docs/forms/number
@@ -13,6 +13,7 @@
13
13
  # * +plaintext+ - Render input as plain text.
14
14
  # * +prepend+ - Display as input group with text on the left-hand side
15
15
  # * +wrapper+ - Hash with all options for the surrounding html tag
16
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
16
17
  #
17
18
  # ==== References
18
19
  # https://headmin.dev/docs/forms/password
@@ -12,6 +12,7 @@
12
12
  # * +prepend+ - Display as input group with text on the left-hand side
13
13
  # * +redactor+ - Hash with all options you can pass to redactor JS config
14
14
  # * +wrapper+ - Hash with all options for the surrounding html tag
15
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
15
16
  #
16
17
  # ==== References
17
18
  # https://imperavi.com/redactor/docs
@@ -17,6 +17,7 @@
17
17
  # * +tags+ - Allow options to be created dynamically. This will set the multiple attribute to true
18
18
  # * +wrapper+ - Hash with all options for the surrounding html tag
19
19
  # * +remote+ - Hash with all options for remote data fetching
20
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
20
21
  #
21
22
  # ==== Remote options
22
23
  # * +url+ -- JSON endpoint to fetch data from
@@ -11,6 +11,7 @@
11
11
  # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
12
12
  # * +unchecked_value+ - Value for unchecked state
13
13
  # * +wrapper+ - Hash with all options for the surrounding html tag
14
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
14
15
  #
15
16
  # ==== References
16
17
  # https://headmin.dev/docs/forms/switch
@@ -26,4 +27,4 @@
26
27
  switch = Formstrap::SwitchView.new(local_assigns)
27
28
  %>
28
29
 
29
- <%= render "formstrap/checkbox", switch.options %>
30
+ <%= render "formstrap/checkbox", switch.options %>
@@ -15,6 +15,7 @@
15
15
  # * +plaintext+ - Render input as plain text.
16
16
  # * +prepend+ - Display as input group with text on the left-hand side
17
17
  # * +wrapper+ - Hash with all options for the surrounding html tag
18
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
18
19
  #
19
20
  # ==== References
20
21
  # https://headmin.dev/docs/forms/text
@@ -39,4 +40,4 @@
39
40
  <%= render "formstrap/validation", text.validation_options if text.validate? %>
40
41
  <%= render "formstrap/hint", text.hint_options if text.hint? %>
41
42
  <%= render "formstrap/label", text.label_options if text.append_label? %>
42
- <% end %>
43
+ <% end %>
@@ -13,6 +13,7 @@
13
13
  # * +plaintext+ - Render input as plain text.
14
14
  # * +prepend+ - Display as input group with text on the left-hand side
15
15
  # * +wrapper+ - Hash with all options for the surrounding html tag
16
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
16
17
  #
17
18
  # ==== References
18
19
  # https://headmin.dev/docs/forms/textarea
@@ -10,6 +10,7 @@
10
10
  # * +label+ - Text to display inside label tag. Defaults to the attribute name. Set to false if you don"t want to show a label.
11
11
  # * +toolbar+ - Show toolbar (default true)
12
12
  # * +wrapper+ - Hash with all options for the surrounding html tag
13
+ # * +translatable+ - Adds a translatable icon next to the label if it is set to true. Defaults depends on initializer.
13
14
  #
14
15
  # ==== References
15
16
  # https://imperavi.com/redactor/docs
@@ -7,6 +7,8 @@ de:
7
7
  other: Dateien durchsuchen oder hierher ziehen und ablegen
8
8
  group:
9
9
  save: Speichern
10
+ label:
11
+ translatable_tooltip: Dieses Feld ist übersetzbar und kann je nach Sprache einen anderen Wert enthalten
10
12
  media:
11
13
  modal:
12
14
  close: Schließen
@@ -7,6 +7,8 @@ en:
7
7
  other: Browse files or drag & drop them here
8
8
  group:
9
9
  save: Save
10
+ label:
11
+ translatable_tooltip: This field is translatable and can contain a different value per language
10
12
  media:
11
13
  modal:
12
14
  close: Close
@@ -7,6 +7,8 @@ fr:
7
7
  other: Parcourir les fichiers ou faites les glisser et déposez-les ici
8
8
  group:
9
9
  save: Sauvegarder
10
+ label:
11
+ translatable_tooltip: Ce champ est traduisible et peut contenir une valeur différente selon la langue
10
12
  media:
11
13
  modal:
12
14
  close: Fermer
@@ -7,6 +7,8 @@ nl:
7
7
  other: Kies bestanden of sleep ze hierheen
8
8
  group:
9
9
  save: Opslaan
10
+ label:
11
+ translatable_tooltip: "Dit veld is vertaalbaar en kan per taal een andere waarde bevatten"
10
12
  media:
11
13
  modal:
12
14
  close: Sluiten
@@ -1,7 +1,7 @@
1
1
  module Formstrap
2
2
  class FormBuilder < ActionView::Helpers::FormBuilder
3
3
  def initialize(object_name, object, template, options)
4
- super(object_name, object, template, options)
4
+ super
5
5
 
6
6
  custom_helpers_path = "app/views/formstrap/"
7
7
  @custom_helpers = Dir["#{custom_helpers_path}*.html.erb"].map { |item| item.gsub("#{custom_helpers_path}_", "").split(".").first.to_sym }
@@ -1,3 +1,3 @@
1
1
  module Formstrap
2
- VERSION = "0.4.10"
2
+ VERSION = "0.4.12"
3
3
  end
data/lib/formstrap.rb CHANGED
@@ -6,6 +6,9 @@ require_relative "formstrap/configuration"
6
6
  require "formstrap/form_builder"
7
7
  require "formstrap/form_helper"
8
8
 
9
+ # Load generators
10
+ Dir[File.join(__dir__, "generators", "**", "*_generator.rb")].each { |g| require g }
11
+
9
12
  module Formstrap
10
13
  mattr_accessor :configuration, default: Formstrap::Configuration.new
11
14
 
@@ -0,0 +1,14 @@
1
+ # lib/generators/my_engine/my_initializer/my_initializer_generator.rb
2
+ require "rails/generators"
3
+
4
+ module Formstrap
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("templates", __dir__)
8
+
9
+ def create_initializer_file
10
+ template "formstrap.rb", "config/initializers/formstrap.rb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ Formstrap.configure do |config|
2
+ config.open_ai_key = "your-open-ai-key"
3
+
4
+ # If set to true, this turns on the AI feature on all the redactors appliation wide
5
+ config.ai = false
6
+ end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontierdotbe/formstrap",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Bootstrap-powered Form Helpers",
5
5
  "module": "app/assets/javascripts/formstrap.js",
6
6
  "main": "app/assets/javascripts/formstrap.js",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jef Vlamings
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-10 00:00:00.000000000 Z
11
+ date: 2025-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An extensive Bootstrap form library to power your Ruby On Rails application.
14
14
  email:
@@ -172,7 +172,6 @@ files:
172
172
  - app/views/formstrap/pagination/_infinite.html.erb
173
173
  - app/views/formstrap/repeater/_row.html.erb
174
174
  - app/views/formstrap/shared/_nested_preview.html.erb
175
- - app/views/formstrap/shared/_notifications.html.erb
176
175
  - app/views/formstrap/shared/_popup.html.erb
177
176
  - app/views/formstrap/shared/_thumbnail.html.erb
178
177
  - bin/console
@@ -196,6 +195,8 @@ files:
196
195
  - lib/formstrap/form_builder.rb
197
196
  - lib/formstrap/form_helper.rb
198
197
  - lib/formstrap/version.rb
198
+ - lib/generators/install/install_generator.rb
199
+ - lib/generators/install/templates/formstrap.rb
199
200
  - package.json
200
201
  - src/js/formstrap.js
201
202
  - src/scss/formstrap.scss
@@ -1,20 +0,0 @@
1
- <%
2
- # formstrap/shared/notifications
3
- #
4
- # ==== Examples
5
- # Basic version
6
- # <%= render "formstrap/shared/notifications" %#>
7
- %>
8
-
9
- <div class="toast-container position-absolute top-0 end-0 p-3">
10
- <% flash.each do |name, message| %>
11
- <div class="toast align-items-center text-white show <%= notification_color(name.to_sym)[:background] %>" role="alert" aria-live="assertive" aria-atomic="true" data-controller="toast">
12
- <div class="d-flex">
13
- <div class="toast-body <%= notification_color(name.to_sym)[:text] %>">
14
- <%= message %>
15
- </div>
16
- <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
17
- </div>
18
- </div>
19
- <% end %>
20
- </div>