rails_icons 1.9.0 → 1.10.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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +45 -15
- data/app/controllers/rails_icons/sprites_controller.rb +2 -0
- data/lib/generators/rails_icons/initializer_generator.rb +20 -31
- data/lib/generators/rails_icons/install_generator.rb +10 -3
- data/lib/generators/rails_icons/sync_generator.rb +6 -1
- data/lib/rails_icons/base_generator.rb +1 -12
- data/lib/rails_icons/helpers/sprite_helper.rb +3 -2
- data/lib/rails_icons/version.rb +1 -1
- data/lib/rails_icons.rb +5 -0
- data/rails_icons.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87983d78c763bf00cac5dfcff0cd432d9140643b12235dd3f549aa2d20a4a85f
|
|
4
|
+
data.tar.gz: 892fdb71667edd0e038265645e01a17757c5e16a8227b7265ed1dbb082d0213e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f5c76f15631ed655d92d476c7c945f9a8e33981061fece4aed02ffc83b5cd84888d605c5e98b0b4496c97d7bf8b8a00798b6614010959799326ca10c67dea45
|
|
7
|
+
data.tar.gz: b9e806967af7a3aaf42d46e79dbc9433e4dd3d8ecd3781a66c24e33c15c54913ae95d31ad0de1dc87fb24a2431ef5e6fa9b6c07861ace8b2d51161af17564124
|
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rails_icons (1.
|
|
5
|
-
icons (~> 0.
|
|
4
|
+
rails_icons (1.10.0)
|
|
5
|
+
icons (~> 0.11.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.
|
|
105
|
+
icons (0.11.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
|
@@ -44,6 +44,9 @@ rails generate rails_icons:install --library=heroicons
|
|
|
44
44
|
|
|
45
45
|
# Or multiple at once
|
|
46
46
|
rails generate rails_icons:install --libraries=heroicons lucide
|
|
47
|
+
|
|
48
|
+
# Or only specific variants
|
|
49
|
+
rails generate rails_icons:install --library=heroicons --variants solid outline
|
|
47
50
|
```
|
|
48
51
|
|
|
49
52
|
The generator also mounts an icon preview at `/rails_icons` where you can browse and search all your available icons. This route is open by default, so restrict it in production if needed.
|
|
@@ -81,6 +84,7 @@ icon "check", stroke_width: 2
|
|
|
81
84
|
|
|
82
85
|
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
86
|
|
|
87
|
+
|
|
84
88
|
### Configuration
|
|
85
89
|
|
|
86
90
|
```ruby
|
|
@@ -145,7 +149,7 @@ config.default_sprite_location = nil
|
|
|
145
149
|
|
|
146
150
|
You can also generate a sprite for a specific set of icons:
|
|
147
151
|
```erb
|
|
148
|
-
<%= icons_sprite
|
|
152
|
+
<%= icons_sprite ["check", "search"], library: "heroicons", variant: "outline" %>
|
|
149
153
|
```
|
|
150
154
|
|
|
151
155
|
|
|
@@ -195,19 +199,6 @@ Rails Icons also includes a few animated icons. Great for loading states and so
|
|
|
195
199
|
Use like this: `icon "faded-spinner", library: "animated"`. The same attributes as the other libraries are available.
|
|
196
200
|
|
|
197
201
|
|
|
198
|
-
## Custom icon library
|
|
199
|
-
|
|
200
|
-
Need to use an icon from another library (for example [Simple Icons](https://simpleicons.org/))?
|
|
201
|
-
|
|
202
|
-
1. run `rails generate rails_icons:initializer --custom=simple_icons`;
|
|
203
|
-
2. add the SVG icons to the created directory (*app/assets/svg/icons/simple_icons*);
|
|
204
|
-
|
|
205
|
-
Every custom icon can now be used with the same interface as first-party icon libraries:
|
|
206
|
-
```ruby
|
|
207
|
-
icon "apple", library: "simple_icons", class: "text-black"
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
|
|
211
202
|
## Sync icons
|
|
212
203
|
|
|
213
204
|
To sync all libraries, run:
|
|
@@ -223,13 +214,52 @@ rails generate rails_icons:sync --library=heroicons
|
|
|
223
214
|
rails generate rails_icons:sync --libraries=heroicons lucide
|
|
224
215
|
```
|
|
225
216
|
|
|
217
|
+
To sync only specific variants for a library:
|
|
218
|
+
```bash
|
|
219
|
+
rails generate rails_icons:sync --library=heroicons --variants solid outline
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
## Custom icon libraries
|
|
224
|
+
|
|
225
|
+
Rails Icons pulls SVGs straight from the path `<icons_path>/<library_name>/<name>.svg`. No generator is required for custom icons. Configuration is optional and only used to define defaults.
|
|
226
|
+
|
|
227
|
+
To add a custom library, create its directory and drop in your SVGs:
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
app/assets/svg/icons/simple_icons/apple.svg
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
(Alternatively, scaffold it with `rails generate rails_icons:install --library=simple_icons`, which creates the directory and adds `config.custom_library :simple_icons` in the initializer.)
|
|
234
|
+
|
|
235
|
+
Use them like any other library:
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
icon "apple", library: :simple_icons
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
To add a git source for syncing, edit the initializer:
|
|
242
|
+
```ruby
|
|
243
|
+
RailsIcons.configure do |config|
|
|
244
|
+
config.custom_library :my_icons, source: {
|
|
245
|
+
url: "https://github.com/user/icons.git",
|
|
246
|
+
variants: { default: "." }
|
|
247
|
+
}
|
|
248
|
+
end
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Then sync:
|
|
252
|
+
```bash
|
|
253
|
+
rails generate rails_icons:sync --library=my_icons
|
|
254
|
+
```
|
|
255
|
+
|
|
226
256
|
|
|
227
257
|
## Projects using Rails Icons
|
|
228
258
|
|
|
229
259
|
- [Rails Designer UI Components](https://railsdesigner.com/components/) — The first professionally-designed UI components library for Ruby on Rails apps
|
|
230
260
|
- [Chirp Form](https://chirpform.com/) — Add forms to any site. Display responses anywhere
|
|
231
|
-
- [Helptail](https://helptail.com/) — Put your routine tasks on autopilot
|
|
232
261
|
- [Seal Static](https://sealstatic.com/) — Host sites for every need
|
|
262
|
+
- [Spinal CMS](https://spinalcms.com/) — Minimal and beautiful CMS for static site generators
|
|
233
263
|
|
|
234
264
|
|
|
235
265
|
## Contributing
|
|
@@ -8,10 +8,9 @@ module RailsIcons
|
|
|
8
8
|
|
|
9
9
|
desc "Create the Rails Icons initializer."
|
|
10
10
|
|
|
11
|
-
class_option :library, type: :string, desc: "Choose a library
|
|
12
|
-
class_option :libraries, type: :array, default: [], desc: "Choose libraries
|
|
11
|
+
class_option :library, type: :string, desc: "Choose a library"
|
|
12
|
+
class_option :libraries, type: :array, default: [], desc: "Choose libraries"
|
|
13
13
|
class_option :destination, type: :string, default: RailsIcons.configuration&.icons_path, desc: "Specify icons folder"
|
|
14
|
-
class_option :custom, type: :string, desc: "Name of the custom library"
|
|
15
14
|
|
|
16
15
|
def copy_initializer
|
|
17
16
|
return if File.exist?(INITIALIZER)
|
|
@@ -44,49 +43,39 @@ module RailsIcons
|
|
|
44
43
|
end
|
|
45
44
|
|
|
46
45
|
def insert_libraries_configuration
|
|
46
|
+
return if first_party_libraries.empty?
|
|
47
|
+
|
|
47
48
|
insert_into_file INITIALIZER, "\n#{library_configuration}", before: "end"
|
|
48
49
|
end
|
|
49
50
|
|
|
50
|
-
def
|
|
51
|
-
return if
|
|
51
|
+
def setup_custom_libraries
|
|
52
|
+
return if custom_libraries.empty?
|
|
53
|
+
|
|
54
|
+
insert_into_file INITIALIZER, "\n#{custom_library_configuration}", before: "end"
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
custom_libraries.each do |name|
|
|
57
|
+
FileUtils.mkdir_p(File.join(options[:destination], name))
|
|
58
|
+
end
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
private
|
|
58
62
|
|
|
59
63
|
INITIALIZER = "config/initializers/rails_icons.rb"
|
|
60
64
|
|
|
61
|
-
def
|
|
62
|
-
|
|
63
|
-
custom_default_configuration = <<~RB.indent(2)
|
|
64
|
-
|
|
65
|
-
config.libraries.merge!(
|
|
66
|
-
)
|
|
67
|
-
RB
|
|
68
|
-
|
|
69
|
-
insert_into_file INITIALIZER, custom_default_configuration, before: "end"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
insert_into_file INITIALIZER, "\n#{custom_configuration}", after: "config.libraries.merge!("
|
|
65
|
+
def library_configuration
|
|
66
|
+
first_party_libraries.map { |library| RailsIcons.libraries[library.to_sym].initializer_config }.join("\n")
|
|
73
67
|
end
|
|
74
68
|
|
|
75
|
-
def
|
|
69
|
+
def custom_library_configuration
|
|
70
|
+
custom_libraries.map { |name| "config.custom_library :#{name}" }.join("\n")
|
|
71
|
+
end
|
|
76
72
|
|
|
77
|
-
def
|
|
78
|
-
libraries.
|
|
73
|
+
def first_party_libraries
|
|
74
|
+
libraries.select { |library| RailsIcons.libraries.key?(library.to_sym) }
|
|
79
75
|
end
|
|
80
76
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
#{options[:custom]}: {
|
|
84
|
-
# path: "app/assets/svg/icons/#{options[:custom]}/",
|
|
85
|
-
default: {
|
|
86
|
-
css: "size-6"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
RB
|
|
77
|
+
def custom_libraries
|
|
78
|
+
libraries.reject { |library| RailsIcons.libraries.key?(library.to_sym) }
|
|
90
79
|
end
|
|
91
80
|
|
|
92
81
|
def default_configuration_exists?
|
|
@@ -12,15 +12,16 @@ module RailsIcons
|
|
|
12
12
|
class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})"
|
|
13
13
|
class_option :destination, type: :string, default: RailsIcons.configuration.icons_path, desc: "Specify destination folder for icons"
|
|
14
14
|
class_option :skip_sync, type: :boolean, default: false
|
|
15
|
+
class_option :variants, type: :array, desc: "Only sync specific variants (e.g. solid outline)"
|
|
15
16
|
|
|
16
17
|
def initializer_generator
|
|
17
18
|
generate("rails_icons:initializer", *attributes)
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
def sync_generator
|
|
21
|
-
return if options[:skip_sync] ||
|
|
22
|
+
return if options[:skip_sync] || sync_libraries.blank?
|
|
22
23
|
|
|
23
|
-
generate("rails_icons:sync",
|
|
24
|
+
generate("rails_icons:sync", "--libraries=#{sync_libraries.map(&:downcase).join(" ")}")
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
def add_route
|
|
@@ -34,13 +35,19 @@ module RailsIcons
|
|
|
34
35
|
private
|
|
35
36
|
|
|
36
37
|
def attributes
|
|
37
|
-
["--libraries=#{libraries.map(&:downcase).join(" ")}", "--destination=#{options[:destination]}"].
|
|
38
|
+
["--libraries=#{libraries.map(&:downcase).join(" ")}", "--destination=#{options[:destination]}"].tap do |parts|
|
|
39
|
+
parts << "--variants=#{options[:variants].join(" ")}" if options[:variants].present?
|
|
40
|
+
end.join(" ")
|
|
38
41
|
end
|
|
39
42
|
|
|
40
43
|
def libraries
|
|
41
44
|
[*options.libraries, options.library].compact_blank
|
|
42
45
|
end
|
|
43
46
|
|
|
47
|
+
def sync_libraries
|
|
48
|
+
libraries.select { |library| RailsIcons.libraries.key?(library.to_sym) }
|
|
49
|
+
end
|
|
50
|
+
|
|
44
51
|
def validatable? = true
|
|
45
52
|
end
|
|
46
53
|
end
|
|
@@ -10,13 +10,18 @@ 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 :variants, type: :array, desc: "Only sync specific variants (e.g. solid outline)"
|
|
13
14
|
|
|
14
15
|
def sync_icons
|
|
15
|
-
libraries.each { |library| Icons::Sync.new(library).now }
|
|
16
|
+
libraries.each { |library| Icons::Sync.new(library, variants: variants).now }
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
private
|
|
19
20
|
|
|
21
|
+
def variants
|
|
22
|
+
options[:variants]&.map(&:to_sym)
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
def libraries
|
|
21
26
|
[options[:library], *options[:libraries]]
|
|
22
27
|
.compact_blank
|
|
@@ -13,10 +13,7 @@ module RailsIcons
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
15
|
def validate!
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
raise Icons::LibraryNotFound.new("") if libraries.empty?
|
|
19
|
-
raise Icons::LibraryNotFound.new(invalid_libraries.join(", ")) if invalid_libraries.any?
|
|
16
|
+
raise Icons::LibraryNotFound.new if libraries.empty?
|
|
20
17
|
end
|
|
21
18
|
|
|
22
19
|
def validatable? = false
|
|
@@ -25,14 +22,6 @@ module RailsIcons
|
|
|
25
22
|
[*options.libraries, options.library].compact_blank
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
def invalid_libraries
|
|
29
|
-
libraries.map(&:to_sym).map(&:downcase).reject { |library| RailsIcons.libraries.key?(library) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def custom_library?
|
|
33
|
-
options.custom.present?
|
|
34
|
-
end
|
|
35
|
-
|
|
36
25
|
# Uses `gsub_file` as a read-only operation to check file content. This
|
|
37
26
|
# approach is preferred over `File.read` because `gsub_file` is properly stubbed
|
|
38
27
|
# in generator tests, while `File.read` would fail in the test environment.
|
|
@@ -9,6 +9,7 @@ module RailsIcons
|
|
|
9
9
|
#
|
|
10
10
|
# @param name [String] The icon name
|
|
11
11
|
# @param library [String] The icon library (defaults to RailsIcons configuration)
|
|
12
|
+
# @param from [String] Syntactic sugar for a cleanly readable view layer API (preferred over `library`)
|
|
12
13
|
# @param variant [String] The icon variant (optional)
|
|
13
14
|
# @param sprite_location [String] Override sprite URL (optional)
|
|
14
15
|
# @param arguments [Hash] Additional arguments including class, data, stroke_width, etc.
|
|
@@ -21,10 +22,10 @@ module RailsIcons
|
|
|
21
22
|
# <%= sprite_icon "check", variant: "solid", library: "heroicons" %>
|
|
22
23
|
# <%= sprite_icon "heart", library: "lucide", data: { controller: "favorite" } %>
|
|
23
24
|
#
|
|
24
|
-
def sprite_icon(name, library: nil, variant: nil, sprite_location: nil, **arguments)
|
|
25
|
+
def sprite_icon(name, library: nil, from: library, variant: nil, sprite_location: nil, **arguments)
|
|
25
26
|
Icons::SpriteIcon.new(
|
|
26
27
|
name: name,
|
|
27
|
-
library: library || RailsIcons.configuration.default_library,
|
|
28
|
+
library: from || library || RailsIcons.configuration.default_library,
|
|
28
29
|
variant: variant,
|
|
29
30
|
sprite_location: sprite_location,
|
|
30
31
|
arguments: arguments
|
data/lib/rails_icons/version.rb
CHANGED
data/lib/rails_icons.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_support/core_ext/numeric/time"
|
|
3
4
|
require "icons"
|
|
4
5
|
|
|
5
6
|
require_relative "rails_icons/version"
|
|
@@ -7,6 +8,8 @@ require_relative "rails_icons/engine"
|
|
|
7
8
|
|
|
8
9
|
module RailsIcons
|
|
9
10
|
class << self
|
|
11
|
+
attr_accessor :sprite_cache_expires_in
|
|
12
|
+
|
|
10
13
|
# @yield [config] Yields a configuration object
|
|
11
14
|
# @yieldparam config [Icons::Configuration]
|
|
12
15
|
#
|
|
@@ -21,4 +24,6 @@ module RailsIcons
|
|
|
21
24
|
#
|
|
22
25
|
def libraries = Icons.libraries
|
|
23
26
|
end
|
|
27
|
+
|
|
28
|
+
self.sprite_cache_expires_in = 1.hour
|
|
24
29
|
end
|
data/rails_icons.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
|
|
11
11
|
spec.summary = "Add any icon library to a Rails app"
|
|
12
12
|
spec.description = "Add any icon library to a Rails app, from Heroicons, to Lucide to Tabler (and others). Rails Icons is library-agnostic, so you can add any library while using the same interface."
|
|
13
|
-
spec.homepage = "https://railsdesigner.com/rails-icons/"
|
|
13
|
+
spec.homepage = "https://railsdesigner.com/open-source/rails-icons/"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
@@ -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.
|
|
22
|
+
spec.add_dependency "icons", "~> 0.11.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.
|
|
4
|
+
version: 1.10.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.
|
|
32
|
+
version: 0.11.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.
|
|
39
|
+
version: 0.11.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.
|
|
@@ -87,11 +87,11 @@ files:
|
|
|
87
87
|
- lib/rails_icons/version.rb
|
|
88
88
|
- lib/ruby_lsp/rails_icons/addon.rb
|
|
89
89
|
- rails_icons.gemspec
|
|
90
|
-
homepage: https://railsdesigner.com/rails-icons/
|
|
90
|
+
homepage: https://railsdesigner.com/open-source/rails-icons/
|
|
91
91
|
licenses:
|
|
92
92
|
- MIT
|
|
93
93
|
metadata:
|
|
94
|
-
homepage_uri: https://railsdesigner.com/rails-icons/
|
|
94
|
+
homepage_uri: https://railsdesigner.com/open-source/rails-icons/
|
|
95
95
|
source_code_uri: https://github.com/Rails-Designer/rails_icons/
|
|
96
96
|
rdoc_options: []
|
|
97
97
|
require_paths:
|
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
107
|
- !ruby/object:Gem::Version
|
|
108
108
|
version: '0'
|
|
109
109
|
requirements: []
|
|
110
|
-
rubygems_version: 4.0.
|
|
110
|
+
rubygems_version: 4.0.22
|
|
111
111
|
specification_version: 4
|
|
112
112
|
summary: Add any icon library to a Rails app
|
|
113
113
|
test_files: []
|