anyicon 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6118b411159d81352c3d1ce3863139a440605e291705b4e14772051fa485bbea
4
- data.tar.gz: 9038d868f28f9d2b8a6fb4bfb9367ae39cf32976f9a80d6df6393941d127771e
3
+ metadata.gz: e768dfe35064ef90d05f9cbf8df01bc1d89c6ad8cf1a3bf165c8f355c6049198
4
+ data.tar.gz: 23056f37dd001e4b12095bc8e04a59dfaa658629f7a1582055af71b68b216a94
5
5
  SHA512:
6
- metadata.gz: 5848ddafbc9ef74ffc63946623a26e729ad422a8b435cbf76195c7d7c2990724bd6f76ffb95c8d74192c441d9698d1f01257b7317f76a2229402d5fa64692eec
7
- data.tar.gz: 99c2beacea172b885659313fabf104410bc35b72dcd9efd226265cea549d914e44308d7d9f07dd5b5cd0b777931dbafbee7b3f06e1f2eb5bf83b68bce632a518
6
+ metadata.gz: 1bbfba2b8bbb63280abb4c9ac60104d20f00be8d8493a89f7be82aa1a5de484e8870eecd65247f0098c8ae3f33cb99608942abbd2f8cf0ca54c6566a0f979b1f
7
+ data.tar.gz: ca08c198d7db376bb3a8a163103cbe75ab460c6cde6781a15d18d4ec1dcded64ca86f6aa127be65047b030bf91531679ab6788f94df7cc7bf69266fd9b7a6448
@@ -31,13 +31,18 @@ module Anyicon
31
31
  # @return [Array<Hash>] a list of icons with their metadata
32
32
  def list
33
33
  response = fetch(collection_url)
34
- JSON.parse(response.body)
34
+ JSON.parse(response&.body || '{}')
35
35
  end
36
36
 
37
37
  # Downloads all icons in the collection and saves them to the local file system.
38
38
  #
39
39
  # @return [void]
40
40
  def download_all
41
+ if list.empty?
42
+ puts 'No icons available.'
43
+ return
44
+ end
45
+
41
46
  count = 0
42
47
  list.each do |icon|
43
48
  count += 1
@@ -50,7 +55,7 @@ module Anyicon
50
55
  #
51
56
  # @return [Hash] the configured collections
52
57
  def collections
53
- @collections ||= Anyicon::Configuration.new.collections
58
+ @collections ||= Anyicon.configuration.collections
54
59
  end
55
60
 
56
61
  private
@@ -66,7 +71,7 @@ module Anyicon
66
71
  FileUtils.mkdir_p(icon_path(icon['name']).dirname)
67
72
  response = fetch(icon['download_url'])
68
73
  File.write(icon_path(icon['name']), response.body)
69
- rescue ActionView::Template::Error, ::OpenURI::HTTPError => e
74
+ rescue ActionView::Template::Error, Net::HTTPError, Net::HTTPClientException => e
70
75
  ::Rails.logger.error "AnyIcon: Failed to download icon: #{e.message}"
71
76
  end
72
77
 
@@ -7,13 +7,13 @@ module Anyicon
7
7
  # Example usage:
8
8
  #
9
9
  # Anyicon.configure do |config|
10
- # config.collections = {
10
+ # config.add_collections(
11
11
  # custom_collection: {
12
12
  # repo: 'user/repo',
13
13
  # path: 'path/to/icons',
14
14
  # branch: 'main'
15
15
  # }
16
- # }
16
+ # )
17
17
  # end
18
18
  #
19
19
  # The class also allows setting additional configuration options such as
@@ -22,9 +22,9 @@ module Anyicon
22
22
  # A hash containing the default icon collections. Each collection specifies the
23
23
  # repository, path, and branch where the icons can be found.
24
24
  DEFAULT_COLLECTIONS = {
25
- fontawesome_regular: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/regular', branch: 'master' },
26
- fontawesome_solid: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/solid', branch: 'master' },
27
- fontawesome_brands: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/brands', branch: 'master' },
25
+ fontawesome_regular: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/regular', branch: '6.x' },
26
+ fontawesome_solid: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/solid', branch: '6.x' },
27
+ fontawesome_brands: { repo: 'FortAwesome/Font-Awesome', path: 'svgs/brands', branch: '6.x' },
28
28
  heroicons_outline: { repo: 'tailwindlabs/heroicons', path: 'optimized/24/outline', branch: 'master' },
29
29
  heroicons_solid: { repo: 'tailwindlabs/heroicons', path: 'optimized/24/solid', branch: 'master' },
30
30
  tabler_icons_filled: { repo: 'tabler/tabler-icons', path: 'icons/filled', branch: 'main' },
@@ -44,7 +44,11 @@ module Anyicon
44
44
 
45
45
  # Initializes a new Configuration instance with default settings.
46
46
  def initialize
47
- @collections = DEFAULT_COLLECTIONS
47
+ @collections = DEFAULT_COLLECTIONS.dup
48
+ end
49
+
50
+ def add_collections(new_collections)
51
+ @collections.merge!(new_collections)
48
52
  end
49
53
  end
50
54
 
@@ -55,13 +59,6 @@ module Anyicon
55
59
  @configuration ||= Configuration.new
56
60
  end
57
61
 
58
- # Sets the configuration instance.
59
- #
60
- # @param config [Anyicon::Configuration] the configuration instance to set
61
- def self.configuration=(config)
62
- @configuration = config
63
- end
64
-
65
62
  # Yields the configuration instance to a block for customization.
66
63
  #
67
64
  # @yieldparam [Anyicon::Configuration] config the configuration instance
data/lib/anyicon/icon.rb CHANGED
@@ -67,8 +67,8 @@ module Anyicon
67
67
  FileUtils.mkdir_p(icon_path(icon).dirname)
68
68
  response = fetch(url)
69
69
  File.write(icon_path(icon), response.body) if response.is_a?(Net::HTTPSuccess)
70
- rescue ActionView::Template::Error, Net::HTTPError => e
71
- ::Rails.logger.error "AnyIcon: Failed to download icon: #{e.message}"
70
+ rescue ActionView::Template::Error, Net::HTTPError, Net::HTTPClientException => e
71
+ ::Rails.logger.error "AnyIcon: Failed to download icon: #{e.message} (#{url})"
72
72
  end
73
73
 
74
74
  # Returns the local file path for the specified icon.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyicon
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rails/generators'
3
4
 
4
5
  module Anyicon
@@ -17,7 +18,7 @@ module Anyicon
17
18
  # Rails application.
18
19
  class InstallGenerator < ::Rails::Generators::Base
19
20
  source_root File.join(__dir__, 'templates')
20
- desc "This generator installs AnyIcon"
21
+ desc 'This generator installs AnyIcon'
21
22
 
22
23
  # Copies the anyicon configuration template to the initializers directory.
23
24
  #
@@ -7,27 +7,12 @@ Anyicon.configure do |config|
7
7
  #
8
8
  # Example:
9
9
  #
10
- # config.collections = {
10
+ # config.add_collections(
11
11
  # custom_collection: {
12
12
  # repo: 'user/repo',
13
13
  # path: 'path/to/icons',
14
14
  # branch: 'main'
15
15
  # }
16
- # }
16
+ # )
17
17
  #
18
-
19
- config.collections = {
20
- # Add your icon collections here
21
- # Example:
22
- # fontawesome_regular: {
23
- # repo: 'FortAwesome/Font-Awesome',
24
- # path: 'svgs/regular',
25
- # branch: 'master'
26
- # },
27
- # heroicons_solid: {
28
- # repo: 'tailwindlabs/heroicons',
29
- # path: 'optimized/24/solid',
30
- # branch: 'master'
31
- # }
32
- }
33
18
  end
@@ -4,8 +4,7 @@ namespace :anyicon do
4
4
  desc 'Download a specific icon collection'
5
5
  task :download_collection, [:collection] => :environment do |_t, args|
6
6
  collection = args[:collection]
7
- #binding.pry
8
- if Anyicon::Configuration.new.collections.keys.include?(collection.to_sym)
7
+ if Anyicon.configuration.collections.keys.include?(collection.to_sym)
9
8
  Anyicon::Collection.new(collection.to_sym).download_all
10
9
  else
11
10
  puts "Collection #{collection} not found."
@@ -15,7 +14,7 @@ namespace :anyicon do
15
14
  desc 'Download all icon collections'
16
15
  task download_all_collections: :environment do
17
16
  puts 'Downloading all icon collections'
18
- Anyicon::Configuration.new.collections.each_key do |collection|
17
+ Anyicon.configuration.collections.each_key do |collection|
19
18
  puts "Downloading #{collection}..."
20
19
  Anyicon::Collection.new(collection).download_all
21
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-28 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails