custom_elements_manifest_parser 0.1.0 → 0.2.0

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: 510fa863ae80956f1521f6b10c1b36d24e7d5397e14337de1ab424a46a60e00c
4
- data.tar.gz: 17ff0b9d57ab3343919a32bd0f73a37c8839355817f27fdc9302d5c617f8c057
3
+ metadata.gz: 66c8bdbc69aa76da418725dd7a36f155378aa6af3e88a8d2743e519c2edea4f0
4
+ data.tar.gz: 966d6a3b1678f7d8ab2135db6248fbd0cfa86f72ee0f0ad5971f4f61f5a56788
5
5
  SHA512:
6
- metadata.gz: f5636133ef9fde39a1c4ca70d87bf8879ed17495322a098d7ab465e21dbdf352fd75aece557e321a4bfb6705d1b0b816e89cc39e09c8afd9c306cabaab1d2881
7
- data.tar.gz: 64ce1244a7226f6641b5007cc1fb58021110bc31a89d89d003f0056bc233e460dc8a145def0232937e1d1a294a4011b3a410af65f77fbcf3ce8f31a52b665c95
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- custom_elements_manifest_parser (0.1.0)
4
+ custom_elements_manifest_parser (0.2.0)
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,11 @@ 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"] # => 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|
@@ -68,6 +68,7 @@ module CustomElementsManifestParser
68
68
  attribute attr.name, attr.type
69
69
  end
70
70
 
71
+ # @!parse Structs::FunctionLikeStruct
71
72
  attributes_from Structs::DeclarableNodeStruct
72
73
 
73
74
  # @!attribute kind
@@ -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
- 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
101
118
 
102
- if tag_names.include?(dec.attributes[:tagName])
103
- custom_elements << dec
104
- end
119
+ custom_elements[tag_name] = dec
105
120
  end
106
121
  end
107
122
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CustomElementsManifestParser
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
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.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - konnorrogers