formatic 0.2.11 → 0.3.0

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: 24e08479caf78b6670d6992c7b57f2ee23aec26b6aa953b9db7fdfa1184550de
4
- data.tar.gz: 6cc0390bb4f70d25626ab040a83ce32bc404548bcc9fc6812c3da672f5c5af42
3
+ metadata.gz: 6e76d4fb54356f3c1617b84931834bb46e25dbdb8b9923d5449452c72a43fff5
4
+ data.tar.gz: aa825faad29917f0aaf406e849d50c4b202613d1853927e3d2236488e8a767c2
5
5
  SHA512:
6
- metadata.gz: eb198f09b149e71aed3a351893018c69ec15f294ecb18a66ed8159c1f432c7ef0e7259f78f010a01315bf159def6b55315bd0d17af1e50c8882b81913e3f0eb9
7
- data.tar.gz: 14fc1101af9bbc6eed611bfdc3672d44592771a88b0d6cb86b2770dd936846a77caf3c607b8afaca280e9425848eeee05149497111df3299304f6f71b7d4f391
6
+ metadata.gz: 1da9feda2b01a0e4154db1b2efb67904abf8a799c0c518caa83d135edb283e3b534342734acb2a24cf1fadb317e8cc09ecf7c802ee99c475caa339642a2e2fe8
7
+ data.tar.gz: d95a0967fe128dc408d3dd67e4ffc984b65b0b75362ed6b0b3e92bbde94d0fe61506b77bea87a1a5e79637824e96aa949a29f28cd8ff876f143653002674bced
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] 2026-08-04
2
+
3
+ - Make VS Code snippet symlinking atomic so concurrent app boots no longer race into `Errno::EEXIST`
4
+
5
+ ## [0.2.12] 2026-07-24
6
+
7
+ - Add data attribute to every input
2
8
 
3
9
  ## [0.2.11] 2026-07-22
4
10
 
@@ -66,6 +66,10 @@ module Formatic
66
66
  f.object.public_send(attribute_name) if f.object.respond_to?(attribute_name)
67
67
  end
68
68
 
69
+ def data
70
+ manual_data
71
+ end
72
+
69
73
  # ---------------------------
70
74
  # ActiveModel and Rails slugs
71
75
  # ---------------------------
@@ -26,12 +26,22 @@ module Formatic
26
26
  <%- end -%>
27
27
  </div>
28
28
 
29
- <%= f.file_field attribute_name, class: "js-formatic-file__input", direct_upload:, multiple:, accept:, data: { entries: entries_json } %>
29
+ <%= f.file_field attribute_name, class: "js-formatic-file__input", direct_upload:, multiple:, accept:, data: %>
30
+
31
+ <%- if (file = current_file) -%>
32
+ <div class="c-formatic-file__current">
33
+ <%= link_to 'Download', file, target: :_blank %>
34
+ </div>
35
+ <%- end -%>
30
36
  </div>
31
37
  <% end %>
32
38
  <% end %>
33
39
  ERB
34
40
 
41
+ def data
42
+ { entries: entries_json }.merge(manual_data)
43
+ end
44
+
35
45
  private
36
46
 
37
47
  def attachments
@@ -62,5 +72,15 @@ module Formatic
62
72
  }
63
73
  end.to_json
64
74
  end
75
+
76
+ # The currently attached file, if there is exactly one.
77
+ # Multiple files are not shown here, see `Formatic::Files`.
78
+ def current_file
79
+ return if multiple
80
+ return unless attachments.size == 1
81
+
82
+ attachment = attachments.first
83
+ attachment if attachment.present?
84
+ end
65
85
  end
66
86
  end
@@ -20,6 +20,7 @@ module Formatic
20
20
  min: minimum,
21
21
  inputmode: :numeric,
22
22
  pattern: '-?[0-9]*',
23
+ data:,
23
24
  class: 'c-formatic-stepper__number js-formatic-stepper__number',
24
25
  placeholder: wrapper.placeholder,
25
26
  } %>
@@ -33,6 +33,7 @@ module Formatic
33
33
  def input_options
34
34
  result = {
35
35
  placeholder: wrapper.placeholder,
36
+ data:,
36
37
  autofocus:,
37
38
  class: css_classes
38
39
  }
@@ -24,11 +24,13 @@ module Formatic
24
24
  <%= select_tag hour_attribute_name,
25
25
  options_for_hour,
26
26
  id: hour_input_id,
27
+ data:,
27
28
  class: 'c-formatic-time__select' %>
28
29
 
29
30
  <%= select_tag minute_attribute_name,
30
31
  options_for_minute,
31
32
  id: minute_input_id,
33
+ data:,
32
34
  class: 'c-formatic-time__select' %>
33
35
  </div>
34
36
  <% end -%>
@@ -18,7 +18,7 @@ module Formatic
18
18
  <% else %>
19
19
  <%= f.label attribute_name, nil, { for: dom_id } do |builder| %>
20
20
  <%
21
- f.check_box(attribute_name, { id: dom_id, class: css_classes }) +
21
+ f.check_box(attribute_name, { id: dom_id, data:, class: css_classes }) +
22
22
  content_tag(:i) +
23
23
  content_tag(:div, human_attribute_name, class: 'c-formatic-toggle__label-caption-dummy') +
24
24
  content_tag(:div, wrap.toggle_on, class: 'is-active') +
@@ -28,8 +28,7 @@ module Formatic
28
28
  target = vscode_dir.join('formatic.code-snippets')
29
29
  source = Engine.root.join('vscode/formatic.code-snippets')
30
30
 
31
- FileUtils.rm_f(target.to_s)
32
- FileUtils.ln_s(source, target, force: true)
31
+ VscodeSnippets.install(target, source)
33
32
  end
34
33
  end
35
34
 
@@ -58,6 +57,8 @@ module Formatic
58
57
  require_relative '../../app/components/formatic/stepper'
59
58
  require_relative '../../app/components/formatic/textarea'
60
59
  require_relative '../../app/components/formatic/time'
60
+ require_relative '../../app/components/formatic/file'
61
+ require_relative '../../app/components/formatic/files'
61
62
  end
62
63
  end
63
64
  end
@@ -25,17 +25,20 @@ module Formatic
25
25
  <%= select_tag day_attribute_name,
26
26
  options_for_day,
27
27
  id: day_input_id,
28
+ data:,
28
29
  class: 'c-formatic-date__select js-formatic-date__day' %>
29
30
  <% end %>
30
31
 
31
32
  <%= select_tag month_attribute_name,
32
33
  options_for_month,
33
34
  id: month_input_id,
35
+ data:,
34
36
  class: 'c-formatic-date__select js-formatic-date__month' %>
35
37
 
36
38
  <%= select_tag year_attribute_name,
37
39
  options_for_year,
38
40
  id: year_input_id,
41
+ data:,
39
42
  class: 'c-formatic-date__select js-formatic-date__year' %>
40
43
  </div>
41
44
  <% if calendar? %>
@@ -17,7 +17,7 @@ module Formatic
17
17
  </div>
18
18
  <% else %>
19
19
 
20
- <%= f.select attribute_name, choices, {}, { class: ['c-formatic-select', 'js-formatic-select', ('is-autosubmit' if async_submit)] } %>
20
+ <%= f.select attribute_name, choices, {}, { data:, class: ['c-formatic-select', 'js-formatic-select', ('is-autosubmit' if async_submit)] } %>
21
21
 
22
22
  <% end %>
23
23
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Formatic
4
- VERSION = '0.2.11'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tmpdir'
4
+
5
+ module Formatic
6
+ # Installs the gem's VS Code snippets as a symlink inside the host
7
+ # application's `.vscode` directory.
8
+ #
9
+ # This runs in every process that boots the host application (Spring
10
+ # preloader, Puma workers, rake tasks, ...), so those processes race each
11
+ # other. A non-atomic remove-then-create (`FileUtils.ln_s(force: true)`)
12
+ # lets two processes both pass the "does it exist?" check before either
13
+ # creates the link, so one of them dies with `Errno::EEXIST` on
14
+ # `symlink(2)`.
15
+ #
16
+ # To stay race-free the link is created under a temporary name in the
17
+ # system temp directory and then `rename(2)`-ed over the target, which
18
+ # atomically replaces whatever is already there.
19
+ #
20
+ # NOTE: `Formatic::File` (a ViewComponent) shadows `File` inside this
21
+ # module, so we refer to Ruby's file class as `::File`.
22
+ module VscodeSnippets
23
+ class << self
24
+ def install(target, source)
25
+ target = target.to_s
26
+ source = source.to_s
27
+
28
+ return if already_linked?(target, source)
29
+
30
+ install_atomically(target, source)
31
+ end
32
+
33
+ private
34
+
35
+ def install_atomically(target, source)
36
+ tmp = ::File.join(Dir.tmpdir, "formatic-#{Process.pid}-#{Thread.current.object_id}.tmp")
37
+ FileUtils.rm_f(tmp)
38
+ ::File.symlink(source, tmp)
39
+ ::File.rename(tmp, target)
40
+ rescue Errno::EXDEV
41
+ replace(target, source)
42
+ ensure
43
+ FileUtils.rm_f(tmp) if tmp
44
+ end
45
+
46
+ def already_linked?(target, source)
47
+ ::File.symlink?(target) && ::File.readlink(target) == source
48
+ end
49
+
50
+ def replace(target, source)
51
+ FileUtils.rm_f(target)
52
+ ::File.symlink(source, target)
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/formatic.rb CHANGED
@@ -9,6 +9,7 @@ require 'dry/initializer'
9
9
  require 'formatic/version'
10
10
  require 'formatic/css'
11
11
  require 'formatic/safe_join'
12
+ require 'formatic/vscode_snippets'
12
13
  require 'formatic/templates/select'
13
14
  require 'formatic/templates/wrapper'
14
15
  require 'formatic/choices/countries'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - halo
@@ -198,6 +198,7 @@ files:
198
198
  - lib/formatic/templates/select.rb
199
199
  - lib/formatic/templates/wrapper.rb
200
200
  - lib/formatic/version.rb
201
+ - lib/formatic/vscode_snippets.rb
201
202
  - lib/formatic/wrappers/alternative_attribute_name.rb
202
203
  - lib/formatic/wrappers/error_messages.rb
203
204
  - lib/formatic/wrappers/required.rb