easol-canvas 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canvas/validators/layout_schema.rb +81 -30
- data/lib/canvas/version.rb +1 -1
- data/schema_definitions/block_layout.json +23 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c61a6785fbf34da110e1fe2b01a9f096ff4aaf8ea3cfbef780491b5e94e68998
|
4
|
+
data.tar.gz: 3acb2a3215a5fd874ad5e54cc719204cb0a4698218935f2546ce5cacf3f73777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 660512a56bea758cae95483fdaefd41a75156a7c15723e661749a64feb6dbc847bab31e279fecd733af807c33491a138b9c4afc850bfd2db84e8b1ae5d3c848a
|
7
|
+
data.tar.gz: 75fdbbefd7cfccc1849bf26e1c42e9f24f274c1d1ed27774d6b1a5085a5caafd30b4b8a0499d418686320157b6335116e0a25bf973b24fedee60210bb64c8d0d
|
@@ -9,23 +9,39 @@ module Canvas
|
|
9
9
|
# This class is used to validate a layout definition, part of block schema.
|
10
10
|
# Example of a valid layout definition:
|
11
11
|
# {
|
12
|
+
# "attributes" => [
|
13
|
+
# {
|
14
|
+
# "name" => "title",
|
15
|
+
# "type" => "string"
|
16
|
+
# }
|
17
|
+
# ...
|
18
|
+
# ],
|
12
19
|
# "layout" => [
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# "elements" => [
|
17
|
-
# "heading",
|
18
|
-
# {
|
19
|
-
# "type" => "accordion",
|
20
|
-
# "label" => "Logo",
|
20
|
+
# {
|
21
|
+
# "label" => "Design",
|
22
|
+
# "type" => "tab",
|
21
23
|
# "elements" => [
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# "
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
24
|
+
# "heading",
|
25
|
+
# {
|
26
|
+
# "type" => "accordion",
|
27
|
+
# "label" => "Logo",
|
28
|
+
# "elements" => [
|
29
|
+
# "description",
|
30
|
+
# { "type" => "attribute", "name" => "logo_alt" },
|
31
|
+
# "title"
|
32
|
+
# ]
|
33
|
+
# },
|
34
|
+
# {
|
35
|
+
# "type" => "accordion_toggle",
|
36
|
+
# "toggle_attribute" => "cta_enabled",
|
37
|
+
# "elements" => [
|
38
|
+
# "cta_text",
|
39
|
+
# "cta_target"
|
40
|
+
# ]
|
41
|
+
# }
|
42
|
+
# ]
|
43
|
+
# }
|
44
|
+
# ]
|
29
45
|
# }
|
30
46
|
class LayoutSchema
|
31
47
|
attr_reader :errors
|
@@ -41,6 +57,7 @@ module Canvas
|
|
41
57
|
if ensure_valid_format
|
42
58
|
ensure_no_unrecognized_keys
|
43
59
|
ensure_no_duplicate_keys
|
60
|
+
ensure_accordion_toggles_are_valid
|
44
61
|
end
|
45
62
|
|
46
63
|
@errors.empty?
|
@@ -48,8 +65,10 @@ module Canvas
|
|
48
65
|
|
49
66
|
private
|
50
67
|
|
68
|
+
attr_reader :schema
|
69
|
+
|
51
70
|
def ensure_no_duplicate_keys
|
52
|
-
attributes =
|
71
|
+
attributes = fetch_all_attribute_names
|
53
72
|
duplicates =
|
54
73
|
attributes
|
55
74
|
.group_by { |(key)| key }
|
@@ -63,37 +82,54 @@ module Canvas
|
|
63
82
|
end
|
64
83
|
|
65
84
|
def ensure_no_unrecognized_keys
|
66
|
-
attributes =
|
67
|
-
defined_attributes =
|
85
|
+
attributes = fetch_all_attribute_names
|
86
|
+
defined_attributes = schema["attributes"]&.map { |definition| normalize_attribute(definition["name"]) } || []
|
68
87
|
|
69
88
|
attributes.each do |attribute, location|
|
70
89
|
@errors << "Unrecognized attribute `#{attribute}`. Location: #{location}" unless defined_attributes.include?(attribute)
|
71
90
|
end
|
72
91
|
end
|
73
92
|
|
74
|
-
|
75
|
-
|
93
|
+
# @return [Array<Array(String, String)>] an array of all the attribute names that
|
94
|
+
# are mentioned in the layout schema, along with its path. The names are
|
95
|
+
# normalized, i.e. downcased.
|
96
|
+
def fetch_all_attribute_names
|
97
|
+
attributes = fetch_elements_of_type("attribute")
|
98
|
+
attributes.map do |(node, path)|
|
99
|
+
[
|
100
|
+
normalize_attribute(node.is_a?(Hash) ? node["name"] : node),
|
101
|
+
path
|
102
|
+
]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# @param type [String] the element type to fetch
|
107
|
+
# @return [Array<Array(<Hash, String>, String)] an array of elements that match
|
108
|
+
# the given type. Each element is an array containing the node and its path.
|
109
|
+
def fetch_elements_of_type(type)
|
110
|
+
elements = []
|
111
|
+
|
112
|
+
fetch_element = ->(node, path) {
|
113
|
+
if type == "attribute" && node.is_a?(String)
|
114
|
+
elements << [node, path]
|
115
|
+
elsif node["type"] == type
|
116
|
+
elements << [node, path]
|
117
|
+
end
|
76
118
|
|
77
|
-
fetch_attribute_type = ->(node, path) {
|
78
119
|
if node.is_a?(Hash) && node.key?("elements")
|
79
120
|
node["elements"].each_with_index do |element, i|
|
80
121
|
current_path = "#{path}/elements/#{i}"
|
81
|
-
|
122
|
+
fetch_element.call(element, current_path)
|
82
123
|
end
|
83
|
-
else
|
84
|
-
attribute_keys << [
|
85
|
-
normalize_attribute(node.is_a?(Hash) ? node["name"] : node),
|
86
|
-
path
|
87
|
-
]
|
88
124
|
end
|
89
125
|
}
|
90
126
|
|
91
127
|
layout_schema.each_with_index do |tab, i|
|
92
128
|
current_path = "layout/#{i}"
|
93
|
-
|
129
|
+
fetch_element.call(tab, current_path)
|
94
130
|
end
|
95
131
|
|
96
|
-
|
132
|
+
elements
|
97
133
|
end
|
98
134
|
|
99
135
|
def ensure_valid_format
|
@@ -105,8 +141,23 @@ module Canvas
|
|
105
141
|
false
|
106
142
|
end
|
107
143
|
|
144
|
+
def ensure_accordion_toggles_are_valid
|
145
|
+
accordion_toggles = fetch_elements_of_type("accordion_toggle")
|
146
|
+
accordion_toggles.each do |accordion_toggle, location|
|
147
|
+
toggle_attribute = schema["attributes"]&.detect { |attr|
|
148
|
+
attr["name"] == accordion_toggle["toggle_attribute"]
|
149
|
+
}
|
150
|
+
|
151
|
+
if toggle_attribute.nil?
|
152
|
+
@errors << "The toggle_attribute in accordion_toggle is unrecognized. Location: #{location}"
|
153
|
+
elsif toggle_attribute["type"] != "boolean"
|
154
|
+
@errors << "The toggle_attribute in accordion_toggle must be a boolean. Location: #{location}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
108
159
|
def layout_schema
|
109
|
-
|
160
|
+
schema["layout"] || []
|
110
161
|
end
|
111
162
|
|
112
163
|
def schema_definition
|
data/lib/canvas/version.rb
CHANGED
@@ -24,20 +24,21 @@
|
|
24
24
|
"items": {
|
25
25
|
"oneOf": [
|
26
26
|
{ "type": "string" },
|
27
|
-
{ "$ref": "#/$defs/
|
27
|
+
{ "$ref": "#/$defs/accordion" },
|
28
|
+
{ "$ref": "#/$defs/accordion_toggle" },
|
28
29
|
{ "$ref": "#/$defs/attribute" }
|
29
30
|
]
|
30
31
|
}
|
31
32
|
}
|
32
33
|
}
|
33
34
|
},
|
34
|
-
"
|
35
|
+
"accordion": {
|
35
36
|
"type": "object",
|
36
37
|
"required": ["label", "type"],
|
37
38
|
"properties": {
|
38
39
|
"type": {
|
39
40
|
"type": "string",
|
40
|
-
"
|
41
|
+
"const": "accordion"
|
41
42
|
},
|
42
43
|
"label": {
|
43
44
|
"type": "string"
|
@@ -50,6 +51,25 @@
|
|
50
51
|
}
|
51
52
|
}
|
52
53
|
},
|
54
|
+
"accordion_toggle": {
|
55
|
+
"type": "object",
|
56
|
+
"required": ["type", "toggle_attribute", "elements"],
|
57
|
+
"properties": {
|
58
|
+
"type": {
|
59
|
+
"type": "string",
|
60
|
+
"const": "accordion_toggle"
|
61
|
+
},
|
62
|
+
"toggle_attribute": {
|
63
|
+
"type": "string"
|
64
|
+
},
|
65
|
+
"elements": {
|
66
|
+
"type": "array",
|
67
|
+
"items": {
|
68
|
+
"oneOf": [{ "type": "string" }, { "$ref": "#/$defs/attribute" }]
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
},
|
53
73
|
"attribute": {
|
54
74
|
"type": "object",
|
55
75
|
"required": ["name", "type"],
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easol-canvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Byrne
|
8
8
|
- Ian Mooney
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-07-
|
12
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -155,7 +155,7 @@ homepage: https://rubygems.org/gems/easol-canvas
|
|
155
155
|
licenses:
|
156
156
|
- MIT
|
157
157
|
metadata: {}
|
158
|
-
post_install_message:
|
158
|
+
post_install_message:
|
159
159
|
rdoc_options: []
|
160
160
|
require_paths:
|
161
161
|
- lib
|
@@ -170,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
174
|
-
signing_key:
|
173
|
+
rubygems_version: 3.1.6
|
174
|
+
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: CLI to help with building themes for Easol
|
177
177
|
test_files: []
|