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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 159107ec8b6233a574b4e1d7bf8be305f8efe78808c28f79cf1b184d6b46048a
4
- data.tar.gz: 904b3860d3a05f67d61d4a2fe053e79fb1172c059c3179aaeaa8408abb8c0982
3
+ metadata.gz: 66c8bdbc69aa76da418725dd7a36f155378aa6af3e88a8d2743e519c2edea4f0
4
+ data.tar.gz: 966d6a3b1678f7d8ab2135db6248fbd0cfa86f72ee0f0ad5971f4f61f5a56788
5
5
  SHA512:
6
- metadata.gz: e6f9a30d13e73b8fdbea80103fe7d4356e28db2ab361bca424fb74b46b997b5beba832a9534483b8ee4ff7d811839cdc9731c07f045f4f56de801483e57d2271
7
- data.tar.gz: 41e30ff4525fa02154635910bcf2e226f28903a145d2731cc46065417b38b2ea3c3524c7415b1652774099ec793812120c4558c4192cc3ede5d2b55f3de0bf6c
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.1)
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|
@@ -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.1"
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.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - konnorrogers