custom_elements_manifest_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +84 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +66 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +244 -0
  8. data/Rakefile +23 -0
  9. data/bin/console +15 -0
  10. data/bin/setup +8 -0
  11. data/custom_elements_manifest_parser.gemspec +43 -0
  12. data/lib/custom_elements_manifest_parser/base_struct.rb +10 -0
  13. data/lib/custom_elements_manifest_parser/data_types/attribute.rb +57 -0
  14. data/lib/custom_elements_manifest_parser/data_types/css_custom_property.rb +47 -0
  15. data/lib/custom_elements_manifest_parser/data_types/css_part.rb +32 -0
  16. data/lib/custom_elements_manifest_parser/data_types/demo.rb +29 -0
  17. data/lib/custom_elements_manifest_parser/data_types/event.rb +40 -0
  18. data/lib/custom_elements_manifest_parser/data_types/function_return_type.rb +25 -0
  19. data/lib/custom_elements_manifest_parser/data_types/parameter.rb +33 -0
  20. data/lib/custom_elements_manifest_parser/data_types/reference.rb +36 -0
  21. data/lib/custom_elements_manifest_parser/data_types/resolve_initializer.rb +16 -0
  22. data/lib/custom_elements_manifest_parser/data_types/slot.rb +31 -0
  23. data/lib/custom_elements_manifest_parser/data_types/source_reference.rb +17 -0
  24. data/lib/custom_elements_manifest_parser/data_types/type.rb +34 -0
  25. data/lib/custom_elements_manifest_parser/data_types/type_reference.rb +22 -0
  26. data/lib/custom_elements_manifest_parser/nodes/class_declaration.rb +39 -0
  27. data/lib/custom_elements_manifest_parser/nodes/class_field.rb +50 -0
  28. data/lib/custom_elements_manifest_parser/nodes/class_method.rb +55 -0
  29. data/lib/custom_elements_manifest_parser/nodes/custom_element_export.rb +52 -0
  30. data/lib/custom_elements_manifest_parser/nodes/custom_element_field.rb +23 -0
  31. data/lib/custom_elements_manifest_parser/nodes/function_declaration.rb +39 -0
  32. data/lib/custom_elements_manifest_parser/nodes/javascript_export.rb +59 -0
  33. data/lib/custom_elements_manifest_parser/nodes/javascript_module.rb +58 -0
  34. data/lib/custom_elements_manifest_parser/nodes/manifest.rb +36 -0
  35. data/lib/custom_elements_manifest_parser/nodes/mixin_declaration.rb +93 -0
  36. data/lib/custom_elements_manifest_parser/nodes/variable_declaration.rb +41 -0
  37. data/lib/custom_elements_manifest_parser/parser.rb +111 -0
  38. data/lib/custom_elements_manifest_parser/structs/class_like_struct.rb +92 -0
  39. data/lib/custom_elements_manifest_parser/structs/custom_element_like_struct.rb +64 -0
  40. data/lib/custom_elements_manifest_parser/structs/declarable_node_struct.rb +19 -0
  41. data/lib/custom_elements_manifest_parser/structs/function_like_struct.rb +40 -0
  42. data/lib/custom_elements_manifest_parser/structs/property_like_struct.rb +47 -0
  43. data/lib/custom_elements_manifest_parser/types.rb +13 -0
  44. data/lib/custom_elements_manifest_parser/version.rb +5 -0
  45. data/lib/custom_elements_manifest_parser.rb +12 -0
  46. data/sig/custom_elements_manifest_parser.rbs +4 -0
  47. metadata +133 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 510fa863ae80956f1521f6b10c1b36d24e7d5397e14337de1ab424a46a60e00c
