easol-canvas 0.1.1 → 1.0.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/checks/valid_block_schemas_check.rb +72 -0
- data/lib/canvas/checks/valid_footer_schema_check.rb +81 -0
- data/lib/canvas/checks/valid_json_check.rb +24 -0
- data/lib/canvas/checks/valid_liquid_check.rb +1 -1
- data/lib/canvas/checks/valid_menu_schema_check.rb +81 -0
- data/lib/canvas/constants.rb +12 -0
- data/lib/canvas/services/expand_attributes.rb +40 -0
- data/lib/canvas/services/fetch_custom_types.rb +27 -0
- data/lib/canvas/validators/block_schema.rb +86 -0
- data/lib/canvas/validators/footer_schema.rb +29 -0
- data/lib/canvas/validators/html.rb +2 -2
- data/lib/canvas/validators/json.rb +21 -0
- data/lib/canvas/validators/liquid.rb +1 -1
- data/lib/canvas/validators/menu_schema.rb +95 -0
- data/lib/canvas/validators/schema_attribute.rb +147 -0
- data/lib/canvas/validators/schema_attributes/base.rb +104 -0
- data/lib/canvas/validators/schema_attributes/color.rb +81 -0
- data/lib/canvas/validators/schema_attributes/image.rb +45 -0
- data/lib/canvas/validators/schema_attributes/link.rb +51 -0
- data/lib/canvas/validators/schema_attributes/number.rb +17 -0
- data/lib/canvas/validators/schema_attributes/page.rb +49 -0
- data/lib/canvas/validators/schema_attributes/post.rb +49 -0
- data/lib/canvas/validators/schema_attributes/product.rb +49 -0
- data/lib/canvas/validators/schema_attributes/radio.rb +55 -0
- data/lib/canvas/validators/schema_attributes/range.rb +24 -0
- data/lib/canvas/validators/schema_attributes/select.rb +59 -0
- data/lib/canvas/validators/schema_attributes/variant.rb +49 -0
- data/lib/canvas/version.rb +1 -1
- data/lib/canvas.rb +14 -3
- metadata +43 -19
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Canvas
|
6
|
+
module Validator
|
7
|
+
class SchemaAttribute
|
8
|
+
# :documented:
|
9
|
+
# Attribute validations specific to select-type variables.
|
10
|
+
class Select < Base
|
11
|
+
def validate
|
12
|
+
super &&
|
13
|
+
ensure_at_least_one_option &&
|
14
|
+
ensure_options_are_valid
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def permitted_values_for_default_key
|
20
|
+
if attribute["options"].is_a?(Array)
|
21
|
+
attribute["options"].map { |option|
|
22
|
+
option["value"] if option.is_a?(Hash)
|
23
|
+
}
|
24
|
+
else
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def required_keys
|
30
|
+
super.merge(
|
31
|
+
"options" => Array
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def ensure_at_least_one_option
|
36
|
+
return true if attribute["options"].length.positive?
|
37
|
+
|
38
|
+
@errors << "Must provide at least 1 option for select type variable"
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def select_option_validate(option)
|
43
|
+
option.is_a?(Hash) &&
|
44
|
+
option.key?("value") &&
|
45
|
+
option.key?("label")
|
46
|
+
end
|
47
|
+
|
48
|
+
def ensure_options_are_valid
|
49
|
+
return true if attribute["options"].all? { |option|
|
50
|
+
select_option_validate(option)
|
51
|
+
}
|
52
|
+
|
53
|
+
@errors << "All options for select type variable must specify a label and value"
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Canvas
|
4
|
+
module Validator
|
5
|
+
class SchemaAttribute
|
6
|
+
# :documented:
|
7
|
+
# Attribute validations specific to variant-type variables.
|
8
|
+
class Variant < Base
|
9
|
+
ALLOWED_DEFAULT_VALUES = %w[random].freeze
|
10
|
+
|
11
|
+
def validate
|
12
|
+
super &&
|
13
|
+
ensure_default_values_are_valid
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def permitted_values_for_default_key
|
19
|
+
if attribute["array"]
|
20
|
+
Array
|
21
|
+
else
|
22
|
+
String
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def ensure_default_values_are_valid
|
27
|
+
return true unless attribute.key?("default")
|
28
|
+
|
29
|
+
if attribute["array"]
|
30
|
+
attribute["default"].all? { |value| default_value_is_valid?(value) }
|
31
|
+
else
|
32
|
+
default_value_is_valid?(attribute["default"])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def default_value_is_valid?(value)
|
37
|
+
value = value.downcase
|
38
|
+
if !ALLOWED_DEFAULT_VALUES.include?(value)
|
39
|
+
@errors << "\"default\" for variant-type variables must be "\
|
40
|
+
"one of: #{ALLOWED_DEFAULT_VALUES.join(', ')}"
|
41
|
+
false
|
42
|
+
else
|
43
|
+
true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/canvas/version.rb
CHANGED
data/lib/canvas.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
require_relative "canvas/version"
|
2
|
+
require_relative "canvas/constants"
|
2
3
|
require_relative "canvas/cli"
|
3
4
|
require_relative "canvas/lint"
|
4
|
-
require_relative "canvas/validators/html"
|
5
|
-
require_relative "canvas/validators/liquid"
|
6
5
|
require_relative "canvas/check"
|
7
6
|
require_relative "canvas/offense"
|
8
7
|
require_relative "canvas/checks"
|
9
8
|
|
10
|
-
|
9
|
+
# We need to ensure Canvas::Validator::SchemaAttribute::Base is required first
|
10
|
+
require_relative "canvas/validators/schema_attributes/base"
|
11
|
+
|
12
|
+
# The attribute validators need to be required before Canvas::Validator::SchemaAttribute
|
13
|
+
attribute_validators = Dir["#{__dir__}/canvas/validators/schema_attributes/*.rb"]
|
14
|
+
attribute_validators.each { |file| require file }
|
15
|
+
|
16
|
+
files = Dir["#{__dir__}/canvas/{checks,services,validators}/*.rb"]
|
17
|
+
files.each { |file| require file }
|
11
18
|
|
12
19
|
Canvas::Checks.register(Canvas::RequiredFilesCheck)
|
13
20
|
Canvas::Checks.register(Canvas::ValidHtmlCheck)
|
14
21
|
Canvas::Checks.register(Canvas::ValidLiquidCheck)
|
22
|
+
Canvas::Checks.register(Canvas::ValidBlockSchemasCheck)
|
23
|
+
Canvas::Checks.register(Canvas::ValidMenuSchemaCheck)
|
24
|
+
Canvas::Checks.register(Canvas::ValidFooterSchemaCheck)
|
25
|
+
Canvas::Checks.register(Canvas::ValidJsonCheck)
|
15
26
|
|
16
27
|
module Canvas
|
17
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easol-canvas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Byrne
|
@@ -9,64 +9,64 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-05-
|
12
|
+
date: 2022-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '1.2'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '1.2'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: nokogiri
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '1.13'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '1.13'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: cli-ui
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '1.5'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '1.5'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: liquid
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '5.3'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '5.3'
|
70
70
|
description: |
|
71
71
|
Canvas is a command line tool to help with building themes for Easol.
|
72
72
|
It provides tooling to check theme directories for errors and to make sure
|
@@ -83,16 +83,40 @@ files:
|
|
83
83
|
- lib/canvas/check.rb
|
84
84
|
- lib/canvas/checks.rb
|
85
85
|
- lib/canvas/checks/required_files_check.rb
|
86
|
+
- lib/canvas/checks/valid_block_schemas_check.rb
|
87
|
+
- lib/canvas/checks/valid_footer_schema_check.rb
|
86
88
|
- lib/canvas/checks/valid_html_check.rb
|
89
|
+
- lib/canvas/checks/valid_json_check.rb
|
87
90
|
- lib/canvas/checks/valid_liquid_check.rb
|
91
|
+
- lib/canvas/checks/valid_menu_schema_check.rb
|
88
92
|
- lib/canvas/cli.rb
|
93
|
+
- lib/canvas/constants.rb
|
89
94
|
- lib/canvas/lint.rb
|
90
95
|
- lib/canvas/offense.rb
|
96
|
+
- lib/canvas/services/expand_attributes.rb
|
97
|
+
- lib/canvas/services/fetch_custom_types.rb
|
91
98
|
- lib/canvas/services/front_matter_extractor.rb
|
99
|
+
- lib/canvas/validators/block_schema.rb
|
100
|
+
- lib/canvas/validators/footer_schema.rb
|
92
101
|
- lib/canvas/validators/html.rb
|
102
|
+
- lib/canvas/validators/json.rb
|
93
103
|
- lib/canvas/validators/liquid.rb
|
104
|
+
- lib/canvas/validators/menu_schema.rb
|
105
|
+
- lib/canvas/validators/schema_attribute.rb
|
106
|
+
- lib/canvas/validators/schema_attributes/base.rb
|
107
|
+
- lib/canvas/validators/schema_attributes/color.rb
|
108
|
+
- lib/canvas/validators/schema_attributes/image.rb
|
109
|
+
- lib/canvas/validators/schema_attributes/link.rb
|
110
|
+
- lib/canvas/validators/schema_attributes/number.rb
|
111
|
+
- lib/canvas/validators/schema_attributes/page.rb
|
112
|
+
- lib/canvas/validators/schema_attributes/post.rb
|
113
|
+
- lib/canvas/validators/schema_attributes/product.rb
|
114
|
+
- lib/canvas/validators/schema_attributes/radio.rb
|
115
|
+
- lib/canvas/validators/schema_attributes/range.rb
|
116
|
+
- lib/canvas/validators/schema_attributes/select.rb
|
117
|
+
- lib/canvas/validators/schema_attributes/variant.rb
|
94
118
|
- lib/canvas/version.rb
|
95
|
-
homepage:
|
119
|
+
homepage: https://rubygems.org/gems/easol-canvas
|
96
120
|
licenses:
|
97
121
|
- MIT
|
98
122
|
metadata: {}
|