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 +4 -4
- data/CHANGELOG.md +7 -1
- data/app/components/formatic/base.rb +4 -0
- data/app/components/formatic/file.rb +21 -1
- data/app/components/formatic/stepper.rb +1 -0
- data/app/components/formatic/string.rb +1 -0
- data/app/components/formatic/time.rb +2 -0
- data/app/components/formatic/toggle.rb +1 -1
- data/lib/formatic/engine.rb +3 -2
- data/lib/formatic/templates/date.rb +3 -0
- data/lib/formatic/templates/select.rb +1 -1
- 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
|
@@ -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:
|
|
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
|
|
@@ -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') +
|
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
|
|
|
@@ -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>
|
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
|