rails_icons 1.0.0 → 1.2.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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -5
  3. data/README.md +27 -13
  4. data/lib/generators/rails_icons/initializer_generator.rb +24 -65
  5. data/lib/generators/rails_icons/install_generator.rb +8 -4
  6. data/lib/generators/rails_icons/sync_generator.rb +12 -43
  7. data/lib/rails_icons/base_generator.rb +20 -0
  8. data/lib/rails_icons/configuration/animated.rb +3 -1
  9. data/lib/rails_icons/configuration/boxicons.rb +77 -0
  10. data/lib/rails_icons/configuration/feather.rb +24 -1
  11. data/lib/rails_icons/configuration/flags.rb +68 -0
  12. data/lib/rails_icons/configuration/heroicons.rb +39 -4
  13. data/lib/rails_icons/configuration/linear.rb +48 -0
  14. data/lib/rails_icons/configuration/lucide.rb +24 -1
  15. data/lib/rails_icons/configuration/phosphor.rb +144 -0
  16. data/lib/rails_icons/configuration/radix.rb +46 -0
  17. data/lib/rails_icons/configuration/sidekickicons.rb +104 -0
  18. data/lib/rails_icons/configuration/tabler.rb +29 -1
  19. data/lib/rails_icons/configuration/weather.rb +54 -0
  20. data/lib/rails_icons/configuration.rb +4 -11
  21. data/lib/rails_icons/errors.rb +15 -1
  22. data/lib/rails_icons/icon/attributes.rb +7 -1
  23. data/lib/rails_icons/icon/file_path.rb +57 -0
  24. data/lib/rails_icons/icon.rb +4 -18
  25. data/lib/rails_icons/libraries.rb +28 -41
  26. data/lib/rails_icons/sync/engine.rb +75 -0
  27. data/lib/rails_icons/sync/process_variants.rb +74 -0
  28. data/lib/rails_icons/sync/transformations.rb +27 -0
  29. data/lib/rails_icons/version.rb +1 -1
  30. data/lib/rails_icons.rb +1 -1
  31. metadata +15 -4
  32. data/lib/generators/rails_icons/sync/engine.rb +0 -87
@@ -1,45 +1,32 @@
1
- module RailsIcons
2
- module Libraries
3
- module_function
4
-
5
- def all
6
- {
7
- feather: {
8
- name: "feather",
9
- url: "https://github.com/feathericons/feather.git",
10
- variants: {
11
- ".": "icons" # Feather has no variants, store in the top directory
12
- }
13
- },
1
+ require_relative "configuration/animated"
2
+ require_relative "configuration/boxicons"
3
+ require_relative "configuration/feather"
4
+ require_relative "configuration/flags"
5
+ require_relative "configuration/heroicons"
6
+ require_relative "configuration/linear"
7
+ require_relative "configuration/lucide"
8
+ require_relative "configuration/phosphor"
9
+ require_relative "configuration/radix"
10
+ require_relative "configuration/sidekickicons"
11
+ require_relative "configuration/tabler"
12
+ require_relative "configuration/weather"
14
13
 
15
- heroicons: {
16
- name: "heroicons",
17
- url: "https://github.com/tailwindlabs/heroicons.git",
18
- variants: {
19
- outline: "optimized/24/outline",
20
- solid: "optimized/24/solid",
21
- mini: "optimized/20/solid",
22
- micro: "optimized/16/solid"
23
- }
24
- },
25
-
26
- lucide: {
27
- name: "lucide",
28
- url: "https://github.com/lucide-icons/lucide.git",
29
- variants: {
30
- outline: "icons"
31
- }
32
- },
14
+ module RailsIcons
15
+ extend self
33
16
 
34
- tabler: {
35
- name: "tabler",
36
- url: "https://github.com/tabler/tabler-icons.git",
37
- variants: {
38
- filled: "icons/filled",
39
- outline: "icons/outline"
40
- }
41
- }
42
- }
43
- end
17
+ def libraries
18
+ {
19
+ boxicons: RailsIcons::Configuration::Boxicons,
20
+ feather: RailsIcons::Configuration::Feather,
21
+ flags: RailsIcons::Configuration::Flags,
22
+ heroicons: RailsIcons::Configuration::Heroicons,
23
+ linear: RailsIcons::Configuration::Linear,
24
+ lucide: RailsIcons::Configuration::Lucide,
25
+ phosphor: RailsIcons::Configuration::Phosphor,
26
+ radix: RailsIcons::Configuration::Radix,
27
+ sidekickicons: RailsIcons::Configuration::Sidekickicons,
28
+ tabler: RailsIcons::Configuration::Tabler,
29
+ weather: RailsIcons::Configuration::Weather
30
+ }
44
31
  end
