heroicon-rails 0.1.6 → 0.2.3

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: d0214bfedc0c7488301225dcc5db5ee1fc4b18c6d9c8527e37f8a9cfc7ab4a5c
4
- data.tar.gz: 6c0750926dcfd9de8fb09e170fdeda5d1838f01363f179f598763b672867f094
3
+ metadata.gz: 0fd24c0a8c60585d43fd4a309683be26a7d35acf5dbb03fe15954e82fbc0f0fb
4
+ data.tar.gz: 7b826a26b7d0d63344d440f1d2a1fe9ba5a186459811715a3abecb34ae37988f
5
5
  SHA512:
6
- metadata.gz: c694424cf64b65d23e5561aadaa590e726df4ce4a22f6dedc9ed53e5f30348c1a1ee2f68cdbc151b7df147a654273e733950be5827af7737efab5759f1764e96
7
- data.tar.gz: 8db9fd21bdb5a4fad0cc7c36bd004994b2e443070b756d2697a216c0431b14c027fb08a1ea11ddc8b4fb986fb1c997e1ed5b3ea01d52133aa166bc7b1f547933
6
+ metadata.gz: 2e0cf0ea42905ff83e9b421ef5c4bc4aec5561391badd97cacaf97668b662650dd494c6096fbf48c5eaa4ebcf39213e832ddd080885e43dc2db77d4667ec5da8
7
+ data.tar.gz: 433d722e0d39c230365b3be72081749ee36ff063515f26854675adeae71e4167b1f193c237004b4c4e1c2f5a61192d85e94dc842295a0047e3d0329ff6964e4d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2023-11-26
4
-
3
+ ## [0.1.6] - Initial stable release
5
4
  - Initial release
5
+ ## [0.1.7] - Updates for accessibility
6
+ - Update all svg elements to have a role="img"
7
+ - Update all svg elements to have a descriptive <title> element
8
+ - Update all svg elements to have an aria-labelledby attribute referencing the <title> element
9
+
@@ -32,8 +32,8 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
34
  # spec.add_dependency "example-gem", "~> 1.0"
35
- spec.add_runtime_dependency "activesupport", ">= 5.2.7"
36
- spec.add_dependency "nokogiri", ">= 1.15.5"
35
+ spec.add_runtime_dependency "activesupport", ">= 7.0.8"
36
+ spec.add_dependency "nokogiri", ">= 1.14.3"
37
37
 
38
38
  # For more information and examples about making a new gem, check out our
39
39
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -3,20 +3,39 @@ require 'active_support/core_ext/string/output_safety'
3
3
  module HeroiconHelper
4
4
  HEROICONS_PATH = File.expand_path("assets/heroicons", __dir__)
5
5
 
6
+ # Returns an SVG icon from the Heroicons library with customizable dimensions.
7
+ # @param name [String] the name of the icon
8
+ # @param type [String] the style of the icon (default: "solid")
9
+ # @param options [Hash] additional options including custom CSS classes
10
+ # @return [String] HTML safe string with the SVG content or error message
6
11
  def heroicon(name, type: "solid", **options)
7
- css_classes = options.delete(:class) || ""
8
-
12
+ custom_class = options.delete(:class) || ""
9
13
  gem_root = Gem::Specification.find_by_name("heroicon-rails").gem_dir
10
- file_path = File.join(gem_root, "lib", "heroicon", "rails", "assets", "heroicons", type, "#{name}.svg")
11
- svg_content = File.read(file_path)
12
- doc = Nokogiri::HTML::DocumentFragment.parse(svg_content)
13
- svg = doc.at_css("svg")
14
- default_css = type == "mini" ? "w-5 h-5" : "w-6 h-6"
15
- css_classes = "#{default_css} #{css_classes}".strip
14
+ icon_path = File.join(gem_root, "lib", "heroicon", "rails", "assets", "heroicons", type, "#{name}.svg")
15
+ icon_content = File.read(icon_path)
16
+ icon_doc = Nokogiri::HTML::DocumentFragment.parse(icon_content)
17
+ svg = icon_doc.at_css("svg")
18
+
19
+ # Identify custom width and height classes
20
+ custom_width_class = custom_class[/\bw-\d+/]
21
+ custom_height_class = custom_class[/\bh-\d+/]
22
+
23
+ # Define default classes, replace with custom if present
24
+ default_width = custom_width_class ? '' : (type == "mini" ? "w-5" : "w-6")
25
+ default_height = custom_height_class ? '' : (type == "mini" ? "h-5" : "h-6")
26
+ css_classes = "#{default_width} #{default_height} #{custom_class}".strip
16
27
  svg[:class] = css_classes unless css_classes.empty?
17
28
 
18
- doc.to_html.html_safe
19
- rescue StandardError
20
- "heroicon '#{name}' not found"
29
+ # Enhance accessibility
30
+ svg[:role] = "img"
31
+ svg["aria-labelledby"] = "#{name}-icon"
32
+ title_element = Nokogiri::XML::Node.new("title", icon_doc)
33
+ title_element.content = name.humanize
34
+ title_element[:id] = "#{name}-icon"
35
+ svg.prepend_child(title_element)
36
+
37
+ icon_doc.to_html.html_safe
38
+ rescue StandardError => e
39
+ "Icon '#{name}' not found. Error: #{e.message}"
21
40
  end
22
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Heroicon
4
4
  module Rails
5
- VERSION = "0.1.6"
5
+ VERSION = "0.2.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroicon-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Weis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-26 00:00:00.000000000 Z
11
+ date: 2024-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.7
19
+ version: 7.0.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.7
26
+ version: 7.0.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.15.5
33
+ version: 1.14.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.15.5
40
+ version: 1.14.3
41
41
  description: This gem simplifies the process of using Heroicons, a popular SVG icon
42
42
  library, in Ruby on Rails applications. It offers a convenient helper method that
43
43
  allows developers to easily embed any Heroicon with customizable types (solid, outline,