formatic 0.2.12 → 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 +4 -4
- data/CHANGELOG.md +3 -1
- data/app/components/formatic/file.rb +16 -0
- data/lib/formatic/engine.rb +1 -2
- data/lib/formatic/version.rb +1 -1
- data/lib/formatic/vscode_snippets.rb +56 -0
- data/lib/formatic.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e76d4fb54356f3c1617b84931834bb46e25dbdb8b9923d5449452c72a43fff5
|
|
4
|
+
data.tar.gz: aa825faad29917f0aaf406e849d50c4b202613d1853927e3d2236488e8a767c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1da9feda2b01a0e4154db1b2efb67904abf8a799c0c518caa83d135edb283e3b534342734acb2a24cf1fadb317e8cc09ecf7c802ee99c475caa339642a2e2fe8
|
|
7
|
+
data.tar.gz: d95a0967fe128dc408d3dd67e4ffc984b65b0b75362ed6b0b3e92bbde94d0fe61506b77bea87a1a5e79637824e96aa949a29f28cd8ff876f143653002674bced
|
data/CHANGELOG.md
CHANGED
|
@@ -27,6 +27,12 @@ module Formatic
|
|
|
27
27
|
</div>
|
|
28
28
|
|
|
29
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 %>
|
|
@@ -66,5 +72,15 @@ module Formatic
|
|
|
66
72
|
}
|
|
67
73
|
end.to_json
|
|
68
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
|
|
69
85
|
end
|
|
70
86
|
end
|
data/lib/formatic/engine.rb
CHANGED
|
@@ -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
|
-
|
|
32
|
-
FileUtils.ln_s(source, target, force: true)
|
|
31
|
+
VscodeSnippets.install(target, source)
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
|
data/lib/formatic/version.rb
CHANGED
|
@@ -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.
|
|
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
|