45
32
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "rails_icons/sync/process_variants"
5
+
6
+ module RailsIcons
7
+ module Sync
8
+ class Engine < Rails::Generators::Base
9
+ def initialize(name)
10
+ super
11
+
12
+ raise "[Rails Icons] Not a valid library" if RailsIcons.libraries.keys.exclude?(name.to_sym)
13
+
14
+ @temp_directory, @name, @library = File.join(TEMP_DIRECTORY, name), name, RailsIcons.libraries.fetch(name.to_sym).source
15
+ end
16
+
17
+ def sync
18
+ clone_repository
19
+ process_variants
20
+ remove_non_svg_files
21
+
22
+ move_library
23
+
24
+ purge_temp_directory
25
+ rescue => error
26
+ say "[Rails Icons] Failed to sync icons: #{error.message}", :red
27
+
28
+ post_error_clean_up
29
+
30
+ raise
31
+ end
32
+
33
+ private
34
+
35
+ TEMP_DIRECTORY = Rails.root.join("tmp/rails_icons").freeze
36
+
37
+ def clone_repository
38
+ raise "[Rails Icons] Failed to clone repository" unless system("git clone '#{@library[:url]}' '#{@temp_directory}'")
39
+
40
+ say "[Rails Icons] '#{@name}' repository cloned successfully."
41
+ end
42
+
43
+ def process_variants = Sync::ProcessVariants.new(@temp_directory, @name, @library).process
44
+
45
+ def remove_non_svg_files
46
+ Pathname.glob("#{@temp_directory}/**/*")
47
+ .select { _1.file? && _1.extname != ".svg" }
48
+ .each(&:delete)
49
+
50
+ say "[Rails Icons] Non-SVG files removed successfully"
51
+ end
52
+
53
+ def move_library
54
+ destination = File.join(RailsIcons.configuration.destination_path, @name)
55
+
56
+ FileUtils.mkdir_p(destination)
57
+ FileUtils.mv(Dir.glob("#{@temp_directory}/*"), destination, force: true)
58
+
59
+ say "[Rails Icons] Synced '#{@name}' library successfully #{%w[😃 🎉 ✨].sample}", :green
60
+ end
61
+
62
+ def purge_temp_directory = FileUtils.rm_rf(TEMP_DIRECTORY)
63
+
64
+ def post_error_clean_up
65
+ if yes?("Do you want to remove the temp files? ('#{@temp_directory}') [y/n]")
66
+ say "[Rails Icons] Cleaning up…"
67
+
68
+ FileUtils.rm_rf(@temp_directory)
69
+ else
70
+ say "[Rails Icons] Keeping files at: '#{@temp_directory}'"
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "rails_icons/sync/transformations"
5
+
6
+ module RailsIcons
7
+ module Sync
8
+ class ProcessVariants < Rails::Generators::Base
9
+ def initialize(temp_directory, name, library)
10
+ @temp_directory, @name, @library = temp_directory, name, library
11
+ end
12
+
13
+ def process
14
+ original_variants = Dir.children(@temp_directory)
15
+ excluded_variants = RailsIcons.configuration.libraries.dig(@name.to_sym)&.exclude_variants || []
16
+
17
+ @library[:variants].each do |variant_name, variant_source_path|
18
+ next if excluded_variants.include?(variant_name)
19
+
20
+ source = File.join(@temp_directory, variant_source_path)
21
+ destination = File.join(@temp_directory, variant_name.to_s)
22
+
23
+ original_variants.delete(variant_name.to_s)
24
+
25
+ raise "[Rails Icons] Failed to find the icons directory: '#{source}'" unless Dir.exist?(source)
26
+
27
+ move_icons(source, destination)
28
+
29
+ apply_transformations_to(destination)
30
+ end
31
+
32
+ remove_files_and_folders_for(original_variants)
33
+ remove_previously_downloaded(excluded_variants)
34
+
35
+ say "[Rails Icons] Icon variants processed successfully"
36
+ end
37
+
38
+ private
39
+
40
+ def move_icons(source, destination)
41
+ FileUtils.mkdir_p(destination)
42
+
43
+ Dir.each_child(source).each do |item|
44
+ FileUtils.mv(File.join(source, item), destination)
45
+ end
46
+ end
47
+
48
+ def apply_transformations_to(destination)
49
+ Dir.each_child(destination) do |filename|
50
+ File.rename(
51
+ File.join(destination, filename),
52
+ File.join(destination, Sync::Transformations.transform(filename, transformations.fetch(:filenames, {})))
53
+ )
54
+ end
55
+ end
56
+
57
+ def remove_files_and_folders_for(paths)
58
+ paths.each do |path|
59
+ FileUtils.rm_rf(File.join(@temp_directory, path))
60
+ end
61
+ end
62
+
63
+ def remove_previously_downloaded(variants)
64
+ variants.each do |variant|
65
+ FileUtils.rm_rf(File.join(RailsIcons.configuration.destination_path, @name, variant.to_s))
66
+ end
67
+ end
68
+
69
+ def transformations
70
+ RailsIcons.libraries.dig(@name.to_sym)&.try(:transformations) || {}
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ module RailsIcons
2
+ module Sync
3
+ class Transformations < Rails::Generators::Base
4
+ def self.transform(filename, rules = {})
5
+ basename = File.basename(filename, File.extname(filename))
6
+
7
+ transformed = rules.reduce(basename) do |fn, (type, value)|
8
+ TRANSFORMERS.fetch(type).call(fn, value)
9
+ end
10
+
11
+ [transformed, File.extname(filename)].join
12
+ end
13
+
14
+ private
15
+
16
+ TRANSFORMERS = {
17
+ delete_prefix: ->(filename, prefixes) {
18
+ Array(prefixes).reduce(filename) { _1.delete_prefix(_2) }
19
+ },
20
+
21
+ delete_suffix: ->(filename, suffixes) {
22
+ Array(suffixes).reduce(filename) { _1.delete_suffix(_2) }
23
+ }
24
+ }
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsIcons
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/rails_icons.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rails_icons/version"
4
+ require_relative "rails_icons/libraries"
4
5
  require_relative "rails_icons/configuration"
5
6
  require_relative "rails_icons/engine"
6
7
  require_relative "rails_icons/errors"
7
8
  require_relative "rails_icons/railtie"
8
- require_relative "rails_icons/libraries"
9
9
  require_relative "rails_icons/icon"
10
10
 
11
11
  module RailsIcons
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.0.0
4
+ version: 1.2.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: 2024-12-07 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,23 +67,34 @@ files:
67
67
  - bin/setup
68
68
  - lib/generators/rails_icons/initializer_generator.rb
69
69
  - lib/generators/rails_icons/install_generator.rb
70
- - lib/generators/rails_icons/sync/engine.rb
71
70
  - lib/generators/rails_icons/sync_generator.rb
72
71
  - lib/generators/rails_icons/templates/initializer.rb.tt
73
72
  - lib/rails_icons.rb
73
+ - lib/rails_icons/base_generator.rb
74
74
  - lib/rails_icons/configuration.rb
75
75
  - lib/rails_icons/configuration/animated.rb
76
+ - lib/rails_icons/configuration/boxicons.rb
76
77
  - lib/rails_icons/configuration/feather.rb
78
+ - lib/rails_icons/configuration/flags.rb
77
79
  - lib/rails_icons/configuration/heroicons.rb
80
+ - lib/rails_icons/configuration/linear.rb
78
81
  - lib/rails_icons/configuration/lucide.rb
