formatic 0.1.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/app/assets/javascript/formatic/components/date.ts +54 -0
- data/app/assets/javascript/formatic/components/select.ts +109 -0
- data/app/assets/javascript/formatic/components/stepper.ts +89 -0
- data/app/assets/javascript/formatic/components/textarea.ts +108 -0
- data/app/assets/javascript/formatic/components/toggle.ts +81 -0
- data/app/assets/javascript/formatic.js +350 -0
- data/app/assets/javascript/formatic.js.map +1 -0
- data/app/assets/stylesheets/formatic/components/checklist.sass +3 -0
- data/app/assets/stylesheets/formatic/components/date.sass +70 -0
- data/app/assets/stylesheets/formatic/components/select.sass +24 -0
- data/app/assets/stylesheets/formatic/components/stepper.sass +43 -0
- data/app/assets/stylesheets/formatic/components/string.sass +13 -0
- data/app/assets/stylesheets/formatic/components/textarea.sass +22 -0
- data/app/assets/stylesheets/formatic/components/toggle.sass +93 -0
- data/app/assets/stylesheets/formatic/components/wrapper.sass +51 -0
- data/app/assets/stylesheets/formatic/generics/flip.sass +3 -0
- data/app/assets/stylesheets/formatic/index.sass +16 -0
- data/app/assets/stylesheets/formatic/package.json +5 -0
- data/app/assets/stylesheets/formatic/scopes/form.sass +45 -0
- data/app/assets/stylesheets/formatic/settings/_colors.sass +13 -0
- data/app/assets/stylesheets/formatic/tools/terminal.sass +3 -0
- data/app/assets/stylesheets/formatic/utilities/container.sass +2 -0
- data/app/components/formatic/application_component.rb +39 -0
- data/app/components/formatic/base.rb +72 -0
- data/app/components/formatic/checklist.rb +65 -0
- data/app/components/formatic/date.rb +110 -0
- data/app/components/formatic/select.rb +49 -0
- data/app/components/formatic/stepper.rb +35 -0
- data/app/components/formatic/string.rb +57 -0
- data/app/components/formatic/textarea.rb +48 -0
- data/app/components/formatic/toggle.rb +57 -0
- data/app/components/formatic/wrapper.rb +122 -0
- data/config/locales/formatic.de.yml +5 -0
- data/config/locales/formatic.en.yml +5 -0
- data/lib/formatic/choices/countries.rb +14 -0
- data/lib/formatic/choices/keys.rb +27 -0
- data/lib/formatic/choices/options.rb +39 -0
- data/lib/formatic/choices/records.rb +47 -0
- data/lib/formatic/choices.rb +62 -0
- data/lib/formatic/css.rb +10 -0
- data/lib/formatic/engine.rb +40 -0
- data/lib/formatic/safe_join.rb +20 -0
- data/lib/formatic/templates/date.rb +76 -0
- data/lib/formatic/templates/select.rb +35 -0
- data/lib/formatic/templates/wrapper.rb +52 -0
- data/lib/formatic/version.rb +5 -0
- data/lib/formatic/wrappers/alternative_attribute_name.rb +18 -0
- data/lib/formatic/wrappers/error_messages.rb +39 -0
- data/lib/formatic/wrappers/required.rb +29 -0
- data/lib/formatic/wrappers/translate.rb +41 -0
- data/lib/formatic/wrappers/validators.rb +39 -0
- data/lib/formatic.rb +29 -0
- metadata +186 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Formatic
|
4
|
+
module Wrappers
|
5
|
+
# Looks up translations for placeholders, hints, etc.
|
6
|
+
class Translate
|
7
|
+
include Calls
|
8
|
+
|
9
|
+
option :prefix
|
10
|
+
option :object
|
11
|
+
option :object_name, optional: true
|
12
|
+
option :attribute_name
|
13
|
+
|
14
|
+
def call
|
15
|
+
if optimal_key
|
16
|
+
I18n.t optimal_key, default: ([optimal_key] + fallback_keys), raise: true
|
17
|
+
else
|
18
|
+
I18n.t fallback_keys.first, default: fallback_keys[1..], raise: true
|
19
|
+
end
|
20
|
+
rescue I18n::MissingTranslationData
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def optimal_key
|
27
|
+
return unless object
|
28
|
+
|
29
|
+
:"#{prefix}.#{object.model_name.i18n_key}.#{attribute_name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def fallback_keys
|
33
|
+
[
|
34
|
+
(:"#{prefix}.#{object_name}.#{attribute_name}" if object_name),
|
35
|
+
:"#{prefix}.default.#{attribute_name}",
|
36
|
+
:"#{prefix}.#{attribute_name}"
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Formatic
|
4
|
+
module Wrappers
|
5
|
+
# Examines the validators of a record.
|
6
|
+
class Validators
|
7
|
+
include Calls
|
8
|
+
|
9
|
+
option :object
|
10
|
+
option :attribute_name
|
11
|
+
|
12
|
+
# This could later be made smarter (e.g. checking for conditionals)
|
13
|
+
# See https://github.com/heartcombo/simple_form/blob/main/lib/simple_form/helpers/validators.rb#L15
|
14
|
+
def call
|
15
|
+
return [] unless object.class.respond_to?(:validators_on)
|
16
|
+
|
17
|
+
attribute_validators + association_validators
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :object
|
23
|
+
|
24
|
+
def attribute_validators
|
25
|
+
object.class.validators_on(attribute_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
# `belongs_to :owner` validates `:owner_id`
|
29
|
+
def association_validators
|
30
|
+
association_attribute_name = ::Formatic::Wrappers::AlternativeAttributeName.call(
|
31
|
+
attribute_name
|
32
|
+
)
|
33
|
+
return [] unless association_attribute_name
|
34
|
+
|
35
|
+
object.class.validators_on(association_attribute_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/formatic.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'calls'
|
4
|
+
require 'countries'
|
5
|
+
require 'holidays'
|
6
|
+
require 'dry/initializer'
|
7
|
+
|
8
|
+
require 'formatic/version'
|
9
|
+
require 'formatic/css'
|
10
|
+
require 'formatic/safe_join'
|
11
|
+
require 'formatic/templates/select'
|
12
|
+
require 'formatic/templates/wrapper'
|
13
|
+
require 'formatic/choices/countries'
|
14
|
+
require 'formatic/choices/keys'
|
15
|
+
require 'formatic/choices/records'
|
16
|
+
require 'formatic/choices'
|
17
|
+
require 'formatic/wrappers/alternative_attribute_name'
|
18
|
+
require 'formatic/wrappers/error_messages'
|
19
|
+
require 'formatic/wrappers/required'
|
20
|
+
require 'formatic/wrappers/translate'
|
21
|
+
require 'formatic/wrappers/validators'
|
22
|
+
|
23
|
+
require 'formatic/engine' if defined?(Rails::Engine)
|
24
|
+
|
25
|
+
module Formatic
|
26
|
+
class Error < ::StandardError; end
|
27
|
+
class MissingModelError < Error; end
|
28
|
+
class SubclassNameError < Error; end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: formatic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- halo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: calls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: countries
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dry-initializer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: holidays
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: view_component
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A little bit like simple_form but as VewComponents and more minimalistic.
|
98
|
+
email:
|
99
|
+
- github@posteo.org
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- CHANGELOG.md
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
107
|
+
- app/assets/javascript/formatic.js
|
108
|
+
- app/assets/javascript/formatic.js.map
|
109
|
+
- app/assets/javascript/formatic/components/date.ts
|
110
|
+
- app/assets/javascript/formatic/components/select.ts
|
111
|
+
- app/assets/javascript/formatic/components/stepper.ts
|
112
|
+
- app/assets/javascript/formatic/components/textarea.ts
|
113
|
+
- app/assets/javascript/formatic/components/toggle.ts
|
114
|
+
- app/assets/stylesheets/formatic/components/checklist.sass
|
115
|
+
- app/assets/stylesheets/formatic/components/date.sass
|
116
|
+
- app/assets/stylesheets/formatic/components/select.sass
|
117
|
+
- app/assets/stylesheets/formatic/components/stepper.sass
|
118
|
+
- app/assets/stylesheets/formatic/components/string.sass
|
119
|
+
- app/assets/stylesheets/formatic/components/textarea.sass
|
120
|
+
- app/assets/stylesheets/formatic/components/toggle.sass
|
121
|
+
- app/assets/stylesheets/formatic/components/wrapper.sass
|
122
|
+
- app/assets/stylesheets/formatic/generics/flip.sass
|
123
|
+
- app/assets/stylesheets/formatic/index.sass
|
124
|
+
- app/assets/stylesheets/formatic/package.json
|
125
|
+
- app/assets/stylesheets/formatic/scopes/form.sass
|
126
|
+
- app/assets/stylesheets/formatic/settings/_colors.sass
|
127
|
+
- app/assets/stylesheets/formatic/tools/terminal.sass
|
128
|
+
- app/assets/stylesheets/formatic/utilities/container.sass
|
129
|
+
- app/components/formatic/application_component.rb
|
130
|
+
- app/components/formatic/base.rb
|
131
|
+
- app/components/formatic/checklist.rb
|
132
|
+
- app/components/formatic/date.rb
|
133
|
+
- app/components/formatic/select.rb
|
134
|
+
- app/components/formatic/stepper.rb
|
135
|
+
- app/components/formatic/string.rb
|
136
|
+
- app/components/formatic/textarea.rb
|
137
|
+
- app/components/formatic/toggle.rb
|
138
|
+
- app/components/formatic/wrapper.rb
|
139
|
+
- config/locales/formatic.de.yml
|
140
|
+
- config/locales/formatic.en.yml
|
141
|
+
- lib/formatic.rb
|
142
|
+
- lib/formatic/choices.rb
|
143
|
+
- lib/formatic/choices/countries.rb
|
144
|
+
- lib/formatic/choices/keys.rb
|
145
|
+
- lib/formatic/choices/options.rb
|
146
|
+
- lib/formatic/choices/records.rb
|
147
|
+
- lib/formatic/css.rb
|
148
|
+
- lib/formatic/engine.rb
|
149
|
+
- lib/formatic/safe_join.rb
|
150
|
+
- lib/formatic/templates/date.rb
|
151
|
+
- lib/formatic/templates/select.rb
|
152
|
+
- lib/formatic/templates/wrapper.rb
|
153
|
+
- lib/formatic/version.rb
|
154
|
+
- lib/formatic/wrappers/alternative_attribute_name.rb
|
155
|
+
- lib/formatic/wrappers/error_messages.rb
|
156
|
+
- lib/formatic/wrappers/required.rb
|
157
|
+
- lib/formatic/wrappers/translate.rb
|
158
|
+
- lib/formatic/wrappers/validators.rb
|
159
|
+
homepage: https://github.com/halo/formatic
|
160
|
+
licenses:
|
161
|
+
- MIT
|
162
|
+
metadata:
|
163
|
+
homepage_uri: https://github.com/halo/formatic
|
164
|
+
source_code_uri: https://github.com/halo/formatic
|
165
|
+
changelog_uri: https://github.com/halo/halo/blob/main/CHANGELOG.md
|
166
|
+
rubygems_mfa_required: 'true'
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: 3.2.0
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubygems_version: 3.5.14
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: A set of ViewComponents for form elements
|
186
|
+
test_files: []
|