easol-canvas 0.1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/canvas/check.rb +4 -1
  3. data/lib/canvas/checks/required_files_check.rb +3 -0
  4. data/lib/canvas/checks/valid_block_schemas_check.rb +72 -0
  5. data/lib/canvas/checks/valid_custom_types_check.rb +36 -0
  6. data/lib/canvas/checks/valid_footer_schema_check.rb +81 -0
  7. data/lib/canvas/checks/valid_html_check.rb +3 -0
  8. data/lib/canvas/checks/valid_json_check.rb +27 -0
  9. data/lib/canvas/checks/valid_liquid_check.rb +4 -1
  10. data/lib/canvas/checks/valid_menu_schema_check.rb +81 -0
  11. data/lib/canvas/checks.rb +4 -1
  12. data/lib/canvas/cli.rb +10 -1
  13. data/lib/canvas/constants.rb +31 -0
  14. data/lib/canvas/lint.rb +8 -4
  15. data/lib/canvas/offense.rb +3 -0
  16. data/lib/canvas/services/expand_attributes.rb +40 -0
  17. data/lib/canvas/services/fetch_custom_types.rb +27 -0
  18. data/lib/canvas/services/front_matter_extractor.rb +1 -0
  19. data/lib/canvas/validators/block_schema.rb +86 -0
  20. data/lib/canvas/validators/custom_type.rb +129 -0
  21. data/lib/canvas/validators/footer_schema.rb +29 -0
  22. data/lib/canvas/validators/html.rb +5 -2
  23. data/lib/canvas/validators/json.rb +24 -0
  24. data/lib/canvas/validators/liquid.rb +4 -1
  25. data/lib/canvas/validators/menu_schema.rb +95 -0
  26. data/lib/canvas/validators/schema_attribute.rb +146 -0
  27. data/lib/canvas/validators/schema_attributes/base.rb +104 -0
  28. data/lib/canvas/validators/schema_attributes/color.rb +81 -0
  29. data/lib/canvas/validators/schema_attributes/image.rb +45 -0
  30. data/lib/canvas/validators/schema_attributes/link.rb +51 -0
  31. data/lib/canvas/validators/schema_attributes/number.rb +17 -0
  32. data/lib/canvas/validators/schema_attributes/page.rb +49 -0
  33. data/lib/canvas/validators/schema_attributes/post.rb +49 -0
  34. data/lib/canvas/validators/schema_attributes/product.rb +49 -0
  35. data/lib/canvas/validators/schema_attributes/radio.rb +55 -0
  36. data/lib/canvas/validators/schema_attributes/range.rb +24 -0
  37. data/lib/canvas/validators/schema_attributes/select.rb +59 -0
  38. data/lib/canvas/validators/schema_attributes/variant.rb +49 -0
  39. data/lib/canvas/version.rb +3 -1
  40. data/lib/canvas.rb +21 -3
  41. metadata +47 -20
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Canvas
4
+ module Validator
5
+ class SchemaAttribute
6
+ # :documented:
7
+ # Attribute validations specific to link-type variables.
8
+ class Link < Base
9
+ ALLOWED_DEFAULT_KEYS = %w[url page post product].freeze
10
+ INVALID_DEFAULT_ERROR = "\"default\" for link-type variables must include "\
11
+ "a single url, page, post or product value"
12
+
13
+ def validate
14
+ super &&
15
+ ensure_single_default_provided &&
16
+ ensure_default_key_is_valid
17
+ end
18
+
19
+ private
20
+
21
+ def permitted_values_for_default_key
22
+ Hash
23
+ end
24
+
25
+ def ensure_default_key_is_valid
26
+ return true unless attribute.key?("default")
27
+
28
+ key = attribute["default"].keys.first
29
+
30
+ unless ALLOWED_DEFAULT_KEYS.include?(key)
31
+ @errors << INVALID_DEFAULT_ERROR
32
+ return false
33
+ end
34
+
35
+ true
36
+ end
37
+
38
+ def ensure_single_default_provided
39
+ return true unless attribute.key?("default")
40
+
41
+ if attribute["default"].count != 1
42
+ @errors << INVALID_DEFAULT_ERROR
43
+ return false
44
+ end
45
+
46
+ true
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Canvas
4
+ module Validator
5
+ class SchemaAttribute
6
+ # :documented:
7
+ # Attribute validations specific to number-type variables.
8
+ class Number < Base
9
+ private
10
+
11
+ def optional_keys
12
+ super.merge("unit" => String)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ 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 page-type variables.
8
+ class Page < 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_validate(value) }
31
+ else
32
+ default_value_is_validate(attribute["default"])
33
+ end
34
+ end
35
+
36
+ def default_value_is_validate(value)
37
+ value = value.downcase
38
+ if !ALLOWED_DEFAULT_VALUES.include?(value)
39
+ @errors << "\"default\" for page-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
@@ -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 post-type variables.
8
+ class Post < 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 post-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
@@ -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 product-type variables.
8
+ class Product < 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 product-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
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Canvas
4
+ module Validator
5
+ class SchemaAttribute
6
+ # :documented:
7
+ # Attribute validations specific to radio-type variables.
8
+ class Radio < Base
9
+ def validate
10
+ super &&
11
+ ensure_at_least_one_option &&
12
+ ensure_options_are_valid
13
+ end
14
+
15
+ private
16
+
17
+ def permitted_values_for_default_key
18
+ if attribute["options"].is_a?(Array)
19
+ attribute["options"].map { |option| option["value"] }
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ def required_keys
26
+ super.merge(
27
+ "options" => Array
28
+ )
29
+ end
30
+
31
+ def ensure_at_least_one_option
32
+ return true if attribute["options"].length.positive?
33
+
34
+ @errors << "Must provide at least 1 option for radio type variable"
35
+ false
36
+ end
37
+
38
+ def ensure_options_are_valid
39
+ return true if attribute["options"].all? { |option|
40
+ select_option_valid?(option)
41
+ }
42
+
43
+ @errors << "All options for radio type variable must specify a label and value"
44
+ false
45
+ end
46
+
47
+ def select_option_valid?(option)
48
+ option.is_a?(Hash) &&
49
+ option.key?("value") &&
50
+ option.key?("label")
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
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 range-type variables.
10
+ class Range < Base
11
+ private
12
+
13
+ def optional_keys
14
+ super.merge(
15
+ "min" => Object,
16
+ "max" => Object,
17
+ "step" => Object,
18
+ "unit" => String
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Canvas
2
- VERSION = "0.1.0"
4
+ VERSION = "1.1.0"
3
5
  end
data/lib/canvas.rb CHANGED
@@ -1,17 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "canvas/version"
4
+ require_relative "canvas/constants"
2
5
  require_relative "canvas/cli"
3
6
  require_relative "canvas/lint"
4
- require_relative "canvas/validators/html"
5
- require_relative "canvas/validators/liquid"
6
7
  require_relative "canvas/check"
7
8
  require_relative "canvas/offense"
8
9
  require_relative "canvas/checks"
9
10
 
10
- Dir[__dir__ + "/canvas/{checks,services}/*.rb"].each { |file| require file }
11
+ # We need to ensure Canvas::Validator::SchemaAttribute::Base is required first
12
+ require_relative "canvas/validators/schema_attributes/base"
13
+
14
+ # The attribute validators need to be required before Canvas::Validator::SchemaAttribute
15
+ attribute_validators = Dir["#{__dir__}/canvas/validators/schema_attributes/*.rb"]
16
+ attribute_validators.each do |file|
17
+ require file
18
+ end
19
+
20
+ files = Dir["#{__dir__}/canvas/{checks,services,validators}/*.rb"]
21
+ files.each do |file|
22
+ require file
23
+ end
11
24
 
12
25
  Canvas::Checks.register(Canvas::RequiredFilesCheck)
13
26
  Canvas::Checks.register(Canvas::ValidHtmlCheck)
14
27
  Canvas::Checks.register(Canvas::ValidLiquidCheck)
28
+ Canvas::Checks.register(Canvas::ValidJsonCheck)
29
+ Canvas::Checks.register(Canvas::ValidBlockSchemasCheck)
30
+ Canvas::Checks.register(Canvas::ValidMenuSchemaCheck)
31
+ Canvas::Checks.register(Canvas::ValidFooterSchemaCheck)
32
+ Canvas::Checks.register(Canvas::ValidCustomTypesCheck)
15
33
 
16
34
  module Canvas
17
35
  end
metadata CHANGED
@@ -1,76 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easol-canvas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Byrne
8
+ - Ian Mooney
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
12
+ date: 2022-06-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: thor
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ">="
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '0'
20
+ version: '1.2'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ">="
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '0'
27
+ version: '1.2'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: nokogiri
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '0'
34
+ version: '1.13'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: '0'
41
+ version: '1.13'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: cli-ui
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '0'
48
+ version: '1.5'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ">="
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '0'
55
+ version: '1.5'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: liquid
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
- - - ">="
60
+ - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: '0'
62
+ version: '5.3'
62
63
  type: :runtime
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
- - - ">="
67
+ - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: '0'
69
+ version: '5.3'
69
70
  description: |
70
71
  Canvas is a command line tool to help with building themes for Easol.
71
72
  It provides tooling to check theme directories for errors and to make sure
72
73
  they confirm with the Easol theme spec.
73
- email: kyle@easol.com
74
+ email: developers@easol.com
74
75
  executables:
75
76
  - canvas
76
77
  extensions: []
@@ -82,16 +83,42 @@ files:
82
83
  - lib/canvas/check.rb
83
84
  - lib/canvas/checks.rb
84
85
  - lib/canvas/checks/required_files_check.rb
86
+ - lib/canvas/checks/valid_block_schemas_check.rb
87
+ - lib/canvas/checks/valid_custom_types_check.rb
88
+ - lib/canvas/checks/valid_footer_schema_check.rb
85
89
  - lib/canvas/checks/valid_html_check.rb
90
+ - lib/canvas/checks/valid_json_check.rb
86
91
  - lib/canvas/checks/valid_liquid_check.rb
92
+ - lib/canvas/checks/valid_menu_schema_check.rb
87
93
  - lib/canvas/cli.rb
94
+ - lib/canvas/constants.rb
88
95
  - lib/canvas/lint.rb
89
96
  - lib/canvas/offense.rb
97
+ - lib/canvas/services/expand_attributes.rb
98
+ - lib/canvas/services/fetch_custom_types.rb
90
99
  - lib/canvas/services/front_matter_extractor.rb
100
+ - lib/canvas/validators/block_schema.rb
101
+ - lib/canvas/validators/custom_type.rb
102
+ - lib/canvas/validators/footer_schema.rb
91
103
  - lib/canvas/validators/html.rb
104
+ - lib/canvas/validators/json.rb
92
105
  - lib/canvas/validators/liquid.rb
106
+ - lib/canvas/validators/menu_schema.rb
107
+ - lib/canvas/validators/schema_attribute.rb
108
+ - lib/canvas/validators/schema_attributes/base.rb
109
+ - lib/canvas/validators/schema_attributes/color.rb
110
+ - lib/canvas/validators/schema_attributes/image.rb
111
+ - lib/canvas/validators/schema_attributes/link.rb
112
+ - lib/canvas/validators/schema_attributes/number.rb
113
+ - lib/canvas/validators/schema_attributes/page.rb
114
+ - lib/canvas/validators/schema_attributes/post.rb
115
+ - lib/canvas/validators/schema_attributes/product.rb
116
+ - lib/canvas/validators/schema_attributes/radio.rb
117
+ - lib/canvas/validators/schema_attributes/range.rb
118
+ - lib/canvas/validators/schema_attributes/select.rb
119
+ - lib/canvas/validators/schema_attributes/variant.rb
93
120
  - lib/canvas/version.rb
94
- homepage:
121
+ homepage: https://rubygems.org/gems/easol-canvas
95
122
  licenses:
96
123
  - MIT
97
124
  metadata: {}