rails_heroicon 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +13 -5
- data/compressed/icons.json +1178 -876
- data/lib/rails_heroicon/helper.rb +8 -2
- data/lib/rails_heroicon/rails_heroicon.rb +24 -6
- data/lib/rails_heroicon/version.rb +1 -1
- metadata +3 -3
@@ -3,6 +3,8 @@ require "action_view"
|
|
3
3
|
module RailsHeroicon
|
4
4
|
module Helper
|
5
5
|
include ActionView::Helpers::TagHelper
|
6
|
+
|
7
|
+
mattr_accessor :icon_cache, default: {}
|
6
8
|
# To add a heroicon, call <tt><%= heroicon "icon_name" %></tt> on your erb template.
|
7
9
|
# Head over to https://heroicons.com to view all the icons.
|
8
10
|
#
|
@@ -34,10 +36,14 @@ module RailsHeroicon
|
|
34
36
|
# The helper method automatically sets <tt>aria-hidden=true</tt> if <tt>aria-label</tt> is not set, and
|
35
37
|
# if <tt>aria-label</tt> is set, then <tt>role=img</tt> is set automatically.
|
36
38
|
def heroicon(symbol, title: nil, **options)
|
37
|
-
|
39
|
+
cache_key = [symbol, title, options]
|
40
|
+
return icon_cache[cache_key] if icon_cache[cache_key]
|
38
41
|
|
42
|
+
icon = RailsHeroicon.new(symbol, **options)
|
39
43
|
title_tag = content_tag(:title, title) if title
|
40
|
-
content_tag(:svg, title_tag.to_s.html_safe + icon.svg_path.html_safe, icon.options)
|
44
|
+
tag = content_tag(:svg, title_tag.to_s.html_safe + icon.svg_path.html_safe, icon.options)
|
45
|
+
icon_cache[cache_key] = tag
|
46
|
+
tag
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
@@ -2,7 +2,7 @@ require_relative "errors"
|
|
2
2
|
|
3
3
|
module RailsHeroicon
|
4
4
|
class RailsHeroicon
|
5
|
-
VARIANTS = %w[outline solid mini].freeze
|
5
|
+
VARIANTS = %w[outline solid mini micro].freeze
|
6
6
|
|
7
7
|
attr_reader :options
|
8
8
|
|
@@ -12,7 +12,7 @@ module RailsHeroicon
|
|
12
12
|
@icon = icon.to_s
|
13
13
|
@variant = variant.to_s
|
14
14
|
@options = options.dup
|
15
|
-
@size =
|
15
|
+
@size = default_or_defined_size(size)
|
16
16
|
@options.merge!(svg_properties)
|
17
17
|
end
|
18
18
|
|
@@ -29,13 +29,14 @@ module RailsHeroicon
|
|
29
29
|
def svg_properties
|
30
30
|
properties = {}
|
31
31
|
|
32
|
-
properties[:
|
32
|
+
properties[:xmlns] = "http://www.w3.org/2000/svg"
|
33
|
+
properties[:viewBox] = view_box
|
33
34
|
properties[:height] = @size
|
34
35
|
properties[:width] = @size
|
35
36
|
properties[:version] = "1.1"
|
36
37
|
properties[:fill] = outline? ? "none" : "currentColor"
|
37
38
|
properties[:stroke] = outline? ? "currentColor" : "none"
|
38
|
-
properties[:"stroke-width"] =
|
39
|
+
properties[:"stroke-width"] = stroke_width
|
39
40
|
|
40
41
|
if options[:"aria-label"].nil? && options["aria-label"].nil? && options.dig(:aria, :label).nil?
|
41
42
|
properties[:"aria-hidden"] = "true"
|
@@ -47,14 +48,27 @@ module RailsHeroicon
|
|
47
48
|
end
|
48
49
|
|
49
50
|
# If the user has explicitly stated the size attribute, then use that. If size attribute is not passed
|
50
|
-
# then default to 24 if variant is outline or solid, else default to 20 if variant is mini
|
51
|
-
|
51
|
+
# then default to 24 if variant is outline or solid, else default to 20 if variant is mini, else default to 16 if
|
52
|
+
# variant is micro.
|
53
|
+
def default_or_defined_size(size)
|
52
54
|
return size if size
|
55
|
+
return 16 if micro?
|
53
56
|
return 20 if mini?
|
54
57
|
|
55
58
|
24
|
56
59
|
end
|
57
60
|
|
61
|
+
def stroke_width
|
62
|
+
return unless outline?
|
63
|
+
@options[:"stroke-width"] || 1.5
|
64
|
+
end
|
65
|
+
|
66
|
+
def view_box
|
67
|
+
return "0 0 20 20" if mini?
|
68
|
+
return "0 0 16 16" if micro?
|
69
|
+
"0 0 24 24"
|
70
|
+
end
|
71
|
+
|
58
72
|
def outline?
|
59
73
|
@variant == "outline"
|
60
74
|
end
|
@@ -66,5 +80,9 @@ module RailsHeroicon
|
|
66
80
|
def mini?
|
67
81
|
@variant == "mini"
|
68
82
|
end
|
83
|
+
|
84
|
+
def micro?
|
85
|
+
@variant == "micro"
|
86
|
+
end
|
69
87
|
end
|
70
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_heroicon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abeidahmed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.1.6
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Ruby on Rails view helpers for the awesome Heroicons by Steve Schoger.
|