heroicon-rails 0.2.6 → 0.2.9
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/lib/heroicon/rails/heroicon_helper.rb +19 -9
- data/lib/heroicon/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa3ffefd1dd18db5b24474ff098ba54f4ee056316be92ea6dbc6980ef3537060
|
4
|
+
data.tar.gz: d7b649562c77e01ea4d563675a9ab5147469e18d30d846274b9ad0c6a284a863
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 338d72ee8733fea324d18ab97189ffe0218d720e359bb116bc86a9c019e006322a7e291710f064d93606a6f2ac4d9861377f53b6286f2ff30cd0e5aea56e6b25
|
7
|
+
data.tar.gz: a0be6ce7c011d55b76f22a6a910a84e46229bccd012d5a4db67a32d3b67929f0a8479e08ca7a1ce50c06986dcc53e804d7631b193c4ceedbbae30b73fc8e7341
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/string/output_safety"
|
2
2
|
|
3
3
|
module HeroiconHelper
|
4
4
|
HEROICONS_PATH = File.expand_path("assets/heroicons", __dir__)
|
@@ -9,25 +9,35 @@ module HeroiconHelper
|
|
9
9
|
# @param options [Hash] additional options including custom CSS classes
|
10
10
|
# @return [String] HTML safe string with the SVG content or error message
|
11
11
|
def heroicon(name, type: "solid", **options)
|
12
|
+
# Allow strings or symbols for name and type arguments
|
13
|
+
name = name.to_s
|
14
|
+
type = type.to_s
|
15
|
+
|
16
|
+
# Handle class attribute
|
12
17
|
custom_class = options.delete(:class) || ""
|
13
|
-
|
18
|
+
|
19
|
+
# Handle style attribute
|
14
20
|
style_attribute = options.delete(:style)
|
15
21
|
|
16
|
-
# Handle
|
17
|
-
|
22
|
+
# Handle title attribute
|
23
|
+
title_attribute = options.delete(:title)
|
24
|
+
|
25
|
+
# Handle data- attributes, filtering out anything that doesn"t start with "data-"
|
26
|
+
data_attributes = options.select { |key, _| key.to_s.start_with?("data-") }
|
18
27
|
options.except!(*data_attributes.keys)
|
19
28
|
|
29
|
+
# Load the SVG icon
|
20
30
|
gem_root = Gem::Specification.find_by_name("heroicon-rails").gem_dir
|
21
31
|
icon_path = File.join(gem_root, "lib", "heroicon", "rails", "assets", "heroicons", type, "#{name}.svg")
|
22
32
|
icon_content = File.read(icon_path)
|
23
33
|
icon_doc = Nokogiri::HTML::DocumentFragment.parse(icon_content)
|
24
34
|
svg = icon_doc.at_css("svg")
|
25
35
|
|
26
|
-
# Apply custom classes
|
36
|
+
# Apply custom css classes
|
27
37
|
custom_width_class = custom_class[/\bw-\d+/]
|
28
38
|
custom_height_class = custom_class[/\bh-\d+/]
|
29
|
-
default_width = custom_width_class ?
|
30
|
-
default_height = custom_height_class ?
|
39
|
+
default_width = custom_width_class ? "" : (type == "mini" ? "w-5" : "w-6")
|
40
|
+
default_height = custom_height_class ? "" : (type == "mini" ? "h-5" : "h-6")
|
31
41
|
css_classes = "#{default_width} #{default_height} #{custom_class}".strip
|
32
42
|
svg[:class] = css_classes unless css_classes.empty?
|
33
43
|
|
@@ -38,7 +48,7 @@ module HeroiconHelper
|
|
38
48
|
svg[:role] = "img"
|
39
49
|
svg["aria-labelledby"] = "#{name}-icon"
|
40
50
|
title_element = Nokogiri::XML::Node.new("title", icon_doc)
|
41
|
-
title_element.content = name.humanize
|
51
|
+
title_element.content = title_attribute || name.humanize
|
42
52
|
title_element[:id] = "#{name}-icon"
|
43
53
|
svg.prepend_child(title_element)
|
44
54
|
|
@@ -49,6 +59,6 @@ module HeroiconHelper
|
|
49
59
|
|
50
60
|
icon_doc.to_html.html_safe
|
51
61
|
rescue StandardError => e
|
52
|
-
"Icon
|
62
|
+
"Icon #{name} not found. Error: #{e.message}"
|
53
63
|
end
|
54
64
|
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Weis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -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.4.19
|
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
|