rails_icons 1.8.0 → 1.9.0

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: 9d05be67d1c13063b9c5fca713d8ef525f2859bc06052909d5bd2df13bbede6f
4
- data.tar.gz: 37d0a613b5c7cbeac079203e5cd44337fd338f58f0e2b5ec8ad111cc4897e9b0
3
+ metadata.gz: 7cd203323e3d677c596eafcbc471b132b29bae354de297cdb96aee0da7a9b842
4
+ data.tar.gz: 777f5a17de05f8c66a7b5853af51b170bef1a55011fd9599cb397ef82aa34b0c
5
5
  SHA512:
6
- metadata.gz: 7d6fd9ff135d39bb5b02cb70e7a96b8a12d3f2f31c95c91cc0faab8280a87f54a97752254291bbe61083d409c7a125cef07d53f2ce7a0e2c4fceac28fbf11e66
7
- data.tar.gz: fdcffc8c5dfcbb944aea21f64994989d207b968764c0e74f9ff59fd5b8cab4294e15a9e4c35fbce918d3e4011d9e17566a0b6ef57c944a9c560c747c5ab2fe25
6
+ metadata.gz: 1daf94a537ad62da679b0c09696beeaeb8d74e207d393f126b682d54f134eb39468ae943080079dd16b7caa80a97f6b8b6721dc626e8a4bdbb0bc318c1315c43
7
+ data.tar.gz: cafc3c92e4cc3b8146eab5879ea8549f6fbd5b0929487a18ed00c5a3f0c8a775f8d17289e61431e808a8b29fb9b41b7734e2ca976b4f72a5ed97106cbe05fbab
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_icons (1.8.0)
5
- icons (~> 0.8.1)
4
+ rails_icons (1.9.0)
5
+ icons (~> 0.9.0)
6
6
  rails (>= 7.0)
7
7
 
8
8
  GEM
@@ -102,7 +102,7 @@ GEM
102
102
  activesupport (>= 6.1)
103
103
  i18n (1.14.7)
104
104
  concurrent-ruby (~> 1.0)
105
- icons (0.8.1)
105
+ icons (0.9.0)
106
106
  nokogiri (~> 1.16, >= 1.16.4)
107
107
  io-console (0.8.1)
108
108
  irb (1.15.2)
data/README.md CHANGED
@@ -12,7 +12,7 @@ icon "check", class: "text-gray-500"
12
12
  icon "apple", library: "simple_icons", class: "text-black"
13
13
  ```
14
14
 
15
- The icons are sourced directly from their respective GitHub repositories, ensuring Rails Icons remain lightweight.
15
+ The icons are sourced directly from their respective GitHub repositories via the [Icons](https://github.com/Rails-Designer/icons) gem, ensuring Rails Icons remain lightweight.
16
16
 
17
17
 
18
18
  **Sponsored By [Rails Designer](https://railsdesigner.com/)**
@@ -77,6 +77,96 @@ icon "check", stroke_width: 2
77
77
  ```
78
78
 
79
79
 
