diff --git a/lib/generators/rails_icons/initializer_generator.rb b/lib/generators/rails_icons/initializer_generator.rb index 9318041..cb33059 100644 --- a/lib/generators/rails_icons/initializer_generator.rb +++ b/lib/generators/rails_icons/initializer_generator.rb @@ -4,8 +4,10 @@ module RailsIcons class InitializerGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) + desc "Create the Rails Icons initializer." + class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})" - class_option :destination, type: :string, default: "app/assets/svg/icons/", desc: "Specify destination folder for icons" + class_option :destination, type: :string, default: RailsIcons.configuration.destination_path, desc: "Specify destination folder for icons" class_option :custom, type: :string, desc: "Name of the custom library" def copy_initializer @@ -28,6 +30,16 @@ def insert_default_configuration end end + def insert_custom_destination_path + return if options[:destination] && options[:destination] == RailsIcons.configuration.destination_path + + insert_into_file INITIALIZER, <<~RB.indent(2), after: "RailsIcons.configure do |config|\n" + # Default destination path + config.destination_path = "#{options[:destination]}" + + RB + end + def insert_libraries_configuration insert_into_file INITIALIZER, "\n#{library_configuration}", before: "end" end diff --git a/lib/generators/rails_icons/install_generator.rb b/lib/generators/rails_icons/install_generator.rb index 80aa229..bc0d64c 100644 --- a/lib/generators/rails_icons/install_generator.rb +++ b/lib/generators/rails_icons/install_generator.rb @@ -4,8 +4,10 @@ module RailsIcons class InstallGenerator < Rails::Generators::Base source_root File.expand_path("templates", __dir__) + desc "Install Rails Icons with the choosen libraries. This creates the configuration initializer and will sync the icons." + class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})" - class_option :destination, type: :string, default: "app/assets/svg/icons/", desc: "Specify destination folder for icons" + class_option :destination, type: :string, default: RailsIcons.configuration.destination_path, desc: "Specify destination folder for icons" class_option :skip_sync, type: :boolean, default: false def initializer_generator diff --git a/lib/generators/rails_icons/sync_generator.rb b/lib/generators/rails_icons/sync_generator.rb index 3a26f26..c3d328d 100644 --- a/lib/generators/rails_icons/sync_generator.rb +++ b/lib/generators/rails_icons/sync_generator.rb @@ -4,12 +4,12 @@ module RailsIcons class SyncGenerator < Rails::Generators::Base - class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})" - class_option :destination, type: :string, default: "app/assets/svg/icons/", desc: "Specify destination folder for icons" - - desc "Sync an icon library(s) from their respective git repos." source_root File.expand_path("templates", __dir__) + desc "Sync the choosen icon libraries from their respective git repos." + + class_option :libraries, type: :array, default: [], desc: "Choose libraries (#{RailsIcons.libraries.keys.join("/")})" + def sync_icons raise "[Rails Icons] Not a valid library" if options[:libraries].empty? diff --git a/lib/rails_icons/configuration.rb b/lib/rails_icons/configuration.rb index bc443a6..b2fce6b 100644 --- a/lib/rails_icons/configuration.rb +++ b/lib/rails_icons/configuration.rb @@ -40,6 +40,7 @@ def respond_to_missing?(method_name) def set_default_config @config.default_library = nil + @config.destination_path = "app/assets/svg/icons" end def set_libraries_config diff --git a/lib/rails_icons/icon.rb b/lib/rails_icons/icon.rb index f65b61d..0a0c4f1 100644 --- a/lib/rails_icons/icon.rb +++ b/lib/rails_icons/icon.rb @@ -40,10 +40,7 @@ def file_path return Rails.root.join(custom_library.dig(:path), "#{@name}.svg") if custom_library? parts = [ - "app", - "assets", - "svg", - "icons", + RailsIcons.configuration.destination_path, @library, @variant, "#{@name}.svg" @@ -79,7 +76,7 @@ def custom_library &.dig("custom") &.dig(@library.to_sym)&.with_defaults( { - path: "app/assets/svg/icons/#{@library}" + path: [RailsIcons.configuration.destination_path, @library].join("/") } ) || {} end diff --git a/lib/rails_icons/sync/engine.rb b/lib/rails_icons/sync/engine.rb index 986959d..6331705 100644 --- a/lib/rails_icons/sync/engine.rb +++ b/lib/rails_icons/sync/engine.rb @@ -51,7 +51,7 @@ def remove_non_svg_files end def move_library - destination = File.join("app/assets/svg/icons/", @name) + destination = File.join(RailsIcons.configuration.destination_path, @name) FileUtils.mkdir_p(destination) FileUtils.mv(Dir.glob("#{@temp_directory}/*"), destination, force: true)