klods-ruby 1.2.0 → 1.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/lib/klods/form_builder.rb +60 -0
- data/lib/klods/railtie.rb +2 -0
- data/lib/klods/version.rb +1 -1
- metadata +31 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e69d689812ff62a2d4e4e81169ca4d572eee1c7036af0b17e5b6ad66b6c73c2d
|
|
4
|
+
data.tar.gz: 0cc52609f3b1fe61aeb480e1a289269dbec20e1a50690bb95b8c645ead2b7506
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e64fd8cf5a7927ae1edd8486e4fe21ed63fe56db8b53f6021984914c7f1add7dfa44aceb61c258d1b23f4faa64430578a7ebce392a2822170b722344f18a7a0
|
|
7
|
+
data.tar.gz: 6e2dcccafe102221366b77f3ea062957fde302f4729b9c1475ee9c361b4f96210c40e2b3f6f62479c7e4084132aba6beb2020840ce521b9b30a38473c182fb44
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Klods
|
|
2
|
+
class FormBuilder < ActionView::Helpers::FormBuilder
|
|
3
|
+
# Renders a fully wired klods form field: wrapper div, label, input, and
|
|
4
|
+
# optional help/error text. Error state is read from object.errors automatically.
|
|
5
|
+
#
|
|
6
|
+
# = f.klods_field :email, label: "Email", type: :email, autocomplete: "email"
|
|
7
|
+
# = f.klods_field :password, label: "Password", type: :password, required: true
|
|
8
|
+
# = f.klods_field :bio, label: "Bio", type: :textarea
|
|
9
|
+
# = f.klods_field :name, label: "Name", help: "Your display name"
|
|
10
|
+
def klods_field(method, label: nil, type: :text, help: nil, required: false, **options)
|
|
11
|
+
errors = Array(object&.errors&.[](method))
|
|
12
|
+
error_msg = errors.first
|
|
13
|
+
is_invalid = !error_msg.nil?
|
|
14
|
+
|
|
15
|
+
id = field_id(method)
|
|
16
|
+
help_id = "#{id}-help" if help
|
|
17
|
+
error_id = "#{id}-error" if is_invalid
|
|
18
|
+
|
|
19
|
+
aria = {}
|
|
20
|
+
aria["aria-describedby"] = is_invalid ? error_id : help_id if error_id || help_id
|
|
21
|
+
aria["aria-invalid"] = "true" if is_invalid
|
|
22
|
+
|
|
23
|
+
field_cls = ["klods-field", ("klods-field--invalid" if is_invalid)].compact.join(" ")
|
|
24
|
+
label_cls = ["klods-label", ("klods-label--required" if required)].compact.join(" ")
|
|
25
|
+
|
|
26
|
+
@template.content_tag(:div, class: field_cls) do
|
|
27
|
+
label(method, label || method.to_s.humanize, class: label_cls) +
|
|
28
|
+
send(input_helper_for(type), method, class: "klods-input", **aria, **options) +
|
|
29
|
+
((help && !is_invalid) ? @template.content_tag(:p, help, id: help_id, class: "klods-help") : "".html_safe) +
|
|
30
|
+
(error_msg ? @template.content_tag(:p, error_msg, id: error_id, class: "klods-error", role: "alert") : "".html_safe)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Renders a submit button styled as a primary klods button.
|
|
35
|
+
#
|
|
36
|
+
# = f.klods_submit "Save"
|
|
37
|
+
# = f.klods_submit "Sign up", class: "klods-button--wide" # extra class merged in
|
|
38
|
+
def klods_submit(label = nil, **options)
|
|
39
|
+
extra = options.delete(:class)
|
|
40
|
+
options[:class] = ["klods-button", "klods-button--primary", extra].compact.join(" ")
|
|
41
|
+
submit(label, **options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def input_helper_for(type)
|
|
47
|
+
{
|
|
48
|
+
email: :email_field,
|
|
49
|
+
password: :password_field,
|
|
50
|
+
tel: :phone_field,
|
|
51
|
+
url: :url_field,
|
|
52
|
+
number: :number_field,
|
|
53
|
+
date: :date_field,
|
|
54
|
+
time: :time_field,
|
|
55
|
+
search: :search_field,
|
|
56
|
+
textarea: :text_area
|
|
57
|
+
}.fetch(type, :text_field)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/klods/railtie.rb
CHANGED
data/lib/klods/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klods-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Drue Wilding
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-06-
|
|
11
|
+
date: 2026-06-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -38,6 +38,34 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '1.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: actionview
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '7.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '7.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: activemodel
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '7.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '7.0'
|
|
41
69
|
description:
|
|
42
70
|
email:
|
|
43
71
|
- drue@wilding.dk
|
|
@@ -69,6 +97,7 @@ files:
|
|
|
69
97
|
- lib/klods/components/toast.rb
|
|
70
98
|
- lib/klods/components/tooltip.rb
|
|
71
99
|
- lib/klods/core.rb
|
|
100
|
+
- lib/klods/form_builder.rb
|
|
72
101
|
- lib/klods/html.rb
|
|
73
102
|
- lib/klods/icons.rb
|
|
74
103
|
- lib/klods/layout.rb
|