metadata_presenter 2.16.5 → 2.16.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/metadata_presenter/component.rb +6 -1
- data/app/validators/metadata_presenter/date_after_validator.rb +8 -0
- data/app/validators/metadata_presenter/date_before_validator.rb +8 -0
- data/app/validators/metadata_presenter/max_word_validator.rb +9 -0
- data/app/validators/metadata_presenter/min_word_validator.rb +9 -0
- data/app/validators/metadata_presenter/word_count.rb +15 -0
- data/default_metadata/string/error.date_after.json +6 -0
- data/default_metadata/string/error.date_before.json +6 -0
- data/default_metadata/string/error.max_word.json +6 -0
- data/default_metadata/string/error.min_word.json +6 -0
- data/default_metadata/validations/date_after.json +1 -0
- data/default_metadata/validations/date_before.json +1 -0
- data/default_metadata/validations/max_length.json +1 -0
- data/default_metadata/validations/max_word.json +1 -0
- data/default_metadata/validations/maximum.json +1 -0
- data/default_metadata/validations/min_length.json +1 -0
- data/default_metadata/validations/min_word.json +1 -0
- data/lib/metadata_presenter/version.rb +1 -1
- data/schemas/validations/validations.json +43 -10
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9f50e8249cf5e5e3c1c18b3894169d367354434711fcf6bd7cfc53f95b78665
|
4
|
+
data.tar.gz: 662a5efde45a3e2d24461a9d76c0d6d380337094365210d1604ede6d01468b6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0542b36a6eabe1fff9555a1311619b005c03e47c54fdb90177b5aff8d5d553db637769b4152b9986656bdfb7c15a64529f33ffeae7aa47a6f6eeb55bdeedcb13
|
7
|
+
data.tar.gz: '08844c20d86b8fd3fb5dae503dff343841cd2850d673a395732580ef15fabfe849e4c9a2db34cfbb615e8fb427eccd0ed971e67b9994cb2f32b747bb44d48d51'
|
@@ -1,5 +1,10 @@
|
|
1
1
|
class MetadataPresenter::Component < MetadataPresenter::Metadata
|
2
|
-
VALIDATION_BUNDLES = {
|
2
|
+
VALIDATION_BUNDLES = {
|
3
|
+
'date' => 'date',
|
4
|
+
'number' => 'number',
|
5
|
+
'text' => 'string',
|
6
|
+
'textarea' => 'string'
|
7
|
+
}.freeze
|
3
8
|
|
4
9
|
def to_partial_path
|
5
10
|
"metadata_presenter/component/#{type}"
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module MetadataPresenter
|
2
|
+
class DateAfterValidator < BaseValidator
|
3
|
+
def invalid_answer?
|
4
|
+
answer_date = "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}"
|
5
|
+
Date.parse(answer_date).iso8601 > Date.parse(component.validation[schema_key]).iso8601
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module MetadataPresenter
|
2
|
+
class DateBeforeValidator < BaseValidator
|
3
|
+
def invalid_answer?
|
4
|
+
answer_date = "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}"
|
5
|
+
Date.parse(answer_date).iso8601 < Date.parse(component.validation[schema_key]).iso8601
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MetadataPresenter
|
2
|
+
module WordCount
|
3
|
+
def word_count(text)
|
4
|
+
strip_tags(text).split.size
|
5
|
+
end
|
6
|
+
|
7
|
+
def strip_tags(text)
|
8
|
+
strip_punctuation(ActionController::Base.helpers.strip_tags(text))
|
9
|
+
end
|
10
|
+
|
11
|
+
def strip_punctuation(text)
|
12
|
+
text.gsub(/[^a-z0-9\s]/i, '')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "date_after": "" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "date_before": "" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "max_length": "0" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "max_word": "0" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "maximum": "0" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "min_length": "0" }
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "min_word": "0" }
|
@@ -69,8 +69,7 @@
|
|
69
69
|
"min_length": {
|
70
70
|
"title": "Minimum length",
|
71
71
|
"description": "The minimum characters users must enter",
|
72
|
-
"type": "
|
73
|
-
"minimum": 0
|
72
|
+
"type": "string"
|
74
73
|
},
|
75
74
|
"errors_min_length": {
|
76
75
|
"title": "Error messages for ‘Minimum length’",
|
@@ -83,8 +82,7 @@
|
|
83
82
|
"max_length": {
|
84
83
|
"title": "Maximum length",
|
85
84
|
"description": "The maximum characters users can enter",
|
86
|
-
"type": "
|
87
|
-
"minimum": 0
|
85
|
+
"type": "string"
|
88
86
|
},
|
89
87
|
"errors_max_length": {
|
90
88
|
"title": "Error messages for ‘Maximum length’",
|
@@ -94,6 +92,32 @@
|
|
94
92
|
}
|
95
93
|
]
|
96
94
|
},
|
95
|
+
"min_word": {
|
96
|
+
"title": "Minimum words",
|
97
|
+
"description": "The minimum number of words users must enter",
|
98
|
+
"type": "string"
|
99
|
+
},
|
100
|
+
"errors_min_word": {
|
101
|
+
"title": "Error messages for 'Minimum words'",
|
102
|
+
"allOf": [
|
103
|
+
{
|
104
|
+
"$ref": "#/definitions/error_strings"
|
105
|
+
}
|
106
|
+
]
|
107
|
+
},
|
108
|
+
"max_word": {
|
109
|
+
"title": "Maximum words",
|
110
|
+
"description": "The maximum number of words users may enter",
|
111
|
+
"type": "string"
|
112
|
+
},
|
113
|
+
"errors_max_word": {
|
114
|
+
"title": "Error messages for 'Maximum words'",
|
115
|
+
"allOf": [
|
116
|
+
{
|
117
|
+
"$ref": "#/definitions/error_strings"
|
118
|
+
}
|
119
|
+
]
|
120
|
+
},
|
97
121
|
"pattern": {
|
98
122
|
"title": "Pattern to match string against",
|
99
123
|
"description": "A regular expression for validating users’ answers",
|
@@ -123,8 +147,7 @@
|
|
123
147
|
"multiple_of": {
|
124
148
|
"title": "Multiple of",
|
125
149
|
"description": "Whether users must enter a multiple of another number",
|
126
|
-
"type": "
|
127
|
-
"minimum": 0
|
150
|
+
"type": "string"
|
128
151
|
},
|
129
152
|
"errors_multiple_of": {
|
130
153
|
"title": "Error messages for ‘Multiple of’",
|
@@ -137,8 +160,7 @@
|
|
137
160
|
"maximum": {
|
138
161
|
"title": "Maximum value",
|
139
162
|
"description": "The largest number that users can enter",
|
140
|
-
"type": "
|
141
|
-
"minimum": 0
|
163
|
+
"type": "string"
|
142
164
|
},
|
143
165
|
"errors_maximum": {
|
144
166
|
"title": "Error messages for ‘Maximum value’",
|
@@ -164,8 +186,7 @@
|
|
164
186
|
"minimum": {
|
165
187
|
"title": "Minimum value",
|
166
188
|
"description": "The smallest number that users can enter",
|
167
|
-
"type": "
|
168
|
-
"minimum": 0
|
189
|
+
"type": "string"
|
169
190
|
},
|
170
191
|
"errors_minimum": {
|
171
192
|
"title": "Error messages for for ‘Minimum value’",
|
@@ -372,6 +393,12 @@
|
|
372
393
|
"max_length": {
|
373
394
|
"$ref": "#/definitions/max_length"
|
374
395
|
},
|
396
|
+
"min_word": {
|
397
|
+
"$ref": "#/definitions/min_word"
|
398
|
+
},
|
399
|
+
"max_word": {
|
400
|
+
"$ref": "#/definitions/max_word"
|
401
|
+
},
|
375
402
|
"pattern": {
|
376
403
|
"$ref": "#/definitions/pattern"
|
377
404
|
},
|
@@ -388,6 +415,12 @@
|
|
388
415
|
"max_length": {
|
389
416
|
"$ref": "#/definitions/errors_max_length"
|
390
417
|
},
|
418
|
+
"min_word": {
|
419
|
+
"$ref": "#/definitions/errors_min_word"
|
420
|
+
},
|
421
|
+
"max_word": {
|
422
|
+
"$ref": "#/definitions/errors_max_word"
|
423
|
+
},
|
391
424
|
"pattern": {
|
392
425
|
"$ref": "#/definitions/errors_pattern"
|
393
426
|
},
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metadata_presenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.16.
|
4
|
+
version: 2.16.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MoJ Forms
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -313,12 +313,16 @@ files:
|
|
313
313
|
- app/presenters/metadata_presenter/page_answers_presenter.rb
|
314
314
|
- app/validators/metadata_presenter/accept_validator.rb
|
315
315
|
- app/validators/metadata_presenter/base_validator.rb
|
316
|
+
- app/validators/metadata_presenter/date_after_validator.rb
|
317
|
+
- app/validators/metadata_presenter/date_before_validator.rb
|
316
318
|
- app/validators/metadata_presenter/date_validator.rb
|
317
319
|
- app/validators/metadata_presenter/email_validator.rb
|
318
320
|
- app/validators/metadata_presenter/max_length_validator.rb
|
319
321
|
- app/validators/metadata_presenter/max_size_validator.rb
|
322
|
+
- app/validators/metadata_presenter/max_word_validator.rb
|
320
323
|
- app/validators/metadata_presenter/maximum_validator.rb
|
321
324
|
- app/validators/metadata_presenter/min_length_validator.rb
|
325
|
+
- app/validators/metadata_presenter/min_word_validator.rb
|
322
326
|
- app/validators/metadata_presenter/minimum_validator.rb
|
323
327
|
- app/validators/metadata_presenter/number_validator.rb
|
324
328
|
- app/validators/metadata_presenter/required_validator.rb
|
@@ -326,6 +330,7 @@ files:
|
|
326
330
|
- app/validators/metadata_presenter/validate_answers.rb
|
327
331
|
- app/validators/metadata_presenter/validate_schema.rb
|
328
332
|
- app/validators/metadata_presenter/virus_scan_validator.rb
|
333
|
+
- app/validators/metadata_presenter/word_count.rb
|
329
334
|
- app/views/errors/404.html
|
330
335
|
- app/views/layouts/metadata_presenter/application.html.erb
|
331
336
|
- app/views/metadata_presenter/attribute/_body.html.erb
|
@@ -388,15 +393,26 @@ files:
|
|
388
393
|
- default_metadata/service/base.json
|
389
394
|
- default_metadata/string/error.accept.json
|
390
395
|
- default_metadata/string/error.date.json
|
396
|
+
- default_metadata/string/error.date_after.json
|
397
|
+
- default_metadata/string/error.date_before.json
|
391
398
|
- default_metadata/string/error.email.json
|
392
399
|
- default_metadata/string/error.max_length.json
|
393
400
|
- default_metadata/string/error.max_size.json
|
401
|
+
- default_metadata/string/error.max_word.json
|
394
402
|
- default_metadata/string/error.maximum.json
|
395
403
|
- default_metadata/string/error.min_length.json
|
404
|
+
- default_metadata/string/error.min_word.json
|
396
405
|
- default_metadata/string/error.minimum.json
|
397
406
|
- default_metadata/string/error.number.json
|
398
407
|
- default_metadata/string/error.required.json
|
399
408
|
- default_metadata/string/error.virus_scan.json
|
409
|
+
- default_metadata/validations/date_after.json
|
410
|
+
- default_metadata/validations/date_before.json
|
411
|
+
- default_metadata/validations/max_length.json
|
412
|
+
- default_metadata/validations/max_word.json
|
413
|
+
- default_metadata/validations/maximum.json
|
414
|
+
- default_metadata/validations/min_length.json
|
415
|
+
- default_metadata/validations/min_word.json
|
400
416
|
- default_metadata/validations/minimum.json
|
401
417
|
- default_text/content.json
|
402
418
|
- fixtures/branching.json
|