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 +4 -4
- data/heroicon-rails.gemspec +2 -2
- data/lib/heroicon/rails/heroicon_helper.rb +27 -16
- data/lib/heroicon/rails/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fd24c0a8c60585d43fd4a309683be26a7d35acf5dbb03fe15954e82fbc0f0fb
|
4
|
+
data.tar.gz: 7b826a26b7d0d63344d440f1d2a1fe9ba5a186459811715a3abecb34ae37988f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0cf0ea42905ff83e9b421ef5c4bc4aec5561391badd97cacaf97668b662650dd494c6096fbf48c5eaa4ebcf39213e832ddd080885e43dc2db77d4667ec5da8
|
7
|
+
data.tar.gz: 433d722e0d39c230365b3be72081749ee36ff063515f26854675adeae71e4167b1f193c237004b4c4e1c2f5a61192d85e94dc842295a0047e3d0329ff6964e4d
|
data/heroicon-rails.gemspec
CHANGED
@@ -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", ">=
|
36
|
-
spec.add_dependency "nokogiri", ">= 1.
|
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
|
-
|
8
|
-
|
12
|
+
custom_class = options.delete(:class) || ""
|
9
13
|
gem_root = Gem::Specification.find_by_name("heroicon-rails").gem_dir
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
svg =
|
14
|
-
|
15
|
-
|
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
|
-
#
|
29
|
+
# Enhance accessibility
|
19
30
|
svg[:role] = "img"
|
20
31
|
svg["aria-labelledby"] = "#{name}-icon"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
svg.prepend_child(
|
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
|
-
|
27
|
-
rescue StandardError
|
28
|
-
"
|
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
|
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.
|
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:
|
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:
|
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:
|
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.
|
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.
|
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.
|
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
|