heroicons_helper 0.6.0 → 0.7.1
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/.ruby-version +1 -0
- data/.vscode/settings.json +8 -0
- data/Gemfile +4 -0
- data/README.md +7 -6
- data/Rakefile +6 -0
- data/heroicons_helper.gemspec +6 -0
- data/lib/heroicons_helper/cache.rb +11 -3
- data/lib/heroicons_helper/data.json +1 -1
- data/lib/heroicons_helper/icon.rb +8 -3
- data/lib/heroicons_helper/version.rb +1 -1
- data/lib/heroicons_helper.rb +4 -4
- data/package-lock.json +38 -639
- metadata +26 -9
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "set"
|
4
|
+
require "active_support/core_ext/string/output_safety"
|
4
5
|
|
5
6
|
module HeroiconsHelper
|
6
7
|
# Icon to show heroicons by name and variant.
|
@@ -12,13 +13,14 @@ module HeroiconsHelper
|
|
12
13
|
VARIANT_MINI = "mini"
|
13
14
|
VALID_VARIANTS = Set.new([VARIANT_OUTLINE, VARIANT_SOLID, VARIANT_MINI]).freeze
|
14
15
|
|
15
|
-
def initialize(name, variant, attributes: {})
|
16
|
+
def initialize(name, variant, unsafe: false, attributes: {})
|
16
17
|
@name = name.to_s
|
17
18
|
@variant = variant.to_s
|
19
|
+
@unsafe = unsafe
|
18
20
|
|
19
21
|
heroicon = get_heroicon(@name, @variant)
|
20
22
|
|
21
|
-
@path = heroicon["path"]
|
23
|
+
@path = safe? ? ActiveSupport::SafeBuffer.new(heroicon["path"]) : heroicon["path"]
|
22
24
|
@width = heroicon["width"]
|
23
25
|
@height = heroicon["height"]
|
24
26
|
@keywords = heroicon["keywords"]
|
@@ -36,6 +38,10 @@ module HeroiconsHelper
|
|
36
38
|
"<!-- Heroicon name: #{@variant}/#{@name} --><svg xmlns=\"http://www.w3.org/2000/svg\" #{html_attributes}>#{@path}</svg>"
|
37
39
|
end
|
38
40
|
|
41
|
+
private def safe?
|
42
|
+
!@unsafe
|
43
|
+
end
|
44
|
+
|
39
45
|
private def html_attributes
|
40
46
|
attrs = []
|
41
47
|
@attributes.each_pair { |attr, value| attrs << "#{attr}=\"#{value}\"" }
|
@@ -65,7 +71,6 @@ module HeroiconsHelper
|
|
65
71
|
when VARIANT_OUTLINE
|
66
72
|
{
|
67
73
|
fill: "none",
|
68
|
-
stroke: "currentColor",
|
69
74
|
}
|
70
75
|
when VARIANT_SOLID, VARIANT_MINI
|
71
76
|
{
|
data/lib/heroicons_helper.rb
CHANGED
@@ -9,18 +9,18 @@ module HeroiconsHelper
|
|
9
9
|
file_data = File.read(File.join(File.dirname(__FILE__), "./heroicons_helper/data.json"))
|
10
10
|
ICON_NAMES = JSON.parse(file_data).freeze
|
11
11
|
|
12
|
-
def heroicon(name, variant:, **attributes)
|
12
|
+
def heroicon(name, variant:, unsafe: false, **attributes)
|
13
13
|
cache_key = HeroiconsHelper::Cache.get_key(
|
14
14
|
name: name,
|
15
15
|
variant: variant,
|
16
|
-
|
17
|
-
|
16
|
+
unsafe: unsafe,
|
17
|
+
attributes: attributes,
|
18
18
|
)
|
19
19
|
|
20
20
|
cached_heroicon = HeroiconsHelper::Cache.read(cache_key)
|
21
21
|
return cached_heroicon unless cached_heroicon.nil?
|
22
22
|
|
23
|
-
heroicon = ::HeroiconsHelper::Icon.new(name, variant, attributes: attributes)
|
23
|
+
heroicon = ::HeroiconsHelper::Icon.new(name, variant, unsafe: unsafe, attributes: attributes)
|
24
24
|
HeroiconsHelper::Cache.set(cache_key, heroicon)
|
25
25
|
|
26
26
|
heroicon
|