kiso-icons 0.2.0.pre → 0.3.0.pre

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: abdce35f898bcd015e68eb0fd14ec634c00f48b7c439e1937cb57ce36da1b89b
4
- data.tar.gz: e848efc526a44648dd41a34adf83ffe7f73666eb2bb38cefd48d188670a517c1
3
+ metadata.gz: 7b9b6a3f92b9860337d2979537c89195be478360d43370bdda7b7654396d7016
4
+ data.tar.gz: 3b75e9f062e60b7202499520e1fa2b59dfc849b20dea7837924af9ae94f200b9
5
5
  SHA512:
6
- metadata.gz: 8ad7085b951095eb5540babda7bf8b0495b2111ee70bacbfdd7f0d63f6c4443427786b11d4e114657112bab9c99750fff4bd010c00e22b72d4bfc6996a5630b9
7
- data.tar.gz: 0d528a7c8a0d73f3f7f3a6926a148bce8152738d8c54eaffa280cdf14bd10ef3fd743b8cfb741a1a271c79b846f97dbd74cdcd41118e4e93ac41cf1dd3469812
6
+ metadata.gz: f078789eaf4fb3e751f50f520ad9a79ad7fb37fffff59036937edc09253be207a2c44d3e776005bf34d7e68e715772a5221f1b58e6cbb7f804920c7e5de5c308
7
+ data.tar.gz: 208ba1be9bebd42e66090a4419ce95a7a636f99ba991e7acea961266d0ea538c9d7dec5215d8c2c27eeb0a5209314c25a38b372e6d1c9034aab66ca0ab394df2
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0.pre] - 2026-02-26
11
+
12
+ ### Removed
13
+
14
+ - API fallback (`fallback_to_api` config option and `ApiClient` class). Icons must now be pinned explicitly with `bin/kiso-icons pin <set>`. The bundled Lucide set still works with no setup.
15
+
16
+ ## [0.2.0.pre] - 2026-02-25
17
+
18
+ ### Fixed
19
+
20
+ - Sanitize SVG body content to prevent XSS via malicious icon data
21
+
10
22
  ## [0.1.0.pre] - 2026-02-25
11
23
 
12
24
  ### Added
@@ -22,5 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
34
  - Rails generator (`kiso_icons:install`) for project setup
23
35
  - `pristine` command to re-download all pinned sets
24
36
 
