iconify-rails 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b13d5388ff61d0a4f97bb15cf98a14e28a6f1dd758d83ca4a04d8f6a6d21f353
4
- data.tar.gz: 1789c4d741a0ca3f1cdd47492bff872f0dfa9fcf4ab7b097180ec4b844617637
3
+ metadata.gz: a70e4f2f4aeeae530662f4c6099523e7fe69034dfc8e5ef17544cccea1d70456
4
+ data.tar.gz: e1e78477e5931999fc76fdac47f490e6f6604661aca39c42bc31574f0945848b
5
5
  SHA512:
6
- metadata.gz: c8a2d05f5a4b52e5b21d7b216fc98f4b9f1de10a63c76fbf72a89136451ddb45c1eaf6de69f1915987d11e7672e9ad6ef19c2c5b64320c443fb918b13da848c1
7
- data.tar.gz: ff2a0f976b6049a8dbe1592fd91ed382402de90a5c8c51969a06dd6e86b26d101741108ac37755f6376e1940ef695452c0f18a86494b4aab980397b624c9bbc4
6
+ metadata.gz: 9e4f1c9ad0e7408d0a4afa20a265d35c83d829876cc665b4375ea04e19f0bad1c6e15af0262ab9bde054fff6e37b0ba724a8fab5e26084eb1641f1a5b4e45388
7
+ data.tar.gz: 8fb06b4a42f5a46569614f0632cd95a793282585159f850a6a70cf6c6e23961d4450815dec5f8f9e6d3d71c23a4a7edc0acc4e7496d02fa2796c226cce604e2a
data/README.md CHANGED
@@ -24,6 +24,7 @@ Now setup the location of the json, and the preferred variant if there is one.
24
24
  Iconify.configure do |config|
25
25
  config.file = "vendor/icons/heroicons.json"
26
26
  config.suffix = :suffix
27
+ # config.raise_on_missing_icon = true
27
28
  end
28
29
  ```
29
30
 
@@ -1,12 +1,21 @@
1
1
  module Iconify::Helpers
2
2
  def icon(name, suffix: Iconify.configuration.default_suffix, **attrs)
3
3
  suffix = suffix.to_s
4
+
4
5
  icon_name = name.to_s.dasherize
5
- icon_name = "#{icon_name}-#{suffix}" if suffix.present?
6
+ icon_name = "#{icon_name}-#{suffix}" if suffix.present? && !icon_name.include?(suffix)
7
+ icon_name = Iconify::ALIASES[icon_name] if aliased?(icon_name)
6
8
 
7
9
  icon = Iconify::ICON_DATA["icons"][icon_name]
8
10
 
9
- tag.span { "#{icon_name} missing" } if icon.nil?
11
+ if icon.nil?
12
+ message = "#{icon_name} missing"
13
+ if Iconify.configuration.raise_on_missing_icon
14
+ raise Iconify::Error, message
15
+ end
16
+
17
+ return tag.span { message } if icon.nil?
18
+ end
10
19
 
11
20
  viewbox = read_view_box(icon)
12
21
 
@@ -17,6 +26,10 @@ module Iconify::Helpers
17
26
 
18
27
  private
19
28
 
29
+ def aliased?(icon_name)
30
+ Iconify::ALIASES[icon_name].present?
31
+ end
32
+
20
33
  def read_view_box(icon)
21
34
  left = icon["left"] || Iconify::ICON_DATA["left"] || 0
22
35
  right = icon["right"] || Iconify::ICON_DATA["right"] || 0
@@ -1,3 +1,3 @@
1
1
  module Iconify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/iconify-rails.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  module Iconify
2
+ class Error < StandardError; end
3
+
2
4
  class Configuration
3
- attr_accessor :file, :default_suffix
5
+ attr_accessor :file, :default_suffix, :raise_on_missing_icon
4
6
 
5
7
  def initialize
6
8
  @file = "vendor/icons/heroicons.json"
7
9
  @default_suffix = nil
10
+ @raise_on_missing_icon = false
8
11
  end
9
12
  end
10
13
 
@@ -22,9 +25,11 @@ module Iconify
22
25
  raw = File.read(path)
23
26
  parsed = JSON.parse(raw)
24
27
  raw_suffixes = parsed.delete("suffixes")
28
+ raw_aliases = parsed.delete("aliases")
25
29
 
26
30
  self.const_set("ICON_DATA", parsed.freeze)
27
31
  self.const_set("SUFFIXES", raw_suffixes&.keys.freeze)
32
+ self.const_set("ALIASES", raw_aliases&.to_h { |k, v| [ k, v["parent"] ] }&.compact)
28
33
  end
29
34
  end
30
35
  end
@@ -1,4 +1,5 @@
1
1
  Iconify.configure do |config|
2
2
  config.file = "vendor/icons/heroicons.json"
3
3
  config.default_suffix = :solid
4
+ # config.raise_on_missing_icon = true
4
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iconify-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Kircher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-20 00:00:00.000000000 Z
11
+ date: 2025-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.5.9
62
+ rubygems_version: 3.5.23
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Use @iconify/json icon sets with Rails for inline SVGs