dsfr-form_builder 0.0.1 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dsfr-form_builder.rb +75 -5
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f78a8ca84967d63fc6f95b3e23ace1f50d1b7c766b384e5581c80b582efad0ce
4
- data.tar.gz: ed4c78246f7de17792c50af66a13251d70c888c028aa2a1f7cab74c8e6336268
3
+ metadata.gz: aff91dd2eb3c542a1f433c991f7192ee7e65ed067b12515231f5fa53a1ee3813
4
+ data.tar.gz: b98b1557af59d4d6d271a4ed430db74439badf97119ffdc1f01abf274b55ac43
5
5
  SHA512:
6
- metadata.gz: 907d5214d6ee90397b97b7be0ee73b3538fecc6043c22a3d1722b3216dc64edcd1f3c91ae6f94dbcb1cd11a8a1b9a13e1f0d56f336d61840b9f1bd4d7b99ecc7
7
- data.tar.gz: 8512492bed98876820620cab73bf5a2ec76eb7e49e5d50945bdd7dda8d6c1430e687b2b7ca97f555a922d44a7ab5c7757fef72f5bd22ecb2d939805d74277dd6
6
+ metadata.gz: c7388eb869cc537c7925bd98485197293e08f9ad0317833a1b7ac2e1ffb516c75146c4e9d0daedb559820c060326086d9865135302f36a0ec8f730673b3c6320
7
+ data.tar.gz: 460021e34f3557451b66f0c93b4f677bb14713b374c9f73ad006e20a2192d6b833158648b566927e5e0f300e0022d5b8b693c9acbdaddb73c3fb05d35038082d
@@ -16,10 +16,14 @@ module Dsfr
16
16
  dsfr_input_field(attribute, :text_field, opts)
17
17
  end
18
18
 
19
+ def dsfr_text_area(attribute, opts = {})
20
+ dsfr_input_field(attribute, :text_area, opts)
21
+ end
22
+
19
23
  def dsfr_email_field(attribute, opts = {})
20
24
  dsfr_input_field(attribute, :email_field, opts)
21
25
  end
22
-
26
+
23
27
  def dsfr_url_field(attribute, opts = {})
24
28
  dsfr_input_field(attribute, :url_field, opts)
25
29
  end
@@ -28,6 +32,10 @@ module Dsfr
28
32
  dsfr_input_field(attribute, :phone_field, opts)
29
33
  end
30
34
 
35
+ def dsfr_number_field(attribute, opts = {})
36
+ dsfr_input_field(attribute, :number_field, opts)
37
+ end
38
+
31
39
  def dsfr_input_group(attribute, opts, &block)
32
40
  @template.content_tag(:div, class: input_group_classes(attribute, opts), data: opts[:data]) do
33
41
  yield(block)
@@ -39,17 +47,79 @@ module Dsfr
39
47
  @template.safe_join(
40
48
  [
41
49
  dsfr_label_with_hint(attribute, opts),
42
- public_send(input_kind, attribute, class: "fr-input", **opts.except(:class)),
43
- dsfr_error_message(attribute),
50
+ public_send(input_kind, attribute, class: "fr-input", **opts.except(:class, :hint)),
51
+ dsfr_error_message(attribute)
52
+ ]
53
+ )
54
+ end
55
+ end
56
+
57
+ def dsfr_check_box(attribute, opts = {})
58
+ @template.content_tag(:div, class: "fr-checkbox-group") do
59
+ @template.safe_join(
60
+ [
61
+ check_box(attribute, opts),
62
+ label(attribute, class: "fr-label")
63
+ ]
64
+ )
65
+ end
66
+ end
67
+
68
+ def dsfr_select(attribute, choices, input_options: {}, **opts)
69
+ @template.content_tag(:div, class: "fr-select-group") do
70
+ @template.safe_join(
71
+ [
72
+ dsfr_label_with_hint(attribute, opts),
73
+ dsfr_select_tag(attribute, choices, **opts, **(input_options)),
74
+ dsfr_error_message(attribute)
75
+ ]
76
+ )
77
+ end
78
+ end
79
+
80
+ def dsfr_select_tag(attribute, choices, opts)
81
+ select(attribute, choices, { include_blank: opts[:include_blank] }, class: "fr-select")
82
+ end
83
+
84
+ def dsfr_radio_buttons(attribute, choices, legend: nil, hint: nil, **opts)
85
+ legend_content = @template.safe_join([
86
+ legend || @object.class.human_attribute_name(attribute),
87
+ hint ? hint_tag(hint) : nil
88
+ ].compact)
89
+ @template.content_tag(:fieldset, class: "fr-fieldset") do
90
+ @template.safe_join(
91
+ [
92
+ @template.content_tag(:legend, legend_content, class: "fr-fieldset__legend--regular fr-fieldset__legend"),
93
+ choices.map { |c| dsfr_radio_option(attribute, value: c[:value], label_text: c[:label], hint: c[:hint], **opts) }
44
94
  ]
45
95
  )
46
96
  end
47
97
  end
48
98
 
99
+ def dsfr_radio_option(attribute, value:, label_text:, hint:, **opts)
100
+ @template.content_tag(:div, class: "fr-fieldset__element") do
101
+ @template.content_tag(:div, class: "fr-radio-group") do
102
+ @template.safe_join(
103
+ [
104
+ radio_button(attribute, value, **opts),
105
+ label([ attribute, value ].join("_").to_sym) do
106
+ @template.safe_join(
107
+ [
108
+ label_text,
109
+ hint.present? ? @template.content_tag(:span, hint, class: "fr-hint-text") : nil
110
+ ]
111
+ )
112
+ end
113
+ ]
114
+ )
115
+ end
116
+ end
117
+ end
118
+
49
119
  def dsfr_label_with_hint(attribute, opts = {})
50
120
  label_class = "fr-label #{opts[:class]}"
51
121
  label(attribute, class: label_class) do
52
- label_and_tags = [label_value(attribute, opts)]
122
+ label_and_tags = [ label_value(attribute, opts) ]
53
123
  label_and_tags.push(required_tag) if opts[:required] && display_required_tags
54
124
  label_and_tags.push(hint_tag(opts[:hint])) if opts[:hint]
55
125
 
@@ -90,7 +160,7 @@ module Dsfr
90
160
  [
91
161
  "fr-input-group",
92
162
  @object.errors[attribute].any? ? "fr-input-group--error" : nil,
93
- opts[:class],
163
+ opts[:class]
94
164
  ]
95
165
  )
96
166
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsfr-form_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - BetaGouv developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-21 00:00:00.000000000 Z
11
+ date: 2025-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview