easol-canvas 0.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) 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/valid_sass_check.rb +30 -0
  12. data/lib/canvas/checks.rb +4 -1
  13. data/lib/canvas/cli.rb +10 -1
  14. data/lib/canvas/constants.rb +31 -0
  15. data/lib/canvas/lint.rb +7 -4
  16. data/lib/canvas/offense.rb +3 -0
  17. data/lib/canvas/services/expand_attributes.rb +40 -0
  18. data/lib/canvas/services/fetch_custom_types.rb +27 -0
  19. data/lib/canvas/services/front_matter_extractor.rb +1 -0
  20. data/lib/canvas/validators/block_schema.rb +86 -0
  21. data/lib/canvas/validators/custom_type.rb +141 -0
  22. data/lib/canvas/validators/footer_schema.rb +29 -0
  23. data/lib/canvas/validators/html.rb +5 -2
  24. data/lib/canvas/validators/json.rb +24 -0
  25. data/lib/canvas/validators/liquid.rb +4 -1
  26. data/lib/canvas/validators/menu_schema.rb +95 -0
  27. data/lib/canvas/validators/sass.rb +26 -0
  28. data/lib/canvas/validators/schema_attribute.rb +146 -0
  29. data/lib/canvas/validators/schema_attributes/base.rb +104 -0
  30. data/lib/canvas/validators/schema_attributes/color.rb +81 -0
  31. data/lib/canvas/validators/schema_attributes/image.rb +45 -0
  32. data/lib/canvas/validators/schema_attributes/link.rb +51 -0
  33. data/lib/canvas/validators/schema_attributes/number.rb +17 -0
  34. data/lib/canvas/validators/schema_attributes/page.rb +49 -0
  35. data/lib/canvas/validators/schema_attributes/post.rb +49 -0
  36. data/lib/canvas/validators/schema_attributes/product.rb +49 -0
  37. data/lib/canvas/validators/schema_attributes/radio.rb +55 -0
  38. data/lib/canvas/validators/schema_attributes/range.rb +24 -0
  39. data/lib/canvas/validators/schema_attributes/select.rb +59 -0
  40. data/lib/canvas/validators/schema_attributes/variant.rb +49 -0
  41. data/lib/canvas/version.rb +3 -1
  42. data/lib/canvas.rb +30 -12
  43. data/lib/easol/canvas.rb +4 -0
  44. metadata +62 -19
@@ -0,0 +1,45 @@
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 Image < Base
9
+ ALLOWED_DEFAULT_KEYS = %w[url asset].freeze
10
+
11
+ def validate
12
+ super && ensure_default_key_is_valid
13
+ end
14
+
15
+ private
16
+
17
+ def ensure_default_key_is_valid
18
+ return true unless attribute.key?("default")
19
+
20
+ if attribute["array"]
21
+ attribute["default"].all? { |value| default_value_is_validate(value) }
22
+ else
23
+ default_value_is_validate(attribute["default"])
24
+ end
25
+ end
26
+
27
+ # The default value can be one of 3 different formats:
28
+ # - A string (for backwards compatibility) e.g. "http://my-image.jpg"
29
+ # - A hash with "url" key" e.g. { "url": "http://my-image.jpg" }
30
+ # - A hash with "asset" key" e.g. { "asset": "http://my-image.jpg" }
31
+ def default_value_is_validate(value)
32
+ return true if value.is_a?(String)
33
+
34
+ return true if value.is_a?(Hash) &&
35
+ value.keys.size == 1 &&
36
+ ALLOWED_DEFAULT_KEYS.include?(value.keys.first) &&
37
+ value.values.first.is_a?(String)
38
+
39
+ @errors << "\"default\" for image-type variables must include a single url or asset value"
40
+ false
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -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.1"
4
+ VERSION = "1.2.0"
3
5
  end
data/lib/canvas.rb CHANGED
@@ -1,17 +1,35 @@
1
- require_relative "canvas/version"
2
- require_relative "canvas/cli"
3
- require_relative "canvas/lint"
4
- require_relative "canvas/validators/html"
5
- require_relative "canvas/validators/liquid"
6
- require_relative "canvas/check"
7
- require_relative "canvas/offense"
8
- require_relative "canvas/checks"
1
+ # frozen_string_literal: true
9
2
 
