custom_elements_manifest_parser 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/Gemfile.lock +1 -1
- data/README.md +9 -2
- data/lib/custom_elements_manifest_parser/parser.rb +42 -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: b034129185a15c3ecc863a4dbad481f9a74dd3c56dfdacae153388233afd274b
|
4
|
+
data.tar.gz: d1117275df17115129e2252d8b460b4cee37122785e8c0e7fe3b62ad3e5d43ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4baa54509b17090097ba88f6b13027d286b6a78203109e944cacef0b80bd88c9504fbc82b7b28226a89411c99ddacfd13404e35e0b0180ed2f9192db41326058
|
7
|
+
data.tar.gz: 75f9b399a7b70b82c058c21b3c821aa3b2d593e54ead8912f7843b1c37d3f66d5b4eb161bbf863c7b725d1cafccdb4131dc9d19976befe32ecd6f31658c56fba
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
##
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## [0.2.1] - 10/07/2023
|
4
|
+
|
5
|
+
- Added a `Parser#find_all_tag_names` method to the parser that returns a Hash keyed off the tag name.
|
6
|
+
|
7
|
+
## [0.2.0] - 10/07/2023
|
8
|
+
|
9
|
+
- Added a `Parser#find_by_tag_names(['tag-name'])` method to the parser that returns a Hash keyed off the tag name.
|
10
|
+
- Removed `tag_names` as a parameters for `Parser#find_custom_elements`
|
2
11
|
|
3
12
|
## [0.1.0] - 2023-10-03
|
4
13
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -60,8 +60,15 @@ 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"] # => ClassDeclaration
|
67
|
+
hash["light-preview"] # => ClassDeclaration
|
68
|
+
|
69
|
+
# Finds every declaration with a "tagName"
|
70
|
+
hash = parser.find_all_tag_names
|
71
|
+
hash["light-preview"] # => ClassDeclaration
|
65
72
|
|
66
73
|
# Searches for all custom elements regardless of tagName
|
67
74
|
parser.find_custom_elements.each do |declaration|
|
@@ -81,27 +81,60 @@ 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
|
118
|
+
|
119
|
+
custom_elements[tag_name] = dec
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
custom_elements
|
124
|
+
end
|
125
|
+
|
126
|
+
# @return [Hash{String => Nodes::ClassDeclaration}] - Returns a hash keyed off of found tagNames.
|
127
|
+
def find_all_tag_names
|
128
|
+
custom_elements = {}
|
129
|
+
|
130
|
+
manifest.modules.flatten.each do |mod|
|
131
|
+
mod.declarations.flatten.each do |dec|
|
132
|
+
# Needs to be != true because == false fails nil checks.
|
133
|
+
next if dec.attributes[:customElement] != true
|
134
|
+
|
135
|
+
tag_name = dec.attributes[:tagName]
|
101
136
|
|
102
|
-
if
|
103
|
-
custom_elements << dec
|
104
|
-
end
|
137
|
+
custom_elements[tag_name] = dec if tag_name
|
105
138
|
end
|
106
139
|
end
|
107
140
|
|