80
+ ## Sprites
81
+
82
+ Rails Icons supports SVG sprites for improved performance. Instead of inlining each icon's full SVG, sprite icons reference a shared set of `<symbol>` definitions via `<use href="…">`.
83
+
84
+ ### Configuration
85
+
86
+ ```ruby
87
+ # config/initializers/rails_icons.rb
88
+ RailsIcons.configure do |config|
89
+ config.default_library = "heroicons"
90
+ config.default_variant = "outline"
91
+
92
+ # Where `sprite_icon` references symbols. Defaults to the gem-served
93
+ # endpoint below. Set to nil to use inline mode (`<%= icons_sprite %>` in layout).
94
+ config.default_sprite_location = "/rails_icons/sprite.svg"
95
+
96
+ # Set to true to validate that referenced icons exist on disk
97
+ config.validate_sprite_icons = false
98
+
99
+ # Define which icons to include in the sprite
100
+ config.sprite = {
101
+ heroicons: {
102
+ outline: %w[check chevron-down menu search x],
103
+ mini: %w[check chevron-down]
104
+ }
105
+ }
106
+ end
107
+ ```
108
+
109
+
110
+ ### External sprite (default)
111
+
112
+ Rails Icons serves the sprite at `/rails_icons/sprite.svg` out of the box — no controller, route or MIME type setup needed. The endpoint sits at the host app level, so it stays reachable even when the preview engine is mounted behind authentication.
113
+ ```erb
114
+ <%= sprite_icon "check" %>
115
+ <%# renders: <svg><use href="/rails_icons/sprite.svg#heroicons_outline_check"></use></svg> %>
116
+ ```
117
+
118
+ Point at a precompiled file or a CDN by changing the location:
119
+ ```ruby
120
+ config.default_sprite_location = "https://cdn.example.com/sprite_icons.svg"
121
+ ```
122
+
123
+ Override per icon:
124
+ ```erb
125
+ <%= sprite_icon "check", sprite_location: "/assets/sprites.svg" %>
126
+ ```
127
+
128
+
129
+ ### Inline sprite
130
+
131
+ Set the location to `nil` and embed the sprite directly in your layout:
132
+ ```ruby
133
+ config.default_sprite_location = nil
134
+ ```
135
+
136
+ ```erb
137
+ <body>
138
+ <%= icons_sprite %>
139
+
140
+ <%= sprite_icon "check" %>
141
+ <%= sprite_icon "search", class: "text-blue-500" %>
142
+ <%= sprite_icon "menu", data: { controller: "nav" } %>
143
+ </body>
144
+ ```
145
+
146
+ You can also generate a sprite for a specific set of icons:
147
+ ```erb
148
+ <%= icons_sprite(["check", "search"], library: "heroicons", variant: "outline") %>
149
+ ```
150
+
151
+
152
+ ### Helpers
153
+
154
+ `sprite_icon` accepts the same options as `icon`:
155
+ ```ruby
156
+ sprite_icon "check"
157
+ sprite_icon "check", library: "heroicons", variant: "mini"
158
+ sprite_icon "check", class: "size-6", data: { controller: "swap" }, stroke_width: 2
159
+ sprite_icon "check", sprite_location: "/sprite.svg"
160
+ ```
161
+
162
+ `icons_sprite` generates the inline `<svg>` containing `<symbol>` definitions:
163
+ ```ruby
164
+ icons_sprite # all configured icons
165
+ icons_sprite ["check", "search"] # specific icons
166
+ icons_sprite ["check", "search"], library: "heroicons", variant: "outline" # with library/variant
167
+ ```
168
+
169
+
80
170
  ## First-party libraries
81
171
 
