rails_icons 1.2.0 → 1.4.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: 6413197bc61eb646096a2c6abbf25696fd6eb8c986d85cc08519509066f83e85
4
- data.tar.gz: e1a1f952e9f499a39adba3958be58fc7f7aafbd779397ce5b7d62c4e1d16cb9c
3
+ metadata.gz: 3d7cd3efc6fcdd950e2a509b16d65cb70657b5444ac28b3a16e86a36aaae9a68
4
+ data.tar.gz: 41e21e7a5d8fa720b16e90c7a67534de8c2fd2e59eac726408243778e2d90f60
5
5
  SHA512:
6
- metadata.gz: 37de7ecd41860ff20570285ba3910192c5e52273a0991ae06f51a6d823078031bb0304fce7fae49a8866d5b71c2caf3a99f6123b1cfa9209b61b35acf86e1018
7
- data.tar.gz: 4590aceead66f68e8b890a53823eb9fe8c959c58678631f854bedf49c763c81deda9de0175763b26fb2ad135be3d561e8ab3dd5a2c19b921cd06fad710330884
6
+ metadata.gz: 91571161520d6d7a57b6fc53d7e2a81ec49dfc76c58d922b0c3adb1e706207f55de846b436e7d87803262f18d8dfa0e4a4a7874bf7e8b2770df023f5091d4b7b
7
+ data.tar.gz: 07f2cdb947abed671415af4ec25b784a651acd094581099622bc7e40bf44e98ec70283ee0e1154d974c7a8e6586e1a3a263a88a338c3d0c7af1a42283503443d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_icons (1.2.0)
4
+ rails_icons (1.4.0)
5
5
  nokogiri (~> 1.16, >= 1.16.4)
6
6
  rails (> 6.1)
7
7
 
