b4um_generators 0.2.10 → 0.2.11

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bedf093ab3a868c663ba73bc843bfd9e262dde6511058cbeeafb48b2e48c228d
4
- data.tar.gz: 64ae08a60ec9482ba1040b738c3a92e24da26c079586f74673e3aa7b6c323f4f
3
+ metadata.gz: fe62953ac32b6c0aa41af6886b6d6c97d1446ef4ae92177a4c200faee03dc9ff
4
+ data.tar.gz: 4b08b040919c741f57374a9f572268265b2405180af4a5958659da3232ada073
5
5
  SHA512:
6
- metadata.gz: effd259d2314e5450df3104327b54e5bd7aa803879897bcd8ec321a682b2e54466df294607633bcc0c4f452cb5ce1e644eb56374275ad77b86720111de1e8be2
7
- data.tar.gz: f5b4d6ceaf22362d380413be06194cc7b1e870b316737bf31089dc290b85ba303d7a7e294ccc1696424567b36f0d9b1ec2becc1921307d475c940c1140046bbc
6
+ metadata.gz: 54fb5d2d124addb3063a2e0ab1540ff6327b9fa624d41f6a9e0197e6012fa5a1fd5edaf26356f3b59d7ec4d36a2d3a3ab993a4b0f59d65cf50ade4adb65b9a20
7
+ data.tar.gz: adea210e1f9eec24d763c9084be55aec061bb9d568caf7be9c68c2a539e8b65ac45e8066fa75c9baae2721f8f1d6d20b8d7396612ec9fa955e9b7370f5d3b0a2
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module B4umGenerators
4
- VERSION = "0.2.10"
4
+ VERSION = "0.2.11"
5
5
  end
@@ -110,13 +110,18 @@ module B4um
110
110
  def update_single_attachment_params
111
111
  content = File.read(controller_path)
112
112
 
113
- return if attachment_permitted?(content)
113
+ update_single_permitted_params(content)
114
+ update_single_attachment_action
115
+ end
116
+
117
+ def update_single_permitted_params(content)
118
+ return if single_attachment_permitted?(content)
114
119
 
115
120
  pattern = /
116
121
  params\.expect\(
117
122
  #{Regexp.escape(file_name)}:\s*
118
123
  \[
119
- (?<attributes>[^\]]*)
124
+ (?<attributes>.*?)
120
125
  \]
121
126
  \)
122
127
  /mx
@@ -124,9 +129,83 @@ module B4um
124
129
  return unless content.match?(pattern)
125
130
 
126
131
  gsub_file(controller_path, pattern) do |match|
132
+ match_data = pattern.match(match)
133
+ attributes = match_data[:attributes]
134
+
135
+ insertion = ":#{attachment}, :remove_#{attachment}"
136
+
137
+ updated_attributes =
138
+ if attributes.match?(/\w+:\s*\[/)
139
+ attributes.sub(
140
+ /(?=\w+:\s*\[)/,
141
+ "#{insertion}, "
142
+ )
143
+ else
144
+ "#{attributes}, #{insertion}"
145
+ end
146
+
127
147
  match.sub(
128
- /\]\)$/,
129
- ", :#{attachment}])"
148
+ attributes,
149
+ updated_attributes
150
+ )
151
+ end
152
+ end
153
+
154
+ def single_attachment_permitted?(content)
155
+ content.include?(
156
+ ":#{attachment}, :remove_#{attachment}"
157
+ )
158
+ end
159
+
160
+ def update_single_attachment_action
161
+ content = File.read(controller_path)
162
+
163
+ return if content.include?(
164
+ "remove_#{attachment} = update_params.delete(\"remove_#{attachment}\")"
165
+ )
166
+
167
+ if content.include?(" update_params = #{file_name}_params\n")
168
+ insert_into_file(
169
+ controller_path,
170
+ " remove_#{attachment} = update_params.delete(\"remove_#{attachment}\")\n",
171
+ after: " update_params = #{file_name}_params\n"
172
+ )
173
+ else
174
+ setup = [
175
+ " def update",
176
+ " update_params = #{file_name}_params",
177
+ " remove_#{attachment} = update_params.delete(\"remove_#{attachment}\")",
178
+ "",
179
+ " respond_to do |format|",
180
+ ""
181
+ ].join("\n")
182
+
183
+ gsub_file(
184
+ controller_path,
185
+ " def update\n respond_to do |format|\n",
186
+ setup
187
+ )
188
+ end
189
+
190
+ content = File.read(controller_path)
191
+
192
+ if content.include?(" if @#{file_name}.update(update_params)\n")
193
+ insert_into_file(
194
+ controller_path,
195
+ " @#{file_name}.#{attachment}.purge if remove_#{attachment} == \"1\"\n",
196
+ after: " if @#{file_name}.update(update_params)\n"
197
+ )
198
+ else
199
+ attachment_handling = [
200
+ " if @#{file_name}.update(update_params)",
201
+ " @#{file_name}.#{attachment}.purge if remove_#{attachment} == \"1\"",
202
+ ""
203
+ ].join("\n")
204
+
205
+ gsub_file(
206
+ controller_path,
207
+ " if @#{file_name}.update(#{file_name}_params)\n",
208
+ attachment_handling
130
209
  )
131
210
  end
132
211
  end
@@ -439,12 +518,34 @@ module B4um
439
518
  <%= "hidden" unless #{file_name}.#{attachment}.attached? %>>
440
519
 
441
520
  <% if #{file_name}.#{attachment}.attached? %>
442
- <%= image_tag #{file_name}.#{attachment},
443
- class: "form-image-preview__image",
444
- alt: #{file_name}.#{attachment}.filename.to_s,
445
- data: {
446
- image_preview_target: "image"
447
- } %>
521
+ <div class="form-image-preview__item"
522
+ role="button"
523
+ tabindex="0"
524
+ aria-pressed="false"
525
+ data-image-preview-target="existingItem"
526
+ data-action="click->image-preview#toggleRemoval keydown->image-preview#toggleRemovalWithKeyboard">
527
+
528
+ <%= image_tag #{file_name}.#{attachment},
529
+ class: "form-image-preview__image",
530
+ alt: #{file_name}.#{attachment}.filename.to_s,
531
+ data: {
532
+ image_preview_target: "image"
533
+ } %>
534
+
535
+ <%= check_box_tag(
536
+ "#{file_name}[remove_#{attachment}]",
537
+ "1",
538
+ false,
539
+ class: "form-image-preview__remove-checkbox",
540
+ data: {
541
+ image_preview_target: "removeCheckbox"
542
+ }
543
+ ) %>
544
+
545
+ <div class="form-image-preview__remove-status">
546
+ Will be removed
547
+ </div>
548
+ </div>
448
549
  <% else %>
449
550
  <img class="form-image-preview__image"
450
551
  data-image-preview-target="image"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: b4um_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Baum
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-10-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
- rubygems_version: 3.6.2
150
+ rubygems_version: 3.6.9
151
151
  specification_version: 4
152
152
  summary: Rails generators for b4um applications
153
153
  test_files: []