phlex-validator 0.0.1
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/LICENSE.txt +21 -0
- data/README.md +11 -0
- data/lib/phlex/validator/html/attributes/a.rb +15 -0
- data/lib/phlex/validator/html/attributes/area.rb +20 -0
- data/lib/phlex/validator/html/attributes/audio.rb +19 -0
- data/lib/phlex/validator/html/attributes/base.rb +8 -0
- data/lib/phlex/validator/html/attributes/bdo.rb +7 -0
- data/lib/phlex/validator/html/attributes/blockquote.rb +7 -0
- data/lib/phlex/validator/html/attributes/body.rb +39 -0
- data/lib/phlex/validator/html/attributes/br.rb +7 -0
- data/lib/phlex/validator/html/attributes/button.rb +35 -0
- data/lib/phlex/validator/html/attributes/canvas.rb +8 -0
- data/lib/phlex/validator/html/attributes/caption.rb +7 -0
- data/lib/phlex/validator/html/attributes/col.rb +13 -0
- data/lib/phlex/validator/html/attributes/data.rb +7 -0
- data/lib/phlex/validator/html/attributes/del.rb +8 -0
- data/lib/phlex/validator/html/attributes/details.rb +8 -0
- data/lib/phlex/validator/html/attributes/dfn.rb +7 -0
- data/lib/phlex/validator/html/attributes/dialog.rb +8 -0
- data/lib/phlex/validator/html/attributes/div.rb +7 -0
- data/lib/phlex/validator/html/attributes/embed.rb +10 -0
- data/lib/phlex/validator/html/attributes/fencedframe.rb +9 -0
- data/lib/phlex/validator/html/attributes/fieldset.rb +9 -0
- data/lib/phlex/validator/html/attributes/form.rb +16 -0
- data/lib/phlex/validator/html/attributes/global.rb +73 -0
- data/lib/phlex/validator/html/attributes/head.rb +7 -0
- data/lib/phlex/validator/html/attributes/hr.rb +11 -0
- data/lib/phlex/validator/html/attributes/html.rb +8 -0
- data/lib/phlex/validator/html/attributes/iframe.rb +44 -0
- data/lib/phlex/validator/html/attributes/img.rb +34 -0
- data/lib/phlex/validator/html/attributes/input.rb +228 -0
- data/lib/phlex/validator/html/attributes/ins.rb +8 -0
- data/lib/phlex/validator/html/attributes/label.rb +7 -0
- data/lib/phlex/validator/html/attributes/li.rb +8 -0
- data/lib/phlex/validator/html/attributes/link.rb +40 -0
- data/lib/phlex/validator/html/attributes/map.rb +7 -0
- data/lib/phlex/validator/html/attributes/meta.rb +18 -0
- data/lib/phlex/validator/html/attributes/meter.rb +14 -0
- data/lib/phlex/validator/html/attributes/object.rb +20 -0
- data/lib/phlex/validator/html/attributes/ol.rb +15 -0
- data/lib/phlex/validator/html/attributes/option.rb +10 -0
- data/lib/phlex/validator/html/attributes/output.rb +9 -0
- data/lib/phlex/validator/html/attributes/pre.rb +8 -0
- data/lib/phlex/validator/html/attributes/progress.rb +8 -0
- data/lib/phlex/validator/html/attributes/q.rb +7 -0
- data/lib/phlex/validator/html/attributes/script.rb +24 -0
- data/lib/phlex/validator/html/attributes/select.rb +14 -0
- data/lib/phlex/validator/html/attributes/slot.rb +7 -0
- data/lib/phlex/validator/html/attributes/source.rb +13 -0
- data/lib/phlex/validator/html/attributes/style.rb +11 -0
- data/lib/phlex/validator/html/attributes/table.rb +15 -0
- data/lib/phlex/validator/html/attributes/tbody.rb +11 -0
- data/lib/phlex/validator/html/attributes/td.rb +19 -0
- data/lib/phlex/validator/html/attributes/template.rb +10 -0
- data/lib/phlex/validator/html/attributes/textarea.rb +20 -0
- data/lib/phlex/validator/html/attributes/tfoot.rb +11 -0
- data/lib/phlex/validator/html/attributes/th.rb +24 -0
- data/lib/phlex/validator/html/attributes/thead.rb +11 -0
- data/lib/phlex/validator/html/attributes/time.rb +19 -0
- data/lib/phlex/validator/html/attributes/tr.rb +11 -0
- data/lib/phlex/validator/html/attributes/track.rb +11 -0
- data/lib/phlex/validator/html/attributes/ul.rb +8 -0
- data/lib/phlex/validator/html/attributes/video.rb +20 -0
- data/lib/phlex/validator/html/mixin.rb +586 -0
- data/lib/phlex/validator/html.rb +464 -0
- data/lib/phlex/validator/version.rb +7 -0
- data/lib/phlex/validator.rb +14 -0
- data/lib/phlex-validator.rb +3 -0
- metadata +154 -0
@@ -0,0 +1,228 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
BaseInputAttributes = {
|
5
|
+
disabled: _Boolean,
|
6
|
+
form: DOMID,
|
7
|
+
name: _String(_Not("isindex")),
|
8
|
+
value: _Union(String, Integer, Float),
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
private_constant :BaseInputAttributes
|
12
|
+
|
13
|
+
TextishInputAttributes = {
|
14
|
+
maxlength: UInt,
|
15
|
+
minlength: UInt,
|
16
|
+
pattern: String,
|
17
|
+
placeholder: String,
|
18
|
+
size: PositiveInteger,
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
private_constant :TextishInputAttributes
|
22
|
+
|
23
|
+
Attributes::Input = {
|
24
|
+
button: {
|
25
|
+
**BaseInputAttributes,
|
26
|
+
popovertarget: DOMID,
|
27
|
+
popovertargetaction: PopoverTargetAction,
|
28
|
+
}.freeze,
|
29
|
+
|
30
|
+
checkbox: {
|
31
|
+
**BaseInputAttributes,
|
32
|
+
checked: _Boolean,
|
33
|
+
required: _Boolean,
|
34
|
+
}.freeze,
|
35
|
+
|
36
|
+
color: {
|
37
|
+
**BaseInputAttributes,
|
38
|
+
autocomplete: Autocomplete,
|
39
|
+
list: DOMID,
|
40
|
+
}.freeze,
|
41
|
+
|
42
|
+
date: {
|
43
|
+
**BaseInputAttributes,
|
44
|
+
autocomplete: Autocomplete,
|
45
|
+
list: DOMID,
|
46
|
+
max: DateString,
|
47
|
+
min: DateString,
|
48
|
+
readonly: _Boolean,
|
49
|
+
required: _Boolean,
|
50
|
+
step: Step,
|
51
|
+
}.freeze,
|
52
|
+
|
53
|
+
datetime_local: {
|
54
|
+
**BaseInputAttributes,
|
55
|
+
autocomplete: Autocomplete,
|
56
|
+
list: DOMID,
|
57
|
+
max: DateTimeString,
|
58
|
+
min: DateTimeString,
|
59
|
+
readonly: _Boolean,
|
60
|
+
required: _Boolean,
|
61
|
+
step: Step,
|
62
|
+
}.freeze,
|
63
|
+
|
64
|
+
email: {
|
65
|
+
**BaseInputAttributes,
|
66
|
+
**TextishInputAttributes,
|
67
|
+
autocapitalize: _Never,
|
68
|
+
autocomplete: Autocomplete,
|
69
|
+
list: DOMID,
|
70
|
+
multiple: _Boolean,
|
71
|
+
readonly: _Boolean,
|
72
|
+
required: _Boolean,
|
73
|
+
}.freeze,
|
74
|
+
|
75
|
+
file: {
|
76
|
+
**BaseInputAttributes,
|
77
|
+
accept: String,
|
78
|
+
autocomplete: Autocomplete,
|
79
|
+
capture: Enum(:user, :environment),
|
80
|
+
list: DOMID,
|
81
|
+
multiple: _Boolean,
|
82
|
+
readonly: _Boolean,
|
83
|
+
required: _Boolean,
|
84
|
+
}.freeze,
|
85
|
+
|
86
|
+
hidden: {
|
87
|
+
**BaseInputAttributes,
|
88
|
+
autocomplete: Autocomplete,
|
89
|
+
dirname: TextDirection,
|
90
|
+
name: _String(_Not("_charset_"), _Not("isindex")),
|
91
|
+
}.freeze,
|
92
|
+
|
93
|
+
image: {
|
94
|
+
**BaseInputAttributes,
|
95
|
+
alt: String,
|
96
|
+
formaction: Href,
|
97
|
+
formenctype: FormEncoding,
|
98
|
+
formmethod: FormMethod,
|
99
|
+
formnovalidate: _Boolean,
|
100
|
+
formtarget: Target,
|
101
|
+
height: UInt,
|
102
|
+
src: Href,
|
103
|
+
value: _Never,
|
104
|
+
width: UInt,
|
105
|
+
}.freeze,
|
106
|
+
|
107
|
+
month: {
|
108
|
+
**BaseInputAttributes,
|
109
|
+
autocomplete: Autocomplete,
|
110
|
+
list: DOMID,
|
111
|
+
max: MonthString,
|
112
|
+
min: MonthString,
|
113
|
+
readonly: _Boolean,
|
114
|
+
required: _Boolean,
|
115
|
+
step: Step,
|
116
|
+
}.freeze,
|
117
|
+
|
118
|
+
number: {
|
119
|
+
**BaseInputAttributes,
|
120
|
+
autocomplete: Autocomplete,
|
121
|
+
list: DOMID,
|
122
|
+
max: NumericValue, # todo should we validate that max is higher than min?
|
123
|
+
min: NumericValue,
|
124
|
+
placeholder: String,
|
125
|
+
readonly: _Boolean,
|
126
|
+
required: _Boolean,
|
127
|
+
step: Step,
|
128
|
+
}.freeze,
|
129
|
+
|
130
|
+
password: {
|
131
|
+
**BaseInputAttributes,
|
132
|
+
**TextishInputAttributes,
|
133
|
+
autocapitalize: _Never,
|
134
|
+
autocomplete: Autocomplete,
|
135
|
+
readonly: _Boolean,
|
136
|
+
required: _Boolean,
|
137
|
+
}.freeze,
|
138
|
+
|
139
|
+
radio: {
|
140
|
+
**BaseInputAttributes,
|
141
|
+
checked: _Boolean,
|
142
|
+
required: _Boolean,
|
143
|
+
}.freeze,
|
144
|
+
|
145
|
+
range: {
|
146
|
+
**BaseInputAttributes,
|
147
|
+
autocomplete: Autocomplete,
|
148
|
+
list: DOMID,
|
149
|
+
max: NumericValue, # todo should we validate that max is higher than min?
|
150
|
+
min: NumericValue,
|
151
|
+
step: Step,
|
152
|
+
}.freeze,
|
153
|
+
|
154
|
+
reset: {
|
155
|
+
**BaseInputAttributes,
|
156
|
+
}.freeze,
|
157
|
+
|
158
|
+
search: {
|
159
|
+
**BaseInputAttributes,
|
160
|
+
**TextishInputAttributes,
|
161
|
+
autocomplete: Autocomplete,
|
162
|
+
list: DOMID,
|
163
|
+
maxlength: UInt,
|
164
|
+
minlength: UInt,
|
165
|
+
readonly: _Boolean,
|
166
|
+
required: _Boolean,
|
167
|
+
}.freeze,
|
168
|
+
|
169
|
+
submit: {
|
170
|
+
**BaseInputAttributes,
|
171
|
+
formaction: Href,
|
172
|
+
formenctype: FormEncoding,
|
173
|
+
formmethod: FormMethod,
|
174
|
+
formnovalidate: _Boolean,
|
175
|
+
formtarget: Target,
|
176
|
+
}.freeze,
|
177
|
+
|
178
|
+
tel: {
|
179
|
+
**BaseInputAttributes,
|
180
|
+
**TextishInputAttributes,
|
181
|
+
autocomplete: Autocomplete,
|
182
|
+
list: DOMID,
|
183
|
+
readonly: _Boolean,
|
184
|
+
required: _Boolean,
|
185
|
+
}.freeze,
|
186
|
+
|
187
|
+
text: {
|
188
|
+
**BaseInputAttributes,
|
189
|
+
**TextishInputAttributes,
|
190
|
+
autocomplete: Autocomplete,
|
191
|
+
list: DOMID,
|
192
|
+
readonly: _Boolean,
|
193
|
+
required: _Boolean,
|
194
|
+
}.freeze,
|
195
|
+
|
196
|
+
time: {
|
197
|
+
**BaseInputAttributes,
|
198
|
+
autocomplete: Autocomplete,
|
199
|
+
list: DOMID,
|
200
|
+
max: TimeString,
|
201
|
+
min: TimeString,
|
202
|
+
readonly: _Boolean,
|
203
|
+
required: _Boolean,
|
204
|
+
step: Step,
|
205
|
+
}.freeze,
|
206
|
+
|
207
|
+
url: {
|
208
|
+
**BaseInputAttributes,
|
209
|
+
**TextishInputAttributes,
|
210
|
+
autocapitalize: _Never,
|
211
|
+
autocomplete: Autocomplete,
|
212
|
+
list: DOMID,
|
213
|
+
readonly: _Boolean,
|
214
|
+
required: _Boolean,
|
215
|
+
}.freeze,
|
216
|
+
|
217
|
+
week: {
|
218
|
+
**BaseInputAttributes,
|
219
|
+
autocomplete: Autocomplete,
|
220
|
+
list: DOMID,
|
221
|
+
max: WeekString,
|
222
|
+
min: WeekString,
|
223
|
+
readonly: _Boolean,
|
224
|
+
required: _Boolean,
|
225
|
+
step: Step,
|
226
|
+
}.freeze,
|
227
|
+
}.freeze
|
228
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
# todo: revisit for specific inter-dependent validations
|
5
|
+
Attributes::Link = {
|
6
|
+
as: Enum(
|
7
|
+
:audio,
|
8
|
+
:document,
|
9
|
+
:embed,
|
10
|
+
:fetch,
|
11
|
+
:font,
|
12
|
+
:image,
|
13
|
+
:manifest,
|
14
|
+
:object,
|
15
|
+
:script,
|
16
|
+
:style,
|
17
|
+
:track,
|
18
|
+
:video,
|
19
|
+
:worker,
|
20
|
+
),
|
21
|
+
blocking: Blocking,
|
22
|
+
crossorigin: CrossOrigin,
|
23
|
+
disabled: _Boolean,
|
24
|
+
fetchpriority: FetchPriority,
|
25
|
+
href: Href,
|
26
|
+
hreflang: Language,
|
27
|
+
imagesizes: String, # todo
|
28
|
+
imagesrcset: String, # todo
|
29
|
+
integrity: String, # todo
|
30
|
+
media: String, # todo — with a CSS parser, you could validate this further
|
31
|
+
referrerpolicy: ReferrerPolicy,
|
32
|
+
rel: LinkRel, # todo — we can do different validations with internal and externa links
|
33
|
+
sizes: Sizes,
|
34
|
+
title: String,
|
35
|
+
type: MimeType,
|
36
|
+
target: _Never,
|
37
|
+
charset: Deprecated,
|
38
|
+
rev: Deprecated,
|
39
|
+
}.freeze
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
# TODO: We can validate the content based on the http_equiv value
|
5
|
+
Attributes::Meta = {
|
6
|
+
charset: Token(:utf_8),
|
7
|
+
content: String,
|
8
|
+
http_equiv: Enum(
|
9
|
+
:content_security_policy,
|
10
|
+
:content_type,
|
11
|
+
:default_style,
|
12
|
+
:x_ua_compatible,
|
13
|
+
:refresh
|
14
|
+
),
|
15
|
+
media: String,
|
16
|
+
name: String,
|
17
|
+
}.freeze
|
18
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
# TODO: We should verify things like min < max, etc.
|
5
|
+
Attributes::Meter = {
|
6
|
+
value: NumericValue,
|
7
|
+
min: NumericValue,
|
8
|
+
max: NumericValue,
|
9
|
+
low: NumericValue,
|
10
|
+
high: NumericValue,
|
11
|
+
optimum: NumericValue,
|
12
|
+
form: DOMID,
|
13
|
+
}.freeze
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Object = {
|
5
|
+
archive: Deprecated,
|
6
|
+
border: Deprecated,
|
7
|
+
classid: Deprecated,
|
8
|
+
codebase: Deprecated,
|
9
|
+
codetype: Deprecated,
|
10
|
+
data: Href,
|
11
|
+
declare: Deprecated,
|
12
|
+
form: DOMID,
|
13
|
+
height: UInt,
|
14
|
+
name: String,
|
15
|
+
standby: Deprecated,
|
16
|
+
type: String, # TODO: should this be an enum?
|
17
|
+
usemap: Deprecated,
|
18
|
+
width: UInt,
|
19
|
+
}.freeze
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Script = {
|
5
|
+
async: _Boolean,
|
6
|
+
attributionsrc: AttributionSource,
|
7
|
+
blocking: Blocking,
|
8
|
+
crossorigin: CrossOrigin,
|
9
|
+
defer: _Boolean,
|
10
|
+
fetchpriority: FetchPriority,
|
11
|
+
integrity: String, # TODO: maybe this can be validated
|
12
|
+
nomodule: _Boolean,
|
13
|
+
nonce: String,
|
14
|
+
referrerpolicy: ReferrerPolicy,
|
15
|
+
src: Href,
|
16
|
+
type: Enum(
|
17
|
+
:importmap,
|
18
|
+
:module,
|
19
|
+
:speculationrules,
|
20
|
+
),
|
21
|
+
charset: Deprecated,
|
22
|
+
language: Deprecated,
|
23
|
+
}.freeze
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Select = {
|
5
|
+
autocomplete: Autocomplete,
|
6
|
+
autofocus: _Boolean,
|
7
|
+
disabled: _Boolean,
|
8
|
+
form: DOMID,
|
9
|
+
multiple: _Boolean,
|
10
|
+
name: String,
|
11
|
+
required: _Boolean,
|
12
|
+
size: UInt,
|
13
|
+
}.freeze
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Table = {
|
5
|
+
align: Deprecated,
|
6
|
+
bgcolor: Deprecated,
|
7
|
+
border: Deprecated,
|
8
|
+
cellpadding: Deprecated,
|
9
|
+
cellspacing: Deprecated,
|
10
|
+
frame: Deprecated,
|
11
|
+
rules: Deprecated,
|
12
|
+
summary: Deprecated,
|
13
|
+
width: Deprecated,
|
14
|
+
}.freeze
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Td = {
|
5
|
+
colspan: ColSpan,
|
6
|
+
headers: SpaceSeparatedList(DOMID),
|
7
|
+
rowspan: RowSpan,
|
8
|
+
abbr: Deprecated,
|
9
|
+
align: Deprecated,
|
10
|
+
axis: Deprecated,
|
11
|
+
bgcolor: Deprecated,
|
12
|
+
char: Deprecated,
|
13
|
+
charoff: Deprecated,
|
14
|
+
height: Deprecated,
|
15
|
+
scope: Deprecated,
|
16
|
+
valign: Deprecated,
|
17
|
+
width: Deprecated,
|
18
|
+
}.freeze
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Textarea = {
|
5
|
+
autocomplete: Autocomplete,
|
6
|
+
cols: PositiveInteger,
|
7
|
+
dirname: TextDirection,
|
8
|
+
disabled: _Boolean,
|
9
|
+
form: DOMID,
|
10
|
+
maxlength: UInt,
|
11
|
+
minlength: UInt,
|
12
|
+
name: String,
|
13
|
+
placeholder: String,
|
14
|
+
readonly: _Boolean,
|
15
|
+
required: _Boolean,
|
16
|
+
rows: PositiveInteger,
|
17
|
+
spellcheck: Enum(:true, :false, :default),
|
18
|
+
wrap: Enum(:hard, :soft),
|
19
|
+
}
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Th = {
|
5
|
+
abbr: String,
|
6
|
+
colspan: ColSpan,
|
7
|
+
headers: SpaceSeparatedList(DOMID),
|
8
|
+
rowspan: RowSpan,
|
9
|
+
scope: Enum(
|
10
|
+
:row,
|
11
|
+
:col,
|
12
|
+
:rowgroup,
|
13
|
+
:colgroup
|
14
|
+
),
|
15
|
+
align: Deprecated,
|
16
|
+
axis: Deprecated,
|
17
|
+
bgcolor: Deprecated,
|
18
|
+
char: Deprecated,
|
19
|
+
charoff: Deprecated,
|
20
|
+
height: Deprecated,
|
21
|
+
valign: Deprecated,
|
22
|
+
width: Deprecated,
|
23
|
+
}.freeze
|
24
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Phlex::Validator::HTML
|
4
|
+
Attributes::Time = {
|
5
|
+
datetime: _Union(
|
6
|
+
YearString,
|
7
|
+
WeekString,
|
8
|
+
MonthString,
|
9
|
+
DateString,
|
10
|
+
TimeZoneOffset,
|
11
|
+
AbstractTime,
|
12
|
+
AbstractDayOfMonth,
|
13
|
+
LocalDateTimeString,
|
14
|
+
DateTimeString,
|
15
|
+
DurationString,
|
16
|
+
PeriodString,
|
17
|
+
),
|
18
|
+
}.freeze
|
19
|
+
end
|