4
+ data.tar.gz: 17ff0b9d57ab3343919a32bd0f73a37c8839355817f27fdc9302d5c617f8c057
5
+ SHA512:
6
+ metadata.gz: f5636133ef9fde39a1c4ca70d87bf8879ed17495322a098d7ab465e21dbdf352fd75aece557e321a4bfb6705d1b0b816e89cc39e09c8afd9c306cabaab1d2881
7
+ data.tar.gz: 64ce1244a7226f6641b5007cc1fb58021110bc31a89d89d003f0056bc233e460dc8a145def0232937e1d1a294a4011b3a410af65f77fbcf3ce8f31a52b665c95
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-03
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at konnor5456@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in custom_elements_manifest_parser.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "yard"
10
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ custom_elements_manifest_parser (0.1.0)
5
+ dry-struct (~> 1.0)
6
+ dry-types (~> 1.0)
7
+ dry-validation (~> 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ concurrent-ruby (1.2.2)
13
+ dry-configurable (1.1.0)
14
+ dry-core (~> 1.0, < 2)
15
+ zeitwerk (~> 2.6)
16
+ dry-core (1.0.1)
17
+ concurrent-ruby (~> 1.0)
18
+ zeitwerk (~> 2.6)
19
+ dry-inflector (1.0.0)
20
+ dry-initializer (3.1.1)
21
+ dry-logic (1.5.0)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-core (~> 1.0, < 2)
24
+ zeitwerk (~> 2.6)
25
+ dry-schema (1.13.3)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-configurable (~> 1.0, >= 1.0.1)
28
+ dry-core (~> 1.0, < 2)
29
+ dry-initializer (~> 3.0)
30
+ dry-logic (>= 1.4, < 2)
31
+ dry-types (>= 1.7, < 2)
32
+ zeitwerk (~> 2.6)
33
+ dry-struct (1.6.0)
34
+ dry-core (~> 1.0, < 2)
35
+ dry-types (>= 1.7, < 2)
36
+ ice_nine (~> 0.11)
37
+ zeitwerk (~> 2.6)
38
+ dry-types (1.7.1)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-core (~> 1.0)
41
+ dry-inflector (~> 1.0)
42
+ dry-logic (~> 1.4)
43
+ zeitwerk (~> 2.6)
44
+ dry-validation (1.10.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-core (~> 1.0, < 2)
47
+ dry-initializer (~> 3.0)
48
+ dry-schema (>= 1.12, < 2)
49
+ zeitwerk (~> 2.6)
50
+ ice_nine (0.11.2)
51
+ minitest (5.20.0)
52
+ rake (13.0.6)
53
+ yard (0.9.34)
54
+ zeitwerk (2.6.12)
55
+
56
+ PLATFORMS
57
+ arm64-darwin-22
58
+
59
+ DEPENDENCIES
60
+ custom_elements_manifest_parser!
61
+ minitest (~> 5.0)
62
+ rake (~> 13.0)
63
+ yard
64
+
65
+ BUNDLED WITH
66
+ 2.2.33
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 konnorrogers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # CustomElementsManifestParser
2
+
3
+ The CustomElementsManifestParser is intended to be a way to parse + interact with JSON
4
+ generated from here: <https://github.com/open-wc/custom-elements-manifest>
5
+
6
+ ## Why?
7
+
8
+ I wanted to generate some slots, attributes, etc for my custom elements in my [Bridgetown](https://www.bridgetownrb.com/) site, and I got bored and decided to build a parser as a fun academic exercise. The parser is based on the schema defined here:
9
+
10
+ <https://github.com/webcomponents/custom-elements-manifest/blob/main/schema.d.ts>
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'custom_elements_manifest_parser'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```bash
23
+ bundle install
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```bash
29
+ bundle add custom_elements_manifest_parser
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ require "json"
36
+ require "custom_elements_manifest_parser"
37
+
38
+ custom_elements_manifest = JSON.parse(File.read("custom-elements.json"))
39
+
40
+ # This is a shortcut for CustomElementsManifestParser::Parser.new(json).parse
41
+ parser = CustomElementsManifestParser.parse(custom_elements_manifest)
42
+
43
+ parser.manifest.schemaVersion # => [String]
44
+ parser.manifest.readme # => [String, nil]
45
+ parser.manifest.deprecated # => [String, Boolean, nil]
46
+
47
+ # Manual Traversal through.
48
+ parser.manifest.modules.each do |mod|
49
+ mod.path # => The file path to the JavaScript module.
50
+
51
+ mod.exports.each do |export|
52
+ # do something with exports
53
+ end
54
+
55
+ mod.declarations.each do |declaration|
56
+ # do something with a declaration
57
+ end
58
+ end
59
+
60
+ ## Convenience Helpers
61
+
62
+ # Searches for the tagName of the custom elements
63
+ parser.find_custom_elements("light-pen", "light-preview").each { |declaration| declaration }
64
+ parser.find_custom_elements(["light-pen", "light-preview"]).each { |declaration| declaration }
65
+
66
+ # Searches for all custom elements regardless of tagName
67
+ parser.find_custom_elements.each do |declaration|
68
+ # Declarations store a "parent_module" to easily access the import path.
69
+ declaration.parent_module.path
70
+
71
+ # Get custom element "tagName", this may sometimes be nil.
72
+ declaration.tagName
73
+
74
+ # Get the name of the class
75
+ declaration.name
76
+ end
77
+ ```
78
+
79
+ ## Extending
80
+
81
+ Because the schema is really a JSON file you can dump anything into, there does need to be some
82
+ room to extend because not all schemas are equal (as I discovered trying to parse Shoelace's manifest).
83
+
84
+ ### Replacing the Parser
85
+
86
+ Subclass the parser and go to town!
87
+
88
+ ```rb
89
+ class MyParser < CustomElementsManifestParser::Parser
90
+ # Do your thing!
91
+ end
92
+
93
+ MyParser.new(json).parse
94
+ ```
95
+
96
+ ### Adding / Removing "visitable_nodes"
97
+
98
+ The parser has `@visitable_nodes` instance variable on it.
99
+
100
+ A `visitable_node` is any node which has a `"kind"` attached to it. Everything in the `CustomElementsManifestParser::Nodes`
101
+ module is considered a `visitable_node` (Except `Manifest` which is a special case)
102
+
103
+ ### Replacing the Manifest
104
+
105
+ The manifest does not live inside of `visitable_nodes` and is instead of a top level attribute. To replace the manifest do the following:
106
+
107
+ ```rb
108
+ require "custom_elements_manifest_parser"
109
+
110
+ class MyManifest < CustomElementsManifestParser::Nodes::Manifest
111
+ attribute :package, CustomElementsManifestParser::Types::Strict::Hash
112
+ end
113
+
114
+ json = JSON.parse(File.read("custom-elements.json"))
115
+
116
+ # This doesn't actually run the parser. This sets up the manifest prior to parsing.
117
+ parser = CustomElementsManifestParser::Parser.new(json)
118
+
119
+ # Replace the manifest
120
+ parser.manifest = MyManifest
121
+
122
+ # Traverse the tree and "visit" each node
123
+ parser.parse
124
+ ```
125
+
126
+ ## Architecture
127
+
128
+ [Dry-Struct](https://dry-rb.org/gems/dry-struct/1.6/) and [Dry-Types](https://dry-rb.org/gems/dry-types/1.7/) are used for cursory data validation.
129
+
130
+ Perhaps in the future [Dry-Validation](https://github.com/dry-rb/dry-validation) will also be used for more complex scenarios.
131
+
132
+ ### Visitable Nodes
133
+
134
+ Visitable nodes are nodes with a `#visit(parser:)` method that when called creates a new instance of
135
+ the node. (This is due to `DryStruct`'s immutability.) When a `#visit` call will need to mutate data structures inside,
136
+ it needs to create a hash and then call `#new`. Like so:
137
+
138
+ ```rb
139
+ def visit(parser:)
140
+ hash = {}
141
+ hash[:thing] = serialize(thing)
142
+ new(hash)
143
+ end
144
+ ```
145
+
146
+ #### Adding a visitable node
147
+
148
+ Visitable Nodes are a hash keyed off of the `"kind"` of the Node.
149
+
150
+ ```rb
151
+ require "custom_elements_manifest_parser"
152
+
153
+ # Wait to call `.parse` until we setup our visitable_nodes
154
+ parser = CustomElementsManifestParser::Parser.new(json)
155
+
156
+ parser.visitable_nodes["js"] = MyJsNode
157
+
158
+ # Erase it all!
159
+ parser.visitable_nodes = {}
160
+
161
+ # Probably won't do anything :shrug:, but you tried!
162
+ parser.parse
163
+ ```
164
+
165
+ ### Data Types
166
+
167
+ Data Types look a lot like `visitable_nodes`, but they don't have an actual `"kind"` within the `custom-elements.json` schema, but
168
+ instead are a best guess at how to serialize a data structure within a `visitable_node`.
169
+
170
+ (The only exception to the `"kind"` rule is the `Nodes::Manifest` class, but that's because that's the top level object so it has an implicit `"kind"`)
171
+
172
+ Data Types can be found in the `CustomElementsManifestParser::DataTypes` module and are attached to the `data_types` attribute
173
+ on the parser.
174
+
175
+ Data Types follow the same interface as `visitable_nodes`.
176
+
177
+ #### Adding a data type
178
+
179
+ ```rb
180
+ require "custom_elements_manifest_parser"
181
+
182
+ # Wait to call `.parse` until we setup our visitable_nodes
183
+ parser = CustomElementsManifestParser::Parser.new(json)
184
+
185
+ parser.data_types[:source] = SourceSerializer
186
+
187
+ # Erase it all!
188
+ parser.data_types = {}
189
+
190
+ # This will probably error out because "visitable_nodes" expect to be able to serialize their children with data_types
191
+ parser.parse
192
+ ```
193
+
194
+ ### Shareable structs
195
+
196
+ Within the `CustomElementsManifestParser::Structs` module you'll find these structs get included by either `DataTypes` or
197
+ `Nodes` by using `attributes_from CustomStruct`. These structs should also implement a `def self.build_hash(parser:, struct:)` function that returns a hash that can then be merged by the parent structs.
198
+
199
+ ```rb
200
+ require_relative "../base_struct.rb"
201
+
202
+ class ShareableStruct < BaseStruct
203
+ def self.build_hash(parser:, struct:)
204
+ hash = {}
205
+ hash[:thing] = do_stuff
206
+ hash
207
+ end
208
+ end
209
+
210
+
211
+ require_relative "../base_struct.rb"
212
+
213
+ class MyStruct < BaseStruct
214
+ attributes_from ShareableStruct
215
+
216
+ def visit(parser:)
217
+ hash = {}
218
+
219
+ hash = hash.merge(ShareableStruct.build_hash(parser: parser, struct: self)
220
+
221
+ new(hash)
222
+ end
223
+ end
224
+ ```
225
+
226
+ The reason we can call `new(hash)` is because `DryStruct` does some heavy lifting with tracking input changes.
227
+
228
+ ## Development
229
+
230
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
231
+
232
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
233
+
234
+ ## Contributing
235
+
236
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/custom_elements_manifest_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/custom_elements_manifest_parser/blob/main/CODE_OF_CONDUCT.md).
237
+
238
+ ## License
239
+
240
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
241
+
242
+ ## Code of Conduct
243
+
244
+ Everyone interacting in the CustomElementsManifestParser project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/custom_elements_manifest_parser/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require 'yard'
13
+
14
+ YARD::Rake::YardocTask.new do |t|
15
+ t.files = [
16
+ 'lib/**/*.rb',
17
+ # OTHER_PATHS
18
+ ]
19
+ # t.options = ['--any', '--extra', '--opts'] # optional
20
+ # t.stats_options = ['--list-undoc'] # optional
21
+ end
22
+
23
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "custom_elements_manifest_parser"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/custom_elements_manifest_parser/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "custom_elements_manifest_parser"
7
+ spec.version = CustomElementsManifestParser::VERSION
8
+ spec.authors = ["konnorrogers"]
9
+ spec.email = ["konnor5456@gmail.com"]
10
+
11
+ spec.summary = "A parser to easily iterate through a custom-elements.json file"
12
+ spec.description = "A parser to easily iterate through a custom-elements.json file"
13
+ spec.homepage = "https://github.com/konnorrogers/custom_elements_manifest_parser"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/konnorrogers/custom_elements_manifest_parser"
21
+ spec.metadata["changelog_uri"] = "https://github.com/konnorrogers/custom_elements_manifest_parser/tree/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ spec.add_dependency "dry-struct", "~> 1.0"
38
+ spec.add_dependency "dry-types", "~> 1.0"
39
+ spec.add_dependency "dry-validation", "~> 1.0"
40
+
41
+ # For more information and examples about making a new gem, checkout our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,10 @@
1
+ require "dry-struct"
2
+
3
+ module CustomElementsManifestParser
4
+ # BaseStruct for data
5
+ class BaseStruct < ::Dry::Struct
6
+ transform_keys(&:to_sym)
7
+
8
+ schema.strict
9
+ end
10
+ end
@@ -0,0 +1,57 @@
1
+ require_relative "../base_struct.rb"
2
+ require_relative "../types.rb"
3
+
4
+ module CustomElementsManifestParser
5
+ module DataTypes
6
+ # Documents an "attribute" on a custom element.
7
+ class Attribute < BaseStruct
8
+ # @param name [String] - The name of the attribute you place on the element.
9
+ attribute :name, Types::Strict::String
10
+
11
+ # @!attribute summary
12
+ # @return [String, nil] - A markdown summary suitable for display in a listing.
13
+ attribute :summary, Types::Strict::String.optional.meta(required: false)
14
+
15
+ # @!attribute description
16
+ # @return [String, nil] - A markdown description.
17
+ attribute :description, Types::Strict::String.optional.meta(required: false)
18
+
19
+ # @!attribute inheritedFrom
20
+ # @return [Reference, nil] - Reference to where it inherited its attribute
21
+ attribute :inheritedFrom, Types::Nominal::Any.optional.meta(required: false)
22
+
23
+ # @!attribute type
24
+ # @return [Type, nil] - The type that the attribute will be serialized/deserialized as.
25
+ attribute :type, Types::Nominal::Any.optional.meta(required: false)
26
+
27
+ # @!attribute default
28
+ # @return [String, nil] -
29
+ # The default value of the attribute, if any.
30
+ # As attributes are always strings, this is the actual value, not a human
31
+ # readable description.
32
+ attribute :default, Types::Strict::String.optional.meta(required: false)
33
+
34
+ # @!attribute fieldName
35
+ # @return [String, nil] - The name of the field this attribute is associated with, if any.
36
+ attribute :fieldName, Types::Strict::String.optional.meta(required: false)
37
+
38
+ # @!attribute resolveInitializer
39
+ # @return [ResolveInitializer, nil]
40
+ attribute :resolveInitializer, Types::Nominal::Any.optional.meta(required: false)
41
+
42
+ # @!attribute deprecated
43
+ # @return [nil, Boolean, String] -
44
+ # Whether the attribute is deprecated.
45
+ # If the value is a string, it's the reason for the deprecation.
46
+ attribute :deprecated, Types::Strict::String.optional | Types::Strict::Bool.optional.meta(required: false)
47
+
48
+ def visit(parser:)
49
+ hash = {}
50
+ hash[:inheritedFrom] = parser.data_types[:inheritedFrom].new(inheritedFrom).visit(parser: parser) unless inheritedFrom.nil?
51
+ hash[:type] = parser.data_types[:type].new(type).visit(parser: parser) unless type.nil?
52
+ hash[:resolveInitializer] = parser.data_types[:resolve_initializer].new(resolveInitializer).visit(parser: parser) unless resolveInitializer.nil?
53
+ new(hash)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,47 @@
1
+ require_relative "../base_struct.rb"
2
+ require_relative "../types.rb"
3
+
4
+ module CustomElementsManifestParser
5
+ module DataTypes
6
+ # Documents a CssCustomProperty
7
+ class CssCustomProperty < BaseStruct
8
+ # @!attribute name
9
+ # @return [String] - The name of the property, including leading `--`.
10
+ attribute :name, Types::Strict::String
11
+
12
+ # @!attribute syntax
13
+ # @return [String, nil] -
14
+ # The expected syntax of the defined property. Defaults to "*".
15
+ # The syntax must be a valid CSS [syntax string](https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax)
16
+ # as defined in the CSS Properties and Values API.
17
+ # Examples:
18
+ # "<color>": accepts a color
19
+ # "<length> | <percentage>": accepts lengths or percentages but not calc expressions with a combination of the two
20
+ # "small | medium | large": accepts one of these values set as custom idents.
21
+ # "*": any valid token
22
+ attribute :syntax, Types::Strict::String.optional.meta(required: false)
23
+
24
+ # @!attribute summary
25
+ # @return [String, nil] - A markdown summary suitable for display in a listing.
26
+ attribute :summary, Types::Strict::String.optional.meta(required: false)
27
+
28
+ # @!attribute description
29
+ # @return [String, nil] - A markdown description.
30
+ attribute :description, Types::Strict::String.optional.meta(required: false)
31
+
32
+ # @!attribute default
33
+ # @return [String, nil] - The default initial value
34
+ attribute :default, Types::Strict::String.optional.meta(required: false)
35
+
36
+ # @!attribute deprecated
37
+ # @return [nil, Boolean, String] -
38
+ # Whether the CSS custom property is deprecated.
39
+ # If the value is a string, it's the reason for the deprecation.
40
+ attribute :deprecated, Types::Strict::String.optional | Types::Strict::Bool.optional.meta(required: false)
41
+
42
+ def visit(parser:)
43
+ self
44
+ end
45
+ end
46
+ end
47
+ end