25
- [Unreleased]: https://github.com/steveclarke/kiso-icons/compare/v0.1.0.pre...HEAD
37
+ [Unreleased]: https://github.com/steveclarke/kiso-icons/compare/v0.3.0.pre...HEAD
38
+ [0.3.0.pre]: https://github.com/steveclarke/kiso-icons/releases/tag/v0.3.0.pre
39
+ [0.2.0.pre]: https://github.com/steveclarke/kiso-icons/releases/tag/v0.2.0.pre
26
40
  [0.1.0.pre]: https://github.com/steveclarke/kiso-icons/releases/tag/v0.1.0.pre
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Iconify icons for Rails. Use any of [224 icon sets](https://icon-sets.iconify.design/) (299k+ icons) as inline SVG. No JavaScript needed.
4
4
 
5
- Icons live in `vendor/icons/` as JSON files. Commit them to git, just like vendored JavaScript with importmap-rails.
5
+ Icons live in `vendor/icons/` as JSON files. Commit them to git.
6
6
 
7
7
  Part of the [Kiso 基礎](https://github.com/steveclarke/kiso) family. Works on its own in any Rails 8+ app.
8
8
 
@@ -51,7 +51,7 @@ You can pass any HTML attribute. If you add `aria: { label: "..." }`, screen rea
51
51
 
52
52
  ### Pin icon sets
53
53
 
54
- The `pin` command downloads an Iconify JSON file to `vendor/icons/`. Commit it to git. In production, icons load from these files with no API calls.
54
+ The `pin` command downloads an Iconify JSON file to `vendor/icons/`. Commit it to git.
55
55
 
56
56
  ```bash
57
57
  ./bin/kiso-icons pin lucide # pin Lucide (replaces the bundled copy)
@@ -70,7 +70,6 @@ Add an initializer to change the defaults:
70
70
  Kiso::Icons.configure do |config|
71
71
  config.default_set = "lucide" # icon set used when no prefix is given
72
72
  config.vendor_path = "vendor/icons" # where pinned JSON files are stored
73
- config.fallback_to_api = false # fetch missing icons from the Iconify API
74
73
  end
75
74
  ```
76
75
 
@@ -78,10 +77,6 @@ end
78
77
  |--------|---------|-------------|
79
78
  | `default_set` | `"lucide"` | Icon set used when you write `kiso_icon_tag("check")` with no prefix. |
80
79
  | `vendor_path` | `"vendor/icons"` | Where pinned JSON files are stored. |
81
- | `fallback_to_api` | `true` in dev, `false` in prod | If `true`, missing icons are fetched from the Iconify API. A log message tells you to pin the set. |
82
-
83
- > [!TIP]
84
- > In production, `fallback_to_api` is off. Pin all the sets you need so icons load from local files.
85
80
 
86
81
  ## How it works
87
82
 
@@ -89,7 +84,6 @@ Icons are found in this order:
89
84
 
90
85
  1. **Pinned JSON** — your sets in `vendor/icons/`
91
86
  2. **Bundled Lucide** — ships with the gem (81 KB gzipped), works with no setup
92
- 3. **Iconify API** — only in dev mode, with a prompt to pin
93
87
 
94
88
  Each SVG uses `width="1em"`, `height="1em"`, and `currentColor`. It inherits its size from `font-size` and its color from the parent element. No CSS framework needed.
95
89
 
@@ -107,9 +101,11 @@ bin/dev # start demo app at http://localhost:3100
107
101
  Run tests:
108
102
 
109
103
  ```bash
110
- bundle exec rake test # unit tests (no Rails)
111
- bundle exec rake test_integration # integration tests (boots Rails)
112
- bundle exec rake # both
104
+ bin/rake test # unit tests (no Rails)
105
+ bin/rake test_integration # integration tests (boots Rails)
106
+ bin/rake # both
107
+ bin/standardrb # lint (StandardRB)
108
+ bin/standardrb --fix # auto-fix lint
113
109
  ```
114
110
 
115
111
  See [CONTRIBUTING.md](CONTRIBUTING.md) to help out.
@@ -1,14 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "logger"
4
+
3
5
  module Kiso
4
6
  module Icons
5
7
  class Configuration
6
- attr_accessor :default_set, :vendor_path, :fallback_to_api
8
+ attr_accessor :default_set, :vendor_path
9
+ attr_writer :logger
7
10
 
8
11
  def initialize
9
12
  @default_set = "lucide"
10
13
  @vendor_path = "vendor/icons"
11
- @fallback_to_api = defined?(Rails) ? Rails.env.development? : false
14
+ end
15
+
16
+ def logger
17
+ @logger ||= Logger.new($stderr, progname: "Kiso::Icons")
12
18
  end
13
19
  end
14
20
  end
@@ -7,7 +7,7 @@ module Kiso
7
7
  class Railtie < ::Rails::Railtie
8
8
  initializer "kiso_icons.configure" do |_app|
9
9
  Kiso::Icons.configure do |config|
10
- config.fallback_to_api = Rails.env.development? || Rails.env.test?
10
+ config.logger = Rails.logger
11
11
  end
12
12
  end
13
13
 
@@ -24,9 +24,6 @@ module Kiso
24
24
  # 4. Bundled (lucide ships in gem)
25
25
  icon_data ||= resolve_from_bundled(set_prefix, icon_name)
26
26
 
27
- # 5. API fallback (dev only)
28
- icon_data ||= resolve_from_api(set_prefix, icon_name)
29
-
30
27
  Kiso::Icons.cache.set(set_prefix, icon_name, icon_data) if icon_data
31
28
 
32
29
  icon_data
@@ -67,12 +64,6 @@ module Kiso
67
64
  @mutex.synchronize { @loaded_sets[set_prefix] = set }
68
65
  set.icon(icon_name)
69
66
  end
70
-
71
- def resolve_from_api(set_prefix, icon_name)
72
- return nil unless Kiso::Icons.configuration.fallback_to_api
73
-
74
- ApiClient.fetch_icon(set_prefix, icon_name)
75
- end
76
67
  end
77
68
  end
78
69
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kiso
4
4
  module Icons
5
- VERSION = "0.2.0.pre"
5
+ VERSION = "0.3.0.pre"
6
6
  end
7
7
  end
data/lib/kiso/icons.rb CHANGED
@@ -19,6 +19,10 @@ module Kiso
19
19
  @resolver ||= Resolver.new
20
20
  end
21
21
 
22
+ def logger
23
+ configuration.logger
24
+ end
25
+
22
26
  def cache
23
27
  @cache ||= Cache.new
24
28
  end
@@ -42,5 +46,4 @@ require "kiso/icons/cache"
42
46
  require "kiso/icons/set"
43
47
  require "kiso/icons/resolver"
44
48
  require "kiso/icons/renderer"
45
- require "kiso/icons/api_client"
46
49
  require "kiso/icons/railtie" if defined?(Rails::Railtie)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiso-icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre
4
+ version: 0.3.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Clarke
@@ -68,7 +68,6 @@ files:
68
68
  - lib/install/install.rb
69
69
  - lib/kiso-icons.rb
70
70
  - lib/kiso/icons.rb
71
- - lib/kiso/icons/api_client.rb
72
71
  - lib/kiso/icons/cache.rb
73
72
  - lib/kiso/icons/commands.rb
74
73
  - lib/kiso/icons/configuration.rb
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "net/http"
4
- require "uri"
5
- require "json"
6
-
7
- module Kiso
8
- module Icons
9
- class ApiClient
10
- API_BASE = "https://api.iconify.design"
11
- TIMEOUT = 5
12
-
13
- class << self
14
- def fetch_icon(set_prefix, icon_name)
15
- start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
-
17
- uri = URI("#{API_BASE}/#{set_prefix}/#{icon_name}.json")
18
- response = make_request(uri)
19
- return nil unless response
20
-
21
- data = JSON.parse(response.body)
22
- return nil unless data["body"]
23
-
24
- elapsed_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round
25
-
26
- warn_to_pin(set_prefix, icon_name, elapsed_ms)
27
-
28
- {
29
- body: data["body"],
30
- width: data["width"] || 24,
31
- height: data["height"] || 24
32
- }
33
- rescue JSON::ParserError => e
34
- warn "[Kiso::Icons] Failed to parse API response for #{set_prefix}:#{icon_name}: #{e.message}"
35
- nil
36
- end
37
-
38
- private
39
-
40
- def make_request(uri)
41
- http = Net::HTTP.new(uri.host, uri.port)
42
- http.use_ssl = true
43
- http.open_timeout = TIMEOUT
44
- http.read_timeout = TIMEOUT
45
-
46
- request = Net::HTTP::Get.new(uri)
47
- request["Accept"] = "application/json"
48
-
49
- response = http.request(request)
50
-
51
- case response
52
- when Net::HTTPSuccess then response
53
- when Net::HTTPNotFound then nil
54
- else
55
- warn "[Kiso::Icons] API returned #{response.code} for #{uri}"
56
- nil
57
- end
58
- rescue Net::OpenTimeout, Net::ReadTimeout
59
- warn "[Kiso::Icons] API timeout for #{uri} (#{TIMEOUT}s)"
60
- nil
61
- rescue SocketError, Errno::ECONNREFUSED => e
62
- warn "[Kiso::Icons] Network error: #{e.message}"
63
- nil
64
- end
65
-
66
- def warn_to_pin(set_prefix, icon_name, elapsed_ms)
67
- message = "[Kiso::Icons] Fetched #{set_prefix}:#{icon_name} from Iconify API (#{elapsed_ms}ms).\n" \
68
- " Pin this set for offline use: bin/kiso-icons pin #{set_prefix}"
69
-
70
- if defined?(Rails) && defined?(Rails.logger)
71
- Rails.logger.debug { message }
72
- else
73
- warn message
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end