10
- Dir[__dir__ + "/canvas/{checks,services}/*.rb"].each { |file| require file }
3
+ module Canvas
4
+ autoload :Check, "canvas/check"
5
+ autoload :Checks, "canvas/checks"
6
+ autoload :Cli, "canvas/cli"
7
+ autoload :Constants, "canvas/constants"
8
+ autoload :Lint, "canvas/lint"
9
+ autoload :Offense, "canvas/offense"
10
+ autoload :Version, "canvas/version"
11
+ end
12
+
13
+ # We need to ensure Canvas::Validator::SchemaAttribute::Base is required first
14
+ require_relative "canvas/validators/schema_attributes/base"
15
+
16
+ # The attribute validators need to be required before Canvas::Validator::SchemaAttribute
17
+ attribute_validators = Dir["#{__dir__}/canvas/validators/schema_attributes/*.rb"]
18
+ attribute_validators.each do |file|
19
+ require file
20
+ end
21
+
22
+ files = Dir["#{__dir__}/canvas/{checks,services,validators}/*.rb"]
23
+ files.each do |file|
24
+ require file
25
+ end
11
26
 
12
27
  Canvas::Checks.register(Canvas::RequiredFilesCheck)
13
28
  Canvas::Checks.register(Canvas::ValidHtmlCheck)
14
29
  Canvas::Checks.register(Canvas::ValidLiquidCheck)
15
-
16
- module Canvas
17
- end
30
+ Canvas::Checks.register(Canvas::ValidJsonCheck)
31
+ Canvas::Checks.register(Canvas::ValidSassCheck)
32
+ Canvas::Checks.register(Canvas::ValidBlockSchemasCheck)
33
+ Canvas::Checks.register(Canvas::ValidMenuSchemaCheck)
34
+ Canvas::Checks.register(Canvas::ValidFooterSchemaCheck)
35
+ Canvas::Checks.register(Canvas::ValidCustomTypesCheck)
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Enables using this gem "as is"
4
+ require_relative "../canvas"
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.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Byrne
@@ -9,64 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-20 00:00:00.000000000 Z
12
+ date: 2022-06-07 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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
69
+ version: '5.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: sassc
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.4'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '2.4'
70
84
  description: |
71
85
  Canvas is a command line tool to help with building themes for Easol.
72
86
  It provides tooling to check theme directories for errors and to make sure
@@ -83,16 +97,45 @@ files:
83
97
  - lib/canvas/check.rb
84
98
  - lib/canvas/checks.rb
85
99
  - lib/canvas/checks/required_files_check.rb
100
+ - lib/canvas/checks/valid_block_schemas_check.rb
101
+ - lib/canvas/checks/valid_custom_types_check.rb
102
+ - lib/canvas/checks/valid_footer_schema_check.rb
86
103
  - lib/canvas/checks/valid_html_check.rb
104
+ - lib/canvas/checks/valid_json_check.rb
87
105
  - lib/canvas/checks/valid_liquid_check.rb
106
+ - lib/canvas/checks/valid_menu_schema_check.rb
107
+ - lib/canvas/checks/valid_sass_check.rb
88
108
  - lib/canvas/cli.rb
109
+ - lib/canvas/constants.rb
89
110
  - lib/canvas/lint.rb
90
111
  - lib/canvas/offense.rb
112
+ - lib/canvas/services/expand_attributes.rb
113
+ - lib/canvas/services/fetch_custom_types.rb
91
114
  - lib/canvas/services/front_matter_extractor.rb
115
+ - lib/canvas/validators/block_schema.rb
116
+ - lib/canvas/validators/custom_type.rb
117
+ - lib/canvas/validators/footer_schema.rb
92
118
  - lib/canvas/validators/html.rb
119
+ - lib/canvas/validators/json.rb
93
120
  - lib/canvas/validators/liquid.rb
121
+ - lib/canvas/validators/menu_schema.rb
122
+ - lib/canvas/validators/sass.rb
123
+ - lib/canvas/validators/schema_attribute.rb
124
+ - lib/canvas/validators/schema_attributes/base.rb
125
+ - lib/canvas/validators/schema_attributes/color.rb
126
+ - lib/canvas/validators/schema_attributes/image.rb
127
+ - lib/canvas/validators/schema_attributes/link.rb
128
+ - lib/canvas/validators/schema_attributes/number.rb
129
+ - lib/canvas/validators/schema_attributes/page.rb
130
+ - lib/canvas/validators/schema_attributes/post.rb
131
+ - lib/canvas/validators/schema_attributes/product.rb
132
+ - lib/canvas/validators/schema_attributes/radio.rb
133
+ - lib/canvas/validators/schema_attributes/range.rb
134
+ - lib/canvas/validators/schema_attributes/select.rb
135
+ - lib/canvas/validators/schema_attributes/variant.rb
94
136
  - lib/canvas/version.rb
95
- homepage:
137
+ - lib/easol/canvas.rb
138
+ homepage: https://rubygems.org/gems/easol-canvas
96
139
  licenses:
97
140
  - MIT
98
141
  metadata: {}