custom_elements_manifest_parser 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 159107ec8b6233a574b4e1d7bf8be305f8efe78808c28f79cf1b184d6b46048a
4
- data.tar.gz: 904b3860d3a05f67d61d4a2fe053e79fb1172c059c3179aaeaa8408abb8c0982
3
+ metadata.gz: b034129185a15c3ecc863a4dbad481f9a74dd3c56dfdacae153388233afd274b
4
+ data.tar.gz: d1117275df17115129e2252d8b460b4cee37122785e8c0e7fe3b62ad3e5d43ba
5
5
  SHA512:
6
- metadata.gz: e6f9a30d13e73b8fdbea80103fe7d4356e28db2ab361bca424fb74b46b997b5beba832a9534483b8ee4ff7d811839cdc9731c07f045f4f56de801483e57d2271
7
- data.tar.gz: 41e30ff4525fa02154635910bcf2e226f28903a145d2731cc46065417b38b2ea3c3524c7415b1652774099ec793812120c4558c4192cc3ede5d2b55f3de0bf6c
6
+ metadata.gz: 4baa54509b17090097ba88f6b13027d286b6a78203109e944cacef0b80bd88c9504fbc82b7b28226a89411c99ddacfd13404e35e0b0180ed2f9192db41326058
7
+ data.tar.gz: 75f9b399a7b70b82c058c21b3c821aa3b2d593e54ead8912f7843b1c37d3f66d5b4eb161bbf863c7b725d1cafccdb4131dc9d19976befe32ecd6f31658c56fba
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## [Unreleased]
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- custom_elements_manifest_parser (0.1.1)
4
+ custom_elements_manifest_parser (0.2.1)
5
5
  dry-struct (~> 1.0)
6
6
  dry-types (~> 1.0)
7
7
  dry-validation (~> 1.0)
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.find_custom_elements("light-pen", "light-preview").each { |declaration| declaration }
64
- parser.find_custom_elements(["light-pen", "light-preview"]).each { |declaration| declaration }
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
- def find_custom_elements(tag_names = [])
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
- if tag_names.empty?
98
- custom_elements << dec
99
- next
100
- end
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 tag_names.include?(dec.attributes[:tagName])
103
- custom_elements << dec
104
- end
137
+ custom_elements[tag_name] = dec if tag_name
105
138
  end
106
139
  end
107
140
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomElementsManifestParser
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_elements_manifest_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - konnorrogers