82
+ - lib/rails_icons/configuration/phosphor.rb
83
+ - lib/rails_icons/configuration/radix.rb
84
+ - lib/rails_icons/configuration/sidekickicons.rb
79
85
  - lib/rails_icons/configuration/tabler.rb
86
+ - lib/rails_icons/configuration/weather.rb
80
87
  - lib/rails_icons/engine.rb
81
88
  - lib/rails_icons/errors.rb
82
89
  - lib/rails_icons/helpers/icon_helper.rb
83
90
  - lib/rails_icons/icon.rb
84
91
  - lib/rails_icons/icon/attributes.rb
92
+ - lib/rails_icons/icon/file_path.rb
85
93
  - lib/rails_icons/libraries.rb
86
94
  - lib/rails_icons/railtie.rb
95
+ - lib/rails_icons/sync/engine.rb
96
+ - lib/rails_icons/sync/process_variants.rb
97
+ - lib/rails_icons/sync/transformations.rb
87
98
  - lib/rails_icons/version.rb
88
99
  - rails_icons.gemspec
89
100
  homepage: https://railsdesigner.com/rails-icons/
@@ -107,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
118
  - !ruby/object:Gem::Version
108
119
  version: '0'
109
120
  requirements: []
110
- rubygems_version: 3.5.23
121
+ rubygems_version: 3.3.7
111
122
  signing_key:
112
123
  specification_version: 4
113
124
  summary: Add any icon library to a Rails app
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
-
5
- module RailsIcons
6
- module Sync
7
- class Engine < Rails::Generators::Base
8
- def initialize(temp_icons_directory, library)
9
- super
10
-
11
- @temp_directory, @library = File.join(temp_icons_directory, library[:name]), library
12
- end
13
-
14
- def sync
15
- clone
16
- filter_variants_from_directory
17
- remove_non_svg_files
18
- rescue => error
19
- say "[Rails Icons] Failed to sync icons: #{error.message}", :red
20
-
21
- post_error_clean_up
22
-
23
- raise
24
- end
25
-
26
- private
27
-
28
- def clone
29
- raise "[Rails Icons] Failed to clone repository" unless system("git clone '#{@library[:url]}' '#{@temp_directory}'")
30
-
31
- say "#{@library[:name]} repository cloned successfully."
32
- end
33
-
34
- def filter_variants_from_directory
35
- original_set_list = Dir.children(@temp_directory)
36
-
37
- @library[:variants].each do |variant_name, variant_source_path|
38
- source = File.join(@temp_directory, variant_source_path)
39
- destination = File.join(@temp_directory, variant_name.to_s)
40
-
41
- # Whitelist variant directory if present in original_set_list to prevent deletion
42
- original_set_list.delete(variant_name.to_s)
43
-
44
- raise "[Rails Icons] Failed to find the icons directory: '#{source}'" unless Dir.exist?(source)
45
-
46
- move_icons(source, destination)
47
- end
48
-
49
- remove_files_and_folders(original_set_list)
50
-
51
- say "[Rails Icons] Icon variants filtered successfully"
52
- end
53
-
54
- def remove_non_svg_files
55
- Pathname.glob("#{@temp_directory}/**/*")
56
- .select { |p| p.file? && p.extname != ".svg" }
57
- .each(&:delete)
58
-
59
- say "[Rails Icons] Non-SVG files removed successfully"
60
- end
61
-
62
- def post_error_clean_up
63
- if yes?("Do you want to remove the temp files? ('#{@temp_directory}')")
64
- say "[Rails Icons] Cleaning up…"
65
-
66
- FileUtils.rm_rf(@temp_directory)
67
- else
68
- say "[Rails Icons] Keeping files at: '#{@temp_directory}'"
69
- end
70
- end
71
-
72
- def move_icons(source, destination)
73
- FileUtils.mkdir_p(destination)
74
-
75
- Dir.children(source).each do |item|
76
- FileUtils.mv(File.join(source, item), destination)
77
- end
78
- end
79
-
80
- def remove_files_and_folders(paths)
81
- paths.each do |path|
82
- FileUtils.rm_rf(File.join(@temp_directory, path))
83
- end
84
- end
85
- end
86
- end
87
- end