heroicons_helper 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HeroiconsHelper
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.1"
5
5
  end
@@ -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
- height: attributes[:height],
17
- width: attributes[:width]
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