82
172
  - [Boxicons](https://railsdesigner.com/open-source/rails-icons/boxicons/) (1600+ icons)
@@ -139,6 +229,7 @@ rails generate rails_icons:sync --libraries=heroicons lucide
139
229
  - [Rails Designer UI Components](https://railsdesigner.com/components/) — The first professionally-designed UI components library for Ruby on Rails apps
140
230
  - [Chirp Form](https://chirpform.com/) — Add forms to any site. Display responses anywhere
141
231
  - [Helptail](https://helptail.com/) — Put your routine tasks on autopilot
232
+ - [Seal Static](https://sealstatic.com/) — Host sites for every need
142
233
 
143
234
 
144
235
  ## Contributing
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsIcons
4
+ class SpritesController < ActionController::Base
5
+ def show
6
+ respond_to do |format|
7
+ format.svg { render plain: Icons::Sprite.new.svg, content_type: "image/svg+xml" }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -10,7 +10,7 @@ module RailsIcons
10
10
 
11
11
  class_option :library, type: :string, desc: "Choose a library (#{RailsIcons.libraries.keys.join("/")})"
12
12
  class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})"
13
- class_option :destination, type: :string, default: RailsIcons.configuration.icons_path, desc: "Specify icons folder"
13
+ class_option :destination, type: :string, default: RailsIcons.configuration&.icons_path, desc: "Specify icons folder"
14
14
  class_option :custom, type: :string, desc: "Name of the custom library"
15
15
 
16
16
  def copy_initializer
@@ -34,7 +34,7 @@ module RailsIcons
34
34
  end
35
35
 
36
36
  def insert_custom_icons_path
37
- return if options[:destination] && options[:destination] == RailsIcons.configuration.icons_path
37
+ return if options[:destination] == RailsIcons.configuration&.icons_path
38
38
 
39
39
  insert_into_file INITIALIZER, <<~RB.indent(2), after: "RailsIcons.configure do |config|\n"
40
40
  # Default icons path
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails_icons/helpers/icon_helper"
4
+ require "rails_icons/helpers/sprite_helper"
4
5
 
5
6
  module RailsIcons
6
7
  class Engine < ::Rails::Engine
@@ -12,9 +13,31 @@ module RailsIcons
12
13
  end
13
14
  end
14
15
 
16
+ initializer "rails_icons.sprite_configuration", before: :load_config_initializers do
17
+ Icons.configure do |config|
18
+ config.sprite = {}
19
+ config.default_sprite_location = "/rails_icons/sprite.svg"
20
+ config.validate_sprite_icons = false
21
+ end
22
+ end
23
+
24
+ initializer "rails_icons.mime_types", before: :load_config_initializers do
25
+ Mime::Type.register "image/svg+xml", :svg unless Mime::Type.lookup_by_extension(:svg)
26
+ end
27
+
28
+ initializer "rails_icons.sprite_route", after: :load_config_initializers do |app|
29
+ app.routes.prepend do
30
+ get "/rails_icons/sprite.svg",
31
+ to: "rails_icons/sprites#show",
32
+ as: :rails_icons_sprite,
33
+ defaults: {format: :svg}
34
+ end
35
+ end
36
+
15
37
  initializer "rails_icons.helpers" do
16
38
  ActiveSupport.on_load(:action_view) do
17
39
  include RailsIcons::Helpers::IconHelper
40
+ include RailsIcons::Helpers::SpriteHelper
18
41
  end
19
42
  end
20
43
  end
@@ -3,6 +3,20 @@
3
3
  module RailsIcons
4
4
  module Helpers
5
5
  module IconHelper
6
+ # Renders an SVG icon
7
+ #
8
+ # @param name [String] The icon name
9
+ # @param library [String] The icon library (defaults to RailsIcons configuration)
10
+ # @param from [String] Syntactic sugar for a cleanly readable view layer API (preferred over `library`)
11
+ # @param variant [String] The icon variant (optional)
12
+ # @param arguments [Hash] Additional arguments including class, data, stroke_width, etc.
13
+ # @return [ActiveSupport::SafeBuffer] An HTML-safe SVG string
14
+ #
15
+ # @example
16
+ # <%= icon "chevron-down" %>
17
+ # <%= icon "search", class: "text-blue-500" %>
18
+ # <%= icon "check", variant: "solid", library: "heroicons" %>
19
+ #
6
20
  def icon(name, library: RailsIcons.configuration.default_library, from: library, variant: nil, **arguments)
7
21
  Icons::Icon.new(
8
22
  name: name,
@@ -12,6 +26,19 @@ module RailsIcons
12
26
  ).svg.html_safe
13
27
  end
14
28
 
29
+ # Returns a base64-encoded data URI for an SVG icon
30
+ #
31
+ # @param name [String] The icon name
32
+ # @param library [String] The icon library (defaults to RailsIcons configuration)
33
+ # @param from [String] Syntactic sugar for a cleanly readable view layer API (preferred over `library`)
34
+ # @param variant [String] The icon variant (optional)
35
+ # @param arguments [Hash] Additional arguments including class, data, stroke_width, etc.
36
+ # @return [String] A base64-encoded data URI string (e.g. "data:image/svg+xml;base64,...")
37
+ #
38
+ # @example
39
+ # encoded_icon "chevron-down"
40
+ # # => "data:image/svg+xml;base64,PHN2ZyB4bWxucz0..."
41
+ #
15
42
  def encoded_icon(name, library: RailsIcons.configuration.default_library, from: library, variant: nil, **arguments)
16
43
  svg_content = Icons::Icon.new(
17
44
  name: name,
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "icons/sprite_icon"
4
+
5
+ module RailsIcons
6
+ module Helpers
7
+ module SpriteHelper
8
+ # Renders an SVG icon from a sprite, compatible with Rails Icons API
9
+ #
10
+ # @param name [String] The icon name
11
+ # @param library [String] The icon library (defaults to RailsIcons configuration)
12
+ # @param variant [String] The icon variant (optional)
13
+ # @param sprite_location [String] Override sprite URL (optional)
14
+ # @param arguments [Hash] Additional arguments including class, data, stroke_width, etc.
15
+ #
16
+ # @return [ActiveSupport::SafeBuffer] An HTML-safe SVG string referencing a sprite symbol
17
+ #
18
+ # @example
19
+ # <%= sprite_icon "chevron-down" %>
20
+ # <%= sprite_icon "search", class: "text-blue-500" %>
21
+ # <%= sprite_icon "check", variant: "solid", library: "heroicons" %>
22
+ # <%= sprite_icon "heart", library: "lucide", data: { controller: "favorite" } %>
23
+ #
24
+ def sprite_icon(name, library: nil, variant: nil, sprite_location: nil, **arguments)
25
+ Icons::SpriteIcon.new(
26
+ name: name,
27
+ library: library || RailsIcons.configuration.default_library,
28
+ variant: variant,
29
+ sprite_location: sprite_location,
30
+ arguments: arguments
31
+ ).svg.html_safe
32
+ end
33
+
34
+ # Returns the inline SVG sprite content containing all symbols
35
+ #
36
+ # @param icons [Array<String>] Optional array of icon names to include (defaults to all configured icons)
37
+ # @param library [String] Optional library to use for icons
38
+ # @param variant [String] Optional variant to use for icons
39
+ #
40
+ # @return [ActiveSupport::SafeBuffer] An HTML-safe SVG string containing `<symbol>` elements
41
+ #
42
+ # @example
43
+ # <%= icons_sprite %>
44
+ # <%= icons_sprite(["check", "search", "menu"]) %>
45
+ # <%= icons_sprite(["check", "search"], library: "heroicons", variant: "outline") %>
46
+ #
47
+ def icons_sprite(icons = nil, library: nil, variant: nil)
48
+ Icons::Sprite.new(icons: icons, library: library, variant: variant).svg.html_safe
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsIcons
2
- VERSION = "1.8.0"
2
+ VERSION = "1.9.0"
3
3
  end
data/lib/rails_icons.rb CHANGED
@@ -7,11 +7,18 @@ require_relative "rails_icons/engine"
7
7
 
8
8
  module RailsIcons
9
9
  class << self
10
+ # @yield [config] Yields a configuration object
11
+ # @yieldparam config [Icons::Configuration]
12
+ #
10
13
  def configure(&block) = Icons.configure(&block)
11
14
 
15
+ # @return [Icons::Configuration]
16
+ #
12
17
  def configuration = Icons.configuration
13
18
  alias_method :config, :configuration
14
19
 
20
+ # @return [Hash{Symbol => Icons::Library}] The registered icon libraries
21
+ #
15
22
  def libraries = Icons.libraries
16
23
  end
17
24
  end
data/rails_icons.gemspec CHANGED
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "Rakefile", "README.md", "rails_icons.gemspec", "Gemfile", "Gemfile.lock"]
20
20
 
21
21
  spec.add_dependency "rails", ">= 7.0"
22
- spec.add_dependency "icons", "~> 0.8.1"
22
+ spec.add_dependency "icons", "~> 0.9.0"
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer Developers
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 0.8.1
32
+ version: 0.9.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.8.1
39
+ version: 0.9.0
40
40
  description: Add any icon library to a Rails app, from Heroicons, to Lucide to Tabler
41
41
  (and others). Rails Icons is library-agnostic, so you can add any library while
42
42
  using the same interface.
@@ -54,6 +54,7 @@ files:
54
54
  - app/assets/javascripts/rails_icons/preview/preview.js
55
55
  - app/assets/stylesheets/rails_icons/preview.css
56
56
  - app/controllers/rails_icons/previews_controller.rb
57
+ - app/controllers/rails_icons/sprites_controller.rb
57
58
  - app/models/rails_icons/preview.rb
58
59
  - app/models/rails_icons/preview/tags.rb
59
60
  - app/models/rails_icons/preview/tags/animated.yml
@@ -82,6 +83,7 @@ files:
82
83
  - lib/rails_icons/engine.rb
83
84
  - lib/rails_icons/generate_tags.rb
84
85
  - lib/rails_icons/helpers/icon_helper.rb
86
+ - lib/rails_icons/helpers/sprite_helper.rb
85
87
  - lib/rails_icons/version.rb
86
88
  - lib/ruby_lsp/rails_icons/addon.rb
87
89
  - rails_icons.gemspec
@@ -105,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubygems_version: 4.0.9
110
+ rubygems_version: 4.0.14
109
111
  specification_version: 4
110
112
  summary: Add any icon library to a Rails app
111
113
  test_files: []