data/README.md CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  Add any icon library to a Rails app. Rails Icons has first-party support for a [handful of libraries](#first-party-libraries). It is library agnostic so it can be used with any icon library using the same interface.
4
4
 
5
+ ![Rails Icons - A collection of icons from popular libraries like Feather, Lucide, and Heroicons arranged in a grid pattern around the title text](https://raw.githubusercontent.com/Rails-Designer/rails_icons/HEAD/.github/cover.jpg)
6
+
5
7
  ```erb
6
8
  # Using the default icon library
7
- <%= icon "check", class: "text-gray-500" %>
9
+ icon "check", class: "text-gray-500"
8
10
 
9
11
  # Using any custom library
10
- <%= icon "apple", library: "simple_icons", class: "text-black" %>
12
+ icon "apple", library: "simple_icons", class: "text-black"
11
13
  ```
12
14
 
13
15
  The icons are sourced directly from their respective GitHub repositories, ensuring Rails Icons remain lightweight.
@@ -23,6 +25,8 @@ The icons are sourced directly from their respective GitHub repositories, ensuri
23
25
  </picture>
24
26
  </a>
25
27
 
28
+ Want to make JavaScript your second-favorite language? 👉 [JavaScript for Rails Developers](https://javascriptforrails.com/)
29
+
26
30
 
27
31
  ## Install
28
32
 
@@ -97,7 +101,7 @@ Rails Icons also includes a few animated icons. Great for loading states and so
97
101
  - `fading-dots`
98
102
  - `bouncing-dots`
99
103
 
100
- Use like this: `icon "faded-spinner", library: "animated"`. The same attributes as the others libraries are available.
104
+ Use like this: `icon "faded-spinner", library: "animated"`. The same attributes as the other libraries are available.
101
105
 
102
106
 
103
107
  ## Custom icon library
@@ -105,7 +109,7 @@ Use like this: `icon "faded-spinner", library: "animated"`. The same attributes
105
109
  Need to use an icon from another library?
106
110
 
107
111
  1. run `rails generate rails_icons:initializer --custom=simple_icons`;
108
- 2. add the (SVG) icons to the created directory **app/assets/svg/icons/simple_icons**;
112
+ 2. add the (SVG) icons to the created directory *app/assets/svg/icons/simple_icons*;
109
113
 
110
114
  Every custom icon can now be used with the same interface as first-party icon libraries.
111
115
  ```ruby
@@ -47,7 +47,7 @@ module RailsIcons
47
47
  end
48
48
 
49
49
  def setup_custom_configuration
50
- return "" if options[:custom].blank?
50
+ return if options[:custom].blank?
51
51
 
52
52
  insert_custom_configuration
53
53
  create_custom_directory
@@ -58,7 +58,7 @@ module RailsIcons
58
58
  INITIALIZER = "config/initializers/rails_icons.rb"
59
59
 
60
60
  def insert_custom_configuration
61
- unless File.read(INITIALIZER).include?("config.libraries.merge!")
61
+ unless file_contains?(INITIALIZER, "config.libraries.merge!")
62
62
  custom_default_configuration = <<~RB.indent(2)
63
63
  config.libraries.merge!(
64
64
 
@@ -99,5 +99,7 @@ module RailsIcons
99
99
  end
100
100
 
101
101
  def libraries = options[:libraries].map(&:downcase)
102
+
103
+ def validatable? = true
102
104
  end
103
105
  end
@@ -25,5 +25,7 @@ module RailsIcons
25
25
  private
26
26
 
27
27
  def attributes = ["--libraries=#{options[:libraries].map(&:downcase).join(" ")}", "--destination=#{options[:destination]}"].join(" ")
28
+
29
+ def validatable? = true
28
30
  end
29
31
  end
@@ -2,19 +2,47 @@
2
2
 
3
3
  module RailsIcons
4
4
  class BaseGenerator < Rails::Generators::Base
5
+ hide!
6
+
5
7
  def initialize(*arguments)
6
8
  super(*arguments)
7
9
 
8
- validate!
10
+ validate! if validatable?
9
11
  end
10
12
 
11
13
  private
12
14
 
13
15
  def validate!
16
+ return if custom_library?
17
+
14
18
  raise RailsIcons::LibraryNotFound.new("") if options.libraries.empty?
15
19
  raise RailsIcons::LibraryNotFound.new(invalid_libraries.join(", ")) if invalid_libraries.any?
16
20
  end
17
21
 
22
+ def validatable? = false
23
+
18
24
  def invalid_libraries = options.libraries.map(&:to_sym).map(&:downcase).reject { RailsIcons.libraries.key?(_1) }
25
+
26
+ def custom_library? = options.custom.present?
27
+
28
+ # Uses `gsub_file` as a read-only operation to check file content. This
29
+ # approach is preferred over `File.read` because `gsub_file` is properly stubbed
30
+ # in generator tests, while `File.read` would fail in the test environment.
31
+ #
32
+ def file_contains?(path, content)
33
+ return false unless File.exist?(path)
34
+
35
+ result = false
36
+
37
+ gsub_file(path, /.*/) do |file_content|
38
+ result = file_content.include?(content)
39
+
40
+ file_content
41
+ end
42
+
43
+ result
44
+ rescue Thor::Error
45
+ false
46
+ end
19
47
  end
20
48
  end
@@ -19,6 +19,7 @@ module RailsIcons
19
19
  def initializer_config
20
20
  <<~RB.indent(2)
21
21
  # Override Boxicons defaults
22
+ # config.libraries.boxicons.default_variant = "" # Set a default variant for Boxicons
22
23
  # config.libraries.boxicons.exclude_variants = [] # Exclude specific variants
23
24
 
24
25
  # config.libraries.boxicons.solid.css = "size-6"
@@ -17,6 +17,7 @@ module RailsIcons
17
17
  def initializer_config
18
18
  <<~RB.indent(2)
19
19
  # Override Feather defaults
20
+ # config.libraries.feather.default_variant = "" # Feather has no variants, this is provided for backwards compatibility
20
21
  # config.libraries.feather.exclude_variants = [] # Feather has no variants, this is provided for backwards compatibility
21
22
 
22
23
  # config.libraries.feather.default.css = "size-6"
@@ -18,6 +18,7 @@ module RailsIcons
18
18
  def initializer_config
19
19
  <<~RB.indent(2)
20
20
  # Override Flags defaults
21
+ # config.libraries.flags.default_variant = "" # Set a default variant for Flags
21
22
  # config.libraries.flags.exclude_variants = [:square, :landscape]
22
23
 
23
24
  # config.libraries.flags.square.default.css = "size-6"
@@ -20,6 +20,7 @@ module RailsIcons
20
20
  def initializer_config
21
21
  <<~RB.indent(2)
22
22
  # Override Heroicon defaults
23
+ # config.libraries.heroicons.default_variant = "" # Set a default variant for Heroicons
23
24
  # config.libraries.heroicons.exclude_variants = [:mini, :micro] # Exclude specific variants
24
25
 
25
26
  # config.libraries.heroicons.outline.default.css = "size-6"
@@ -17,6 +17,7 @@ module RailsIcons
17
17
  def initializer_config
18
18
  <<~RB.indent(2)
19
19
  # Override Linear defaults
20
+ # config.libraries.linear.default_variant = "" # Set a default variant for Linear
20
21
  # config.libraries.linear.exclude_variants = []
21
22
 
22
23
  # config.libraries.linear.default.css = "size-6"
@@ -17,6 +17,7 @@ module RailsIcons
17
17
  def initializer_config
18
18
  <<~RB.indent(2)
19
19
  # Override Lucide defaults
20
+ # config.libraries.lucide.default_variant = "" # Set a default variant for Lucide
20
21
  # config.libraries.lucide.exclude_variants = [] # Exclude specific variants
21
22
 
22
23
  # config.libraries.lucide.outline.default.css = "size-6"
@@ -22,6 +22,7 @@ module RailsIcons
22
22
  def initializer_config
23
23
  <<~RB.indent(2)
24
24
  # Override Phosphor defaults
25
+ # config.libraries.phosphor.default_variant = "" # Set a default variant for Phosphor
25
26
  # config.libraries.phosphor.exclude_variants = [:duotone, :thin] # Exclude specific variants
26
27
 
27
28
  # config.libraries.phosphor.bold.default.css = "size-6"
@@ -17,6 +17,7 @@ module RailsIcons
17
17
  def initializer_config
18
18
  <<~RB.indent(2)
19
19
  # Override Radix defaults
20
+ # config.libraries.radix.default_variant = "" # Radix has no variants, this is provided for backwards compatibility
20
21
  # config.libraries.radix.exclude_variants = [] # Radix has no variants, this is provided for backwards compatibility
21
22
  # config.libraries.radix.default.css = "size-6"
22
23
  # config.libraries.radix.default.stroke_width = "2"
@@ -20,6 +20,7 @@ module RailsIcons
20
20
  def initializer_config
21
21
  <<~RB.indent(2)
22
22
  # Override Sidekickicons defaults
23
+ # config.libraries.sidekickicons.default_variant = "" # Set a default variant for Sidekickicons
23
24
  # config.libraries.sidekickicons.exclude_variants = [:mini, :micro] # Exclude specific variants
24
25
 
25
26
  # config.libraries.sidekickicons.outline.default.css = "size-6"
@@ -18,6 +18,7 @@ module RailsIcons
18
18
  def initializer_config
19
19
  <<~RB.indent(2)
20
20
  # Override Tabler defaults
21
+ # config.libraries.tabler.default_variant = "" # Set a default variant for Tabler
21
22
  # config.libraries.tabler.exclude_variants = [] # Exclude specific variants
22
23
 
23
24
  # config.libraries.tabler.regular.default.css = "size-6"
@@ -17,6 +17,7 @@ module RailsIcons
17
17
  def initializer_config
18
18
  <<~RB.indent(2)
19
19
  # Override Weather defaults
20
+ # config.libraries.weather.default_variant = "" # Set a default variant for Wweather
20
21
  # config.libraries.weather.exclude_variants = []
21
22
 
22
23
  # config.libraries.weather.default.css = "size-6"
@@ -5,10 +5,10 @@ require_relative "../configuration"
5
5
  module RailsIcons
6
6
  module Helpers
7
7
  module IconHelper
8
- def icon(name, library: RailsIcons.configuration.default_library, variant: nil, **arguments)
8
+ def icon(name, library: RailsIcons.configuration.default_library, from: library, variant: nil, **arguments)
9
9
  RailsIcons::Icon.new(
10
10
  name: name,
11
- library: library,
11
+ library: from || library,
12
12
  variant: variant,
13
13
  arguments: arguments
14
14
  ).svg
@@ -2,7 +2,9 @@ require "rails_icons/icon/file_path"
2
2
  require "rails_icons/icon/attributes"
3
3
 
4
4
  class RailsIcons::Icon
5
- def initialize(name:, library:, arguments:, variant: nil)
5
+ def initialize(name:, library:, arguments:, variant: nil, config: RailsIcons.configuration)
6
+ @config = config # set first, config is used during initialization
7
+
6
8
  @name = name
7
9
  @library = library.to_s.inquiry
8
10
  @variant = (variant || set_variant).to_s
@@ -22,8 +24,8 @@ class RailsIcons::Icon
22
24
  private
23
25
 
24
26
  def set_variant
25
- RailsIcons.configuration.default_variant.presence ||
26
- RailsIcons.configuration.libraries.dig(@library.to_sym, :default_variant)
27
+ @config.libraries.dig(@library.to_sym, :default_variant).presence ||
28
+ @config.default_variant.presence
27
29
  end
28
30
 
29
31
  def error_message
@@ -55,7 +57,7 @@ class RailsIcons::Icon
55
57
  def default(key) = library_attributes.dig(:default, key)
56
58
 
57
59
  def library_attributes
58
- custom_library? ? custom_library : RailsIcons.configuration.libraries.dig(@library, @variant) || {}
60
+ custom_library? ? custom_library : @config.libraries.dig(@library, @variant) || {}
59
61
  end
60
62
 
61
63
  def custom_library
@@ -65,7 +67,7 @@ class RailsIcons::Icon
65
67
  &.dig("custom")
66
68
  &.dig(@library.to_sym)&.with_defaults(
67
69
  {
68
- path: [RailsIcons.configuration.destination_path, @library].join("/")
70
+ path: [@config.destination_path, @library].join("/")
69
71
  }
70
72
  ) || {}
71
73
  end
@@ -6,6 +6,8 @@ require "rails_icons/sync/process_variants"
6
6
  module RailsIcons
7
7
  module Sync
8
8
  class Engine < Rails::Generators::Base
9
+ hide!
10
+
9
11
  def initialize(name)
10
12
  super
11
13
 
@@ -6,6 +6,8 @@ require "rails_icons/sync/transformations"
6
6
  module RailsIcons
7
7
  module Sync
8
8
  class ProcessVariants < Rails::Generators::Base
9
+ hide!
10
+
9
11
  def initialize(temp_directory, name, library)
10
12
  @temp_directory, @name, @library = temp_directory, name, library
11
13
  end
@@ -1,6 +1,8 @@
1
1
  module RailsIcons
2
2
  module Sync
3
3
  class Transformations < Rails::Generators::Base
4
+ hide!
5
+
4
6
  def self.transform(filename, rules = {})
5
7
  basename = File.basename(filename, File.extname(filename))
6
8
 
@@ -1,3 +1,3 @@
1
1
  module RailsIcons
2
- VERSION = "1.2.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-03 00:00:00.000000000 Z
11
+ date: 2025-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails