custom_elements_manifest_parser 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -2
- data/lib/custom_elements_manifest_parser/parser.rb +24 -9
- data/lib/custom_elements_manifest_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c8bdbc69aa76da418725dd7a36f155378aa6af3e88a8d2743e519c2edea4f0
|
4
|
+
data.tar.gz: 966d6a3b1678f7d8ab2135db6248fbd0cfa86f72ee0f0ad5971f4f61f5a56788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ff7c6e45d310418da1a780b2ba26a88382c91f0e682dccdb8159fdc3ae5aa36af0d2629003bbd92fd622d401533956a4e637a06f83e50b97c4fbb9a430b9832
|
7
|
+
data.tar.gz: 3a5aafc4e04d5619e2f15bef227e1a7e7d741e03caaa1587d3aee0a6533b7608a9816bd475b2a8275ae93478a157d664d5e7f7383100b651a615718925797069
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
# [0.2.0] - 10/07/2023
|
4
|
+
|
5
|
+
- Added a `Parser#find_by_tag_names(['tag-name'])` method to the parser that returns a Hash keyed off the tag name.
|
6
|
+
- Removed `tag_names` as a parameters for `Parser#find_custom_elements`
|
7
|
+
|
3
8
|
## [0.1.0] - 2023-10-03
|
4
9
|
|
5
10
|
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,8 +60,11 @@ end
|
|
60
60
|
## Convenience Helpers
|
61
61
|
|
62
62
|
# Searches for the tagName of the custom elements
|
63
|
-
parser.
|
64
|
-
parser.
|
63
|
+
hash = parser.find_by_tag_names("light-pen", "light-preview")
|
64
|
+
hash = parser.find_by_tag_names(["light-pen", "light-preview"])
|
65
|
+
|
66
|
+
hash["light-pen"] # => declaration
|
67
|
+
hash["light-preview"] # => declaration
|
65
68
|
|
66
69
|
# Searches for all custom elements regardless of tagName
|
67
70
|
parser.find_custom_elements.each do |declaration|
|
@@ -81,27 +81,42 @@ module CustomElementsManifestParser
|
|
81
81
|
# ]
|
82
82
|
# end
|
83
83
|
|
84
|
-
# Hash{String, symbol => unknown}
|
85
84
|
def visit_node(node)
|
86
85
|
kind = node["kind"] || node[:kind]
|
87
86
|
@visitable_nodes[kind].new(node).visit(parser: self)
|
88
87
|
end
|
89
88
|
|
90
|
-
|
89
|
+
# @return [Array<ClassDeclaration>] - Returns an array of {Nodes::ClassDeclaration}s that describe the customElement.
|
90
|
+
def find_custom_elements
|
91
91
|
custom_elements = []
|
92
92
|
|
93
93
|
manifest.modules.flatten.each do |mod|
|
94
94
|
mod.declarations.flatten.each do |dec|
|
95
95
|
next if dec.attributes[:customElement] != true
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
custom_elements << dec
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
custom_elements
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param {Array<String>} tag_names - An array of tag names to parse through
|
105
|
+
# @return [Hash{String => Nodes::ClassDeclaration}] - Returns a hash keyed off of found tagNames
|
106
|
+
def find_by_tag_names(*tag_names)
|
107
|
+
custom_elements = {}
|
108
|
+
|
109
|
+
tag_names = tag_names.flatten
|
110
|
+
|
111
|
+
manifest.modules.flatten.each do |mod|
|
112
|
+
mod.declarations.flatten.each do |dec|
|
113
|
+
# Needs to be != true because == false fails nil checks.
|
114
|
+
next if dec.attributes[:customElement] != true
|
115
|
+
|
116
|
+
tag_name = dec.attributes[:tagName]
|
117
|
+
next if tag_names.include?(tag_name) == false
|
101
118
|
|
102
|
-
|
103
|
-
custom_elements << dec
|
104
|
-
end
|
119
|
+
custom_elements[tag_name] = dec
|
105
120
|
end
|
106
121
|
end
|
107
122
|
|