heroicon-rails 0.1.7 → 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: 6658c1b5b6bd0730860672bc4e9c66be23f644bf76e7a20498124274f80f9589
4
- data.tar.gz: b7b9e370fa0e73c9723c308caa72bfc0e356ec83f85abdf351121fb2bbf72613
3
+ metadata.gz: 0fd24c0a8c60585d43fd4a309683be26a7d35acf5dbb03fe15954e82fbc0f0fb
4
+ data.tar.gz: 7b826a26b7d0d63344d440f1d2a1fe9ba5a186459811715a3abecb34ae37988f
5
5
  SHA512:
6
- metadata.gz: 6a6fb724a88ecd3567a4a1452724e1aa66201a0ba44c256d7a9e59043faa413f1b16512966c4cbbfa2856002acec1e46413624897d54bf4415f57d36179c6e90
7
- data.tar.gz: cffc219d6d4674e5dcee21c336ac829723f6fa611b6814c4499ff5cb64b82665e50a5b995d1977bdd70281c95a669c2f38038a7c79ab6a2894925741a568af38
6
+ metadata.gz: 2e0cf0ea42905ff83e9b421ef5c4bc4aec5561391badd97cacaf97668b662650dd494c6096fbf48c5eaa4ebcf39213e832ddd080885e43dc2db77d4667ec5da8
7
+ data.tar.gz: 433d722e0d39c230365b3be72081749ee36ff063515f26854675adeae71e4167b1f193c237004b4c4e1c2f5a61192d85e94dc842295a0047e3d0329ff6964e4d
@@ -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,28 +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
- # Set accessibility attributes
29
+ # Enhance accessibility
19
30
  svg[:role] = "img"
20
31
  svg["aria-labelledby"] = "#{name}-icon"
21
- title = Nokogiri::XML::Node.new("title", doc)
22
- title.content = name.humanize
23
- title[:id] = "#{name}-icon"
24
- svg.prepend_child(title)
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)
25
36
 
26
- doc.to_html.html_safe
27
- rescue StandardError
28
- "heroicon '#{name}' not found"
37
+ icon_doc.to_html.html_safe
38
+ rescue StandardError => e
39
+ "Icon '#{name}' not found. Error: #{e.message}"
29
40
  end
30
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Heroicon
4
4
  module Rails
5
- VERSION = "0.1.7"
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.7
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-30 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,
@@ -969,7 +969,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
969
969
  - !ruby/object:Gem::Version
970
970
  version: '0'
971
971
  requirements: []
972
- rubygems_version: 3.4.10
972
+ rubygems_version: 3.2.33
973
973
  signing_key:
974
974
  specification_version: 4
975
975
  summary: A Ruby gem providing a helper for easily embedding Heroicons SVG icons in