anyicon 1.0.3 → 1.1.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: 3f72fd662c558d005d5707b0d42bff57d58bab8642b220a1997486c45f32553c
4
- data.tar.gz: f3a4bf9cc2d295817735260d97b716356b4d46c269cd8eaac67f867a70a39a77
3
+ metadata.gz: ce30dcf29ae639c318492c5e089b62abb4889d45be351e3b24b34c6bd8573929
4
+ data.tar.gz: 988ee32f96527a7acd237df49eaf7225752fa7786880f8dcf8f344ee97d950c1
5
5
  SHA512:
6
- metadata.gz: e32588d33dd2178c2ebbf91306c1a72ecce49af1c4b9c7f32410fbabfe70aca1f237bda6e1a7e16f92bde8c2112ffb754fe2a6529402d5d2880aea1912cb357d
7
- data.tar.gz: ce2ae69a8c52fe073b155f12e85f1fcfb73913ceab1ad977e9f74b4c6b1e7ab22994b2dfff56729c97a71ba53060c93432482768abe02e9eede8e52f346ae0e6
6
+ metadata.gz: e17a8a1d3490f16c31445362d62f0c5b7d9a7149e1b4b5d950907fd1fed6ddab0cb02fc208b25a4881b8be9e025637e39a13cd00cdf7f0134f7ca49621da65c2
7
+ data.tar.gz: 7734031fe6f47af1d7060dbcd8108f1c621e62a779080cb866976d185fc3282e1cb4aaf31639f65b695aaa669d98054de68b1c0fe12ef4eb8c87a121b1706386
data/README.md CHANGED
@@ -47,6 +47,11 @@ You can just use the anyicon helper in your views:
47
47
  ```erb
48
48
  <%= anyicon icon: 'fontawesome_regular:address-book' %>
49
49
  ```
50
+ or
51
+
52
+ ```erb
53
+ <%= anyicon 'fontawesome_regular:address-book' %>
54
+ ```
50
55
 
51
56
  ## Configuration
52
57
 
@@ -8,8 +8,8 @@ module Anyicon
8
8
  # @param icon [String] the name of the icon in the format 'collection:icon_name'
9
9
  # @param props [Hash] additional properties to apply to the SVG element
10
10
  # @return [String] the rendered SVG icon
11
- def anyicon(icon:, **props)
12
- Anyicon::Icon.render(icon:, **props)
11
+ def anyicon(icon = nil, **props)
12
+ Anyicon::Icon.render(icon = icon, **props)
13
13
  end
14
14
  end
15
15
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
- require 'json'
5
- require 'fileutils'
3
+ require "net/http"
4
+ require "json"
5
+ require "fileutils"
6
6
 
7
7
  module Anyicon
8
8
  # The Collection class is responsible for managing icon collections
@@ -31,7 +31,7 @@ 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.
@@ -39,7 +39,7 @@ module Anyicon
39
39
  # @return [void]
40
40
  def download_all
41
41
  if list.empty?
42
- puts 'No icons available.'
42
+ puts "No icons available."
43
43
  return
44
44
  end
45
45
 
@@ -65,12 +65,12 @@ module Anyicon
65
65
  # @param icon [Hash] the metadata of the icon to download
66
66
  # @return [void]
67
67
  def download(icon)
68
- return if icon['download_url'].nil?
69
- return if File.exist?(icon_path(icon['name']))
68
+ return if icon["download_url"].nil?
69
+ return if File.exist?(icon_path(icon["name"]))
70
70
 
71
- FileUtils.mkdir_p(icon_path(icon['name']).dirname)
72
- response = fetch(icon['download_url'])
73
- File.write(icon_path(icon['name']), response.body)
71
+ FileUtils.mkdir_p(icon_path(icon["name"]).dirname)
72
+ response = fetch(icon["download_url"])
73
+ File.write(icon_path(icon["name"]), response.body)
74
74
  rescue ActionView::Template::Error, Net::HTTPError, Net::HTTPClientException => e
75
75
  ::Rails.logger.error "AnyIcon: Failed to download icon: #{e.message}"
76
76
  end
@@ -80,7 +80,7 @@ module Anyicon
80
80
  # @param icon_name [String] the name of the icon
81
81
  # @return [Pathname] the path to the icon file
82
82
  def icon_path(icon_name)
83
- ::Rails.root.join('app', 'assets', 'images', 'icons', @collection.to_s, icon_name)
83
+ ::Rails.root.join("app", "assets", "images", "icons", @collection.to_s, icon_name)
84
84
  end
85
85
 
86
86
  # Constructs the URL to fetch the icon collection directory contents from the repository.
@@ -90,11 +90,11 @@ module Anyicon
90
90
  return nil unless collections.keys.include?(@collection)
91
91
 
92
92
  [
93
- 'https://api.github.com/repos/',
93
+ "https://api.github.com/repos/",
94
94
  collections[@collection][:repo],
95
- '/contents/',
95
+ "/contents/",
96
96
  collections[@collection][:path]
97
- ].join('')
97
+ ].join("")
98
98
  end
99
99
  end
100
100
  end
@@ -19,7 +19,7 @@ module Anyicon
19
19
  # @return [Net::HTTPResponse] the HTTP response
20
20
  # @raise [Net::HTTPError] if the number of redirects exceeds the limit or another HTTP error occurs
21
21
  def fetch(url, limit = 10)
22
- raise Net::HTTPError, 'Too many HTTP redirects' if limit.zero?
22
+ raise Net::HTTPError, "Too many HTTP redirects" if limit.zero?
23
23
  return nil if url.nil?
24
24
 
25
25
  uri = URI.parse(URI::DEFAULT_PARSER.escape(url))
@@ -27,7 +27,7 @@ module Anyicon
27
27
 
28
28
  case response
29
29
  when Net::HTTPSuccess then response
30
- when Net::HTTPRedirection then fetch(response['location'], limit - 1)
30
+ when Net::HTTPRedirection then fetch(response["location"], limit - 1)
31
31
  else
32
32
  response.error!
33
33
  end
@@ -22,21 +22,21 @@ 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: '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
- heroicons_outline: { repo: 'tailwindlabs/heroicons', path: 'optimized/24/outline', branch: 'master' },
29
- heroicons_solid: { repo: 'tailwindlabs/heroicons', path: 'optimized/24/solid', branch: 'master' },
30
- tabler_icons_filled: { repo: 'tabler/tabler-icons', path: 'icons/filled', branch: 'main' },
31
- tabler_icons_outline: { repo: 'tabler/tabler-icons', path: 'icons/outline', branch: 'main' },
32
- mage_icons_fill: { repo: 'Mage-Icons/mage-icons', path: 'svg/bulk', branch: 'main' },
33
- mage_icons_stroke: { repo: 'Mage-Icons/mage-icons', path: 'svg/stroke', branch: 'main' },
34
- mage_icons_social_bw: { repo: 'Mage-Icons/mage-icons', path: 'svg/social-bw', branch: 'main' },
35
- mage_icons_social_color: { repo: 'Mage-Icons/mage-icons', path: 'svg/social-color', branch: 'main' },
36
- line_awesome: { repo: 'icons8/line-awesome', path: 'svg', branch: 'master' },
37
- carbon: { repo: 'carbon-design-system/carbon', path: 'packages/icons/src/svg/32', branch: 'main' },
38
- ionicons: { repo: 'ionic-team/ionicons', path: 'src/svg', branch: 'main' },
39
- feather_icons: { repo: 'feathericons/feather', path: 'icons', branch: 'main' }
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
+ heroicons_outline: { repo: "tailwindlabs/heroicons", path: "optimized/24/outline", branch: "master" },
29
+ heroicons_solid: { repo: "tailwindlabs/heroicons", path: "optimized/24/solid", branch: "master" },
30
+ tabler_icons_filled: { repo: "tabler/tabler-icons", path: "icons/filled", branch: "main" },
31
+ tabler_icons_outline: { repo: "tabler/tabler-icons", path: "icons/outline", branch: "main" },
32
+ mage_icons_fill: { repo: "Mage-Icons/mage-icons", path: "svg/bulk", branch: "main" },
33
+ mage_icons_stroke: { repo: "Mage-Icons/mage-icons", path: "svg/stroke", branch: "main" },
34
+ mage_icons_social_bw: { repo: "Mage-Icons/mage-icons", path: "svg/social-bw", branch: "main" },
35
+ mage_icons_social_color: { repo: "Mage-Icons/mage-icons", path: "svg/social-color", branch: "main" },
36
+ line_awesome: { repo: "icons8/line-awesome", path: "svg", branch: "master" },
37
+ carbon: { repo: "carbon-design-system/carbon", path: "packages/icons/src/svg/32", branch: "main" },
38
+ ionicons: { repo: "ionic-team/ionicons", path: "src/svg", branch: "main" },
39
+ feather_icons: { repo: "feathericons/feather", path: "icons", branch: "main" }
40
40
  }.freeze
41
41
 
42
42
  # @return [Hash] the configured icon collections
data/lib/anyicon/icon.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
- require 'nokogiri'
5
- require 'fileutils'
3
+ require "net/http"
4
+ require "nokogiri"
5
+ require "fileutils"
6
6
 
7
7
  module Anyicon
8
8
  # The Icon class is responsible for managing the rendering of icons from various
@@ -21,9 +21,10 @@ module Anyicon
21
21
  #
22
22
  # @param icon [String] a comma-separated string of icon names, each in the format 'collection:name'
23
23
  # @param props [Hash] additional properties to apply to the SVG element
24
- def initialize(icon:, **props)
24
+ def initialize(icon = nil, **props)
25
+ # binding.pry
25
26
  super()
26
- @icons = icon.to_s.split(',').map { |i| i.split(':') }
27
+ @icons = (icon || props[:icon]).to_s.split(",").map { |i| i.split(":") }
27
28
  @props = props
28
29
  end
29
30
 
@@ -31,7 +32,7 @@ module Anyicon
31
32
  #
32
33
  # @return [String] the HTML-safe SVG content
33
34
  def render
34
- result = ''.html_safe
35
+ result = "".html_safe
35
36
  @icons.each do |icon|
36
37
  ensure_icon_exists(icon)
37
38
  result.concat(svg_content(icon).html_safe)
@@ -76,7 +77,7 @@ module Anyicon
76
77
  # @param icon [Array] the collection and name of the icon
77
78
  # @return [Pathname] the path to the icon file
78
79
  def icon_path(icon)
79
- ::Rails.root.join('app', 'assets', 'images', 'icons', icon[0], "#{icon[1]}.svg")
80
+ ::Rails.root.join("app", "assets", "images", "icons", icon[0], "#{icon[1]}.svg")
80
81
  end
81
82
 
82
83
  # Constructs the URL to download the specified icon.
@@ -86,8 +87,8 @@ module Anyicon
86
87
  def icon_url(icon)
87
88
  return nil unless collections.keys.include?(icon[0].to_sym)
88
89
 
89
- ['https://github.com/', collections[icon[0].to_sym][:repo], '/raw/', collections[icon[0].to_sym][:branch], '/',
90
- collections[icon[0].to_sym][:path], '/', icon[1], '.svg'].join('')
90
+ [ "https://github.com/", collections[icon[0].to_sym][:repo], "/raw/", collections[icon[0].to_sym][:branch], "/",
91
+ collections[icon[0].to_sym][:path], "/", icon[1], ".svg" ].join("")
91
92
  end
92
93
 
93
94
  # Reads and customizes the SVG content for the specified icon.
@@ -95,11 +96,11 @@ module Anyicon
95
96
  # @param icon [Array] the collection and name of the icon
96
97
  # @return [String] the customized SVG content
97
98
  def svg_content(icon)
98
- return '' unless File.file?(icon_path(icon))
99
+ return "" unless File.file?(icon_path(icon))
99
100
 
100
101
  svg_content = File.read(icon_path(icon))
101
102
  doc = Nokogiri::HTML::DocumentFragment.parse(svg_content)
102
- svg = doc.at_css 'svg'
103
+ svg = doc.at_css "svg"
103
104
 
104
105
  @props.each do |key, value|
105
106
  value = "#{value} #{icon[-2..].join(' ')}" if key == :class && icon.count > 2
@@ -115,8 +116,8 @@ module Anyicon
115
116
  #
116
117
  # @param kwargs [Hash] the parameters for initializing an Icon instance
117
118
  # @return [String] the HTML-safe SVG content
118
- def render(**kwargs)
119
- new(**kwargs).render
119
+ def render(*args, **kwargs)
120
+ new(*args, **kwargs).render
120
121
  end
121
122
  end
122
123
  end
@@ -1,3 +1,3 @@
1
1
  module Anyicon
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/anyicon.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails'
4
- require 'anyicon/engine'
5
- require 'anyicon/common'
6
- require 'anyicon/collections'
7
- require 'anyicon/icon'
8
- require 'anyicon/configuration'
3
+ require "rails"
4
+ require "anyicon/engine"
5
+ require "anyicon/common"
6
+ require "anyicon/collections"
7
+ require "anyicon/icon"
8
+ require "anyicon/configuration"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
3
+ require "rails/generators"
4
4
 
5
5
  module Anyicon
6
6
  module Generators
@@ -17,14 +17,14 @@ module Anyicon
17
17
  # This will copy the `anyicon.rb` template to `config/initializers/anyicon.rb` in your
18
18
  # Rails application.
19
19
  class InstallGenerator < ::Rails::Generators::Base
20
- source_root File.join(__dir__, 'templates')
21
- desc 'This generator installs AnyIcon'
20
+ source_root File.join(__dir__, "templates")
21
+ desc "This generator installs AnyIcon"
22
22
 
23
23
  # Copies the anyicon configuration template to the initializers directory.
24
24
  #
25
25
  # @return [void]
26
26
  def copy_config
27
- template 'anyicon.rb', 'config/initializers/anyicon.rb'
27
+ template "anyicon.rb", "config/initializers/anyicon.rb"
28
28
  end
29
29
  end
30
30
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :anyicon do
4
- desc 'Download a specific icon collection'
5
- task :download_collection, [:collection] => :environment do |_t, args|
4
+ desc "Download a specific icon collection"
5
+ task :download_collection, [ :collection ] => :environment do |_t, args|
6
6
  collection = args[:collection]
7
7
  if Anyicon.configuration.collections.keys.include?(collection.to_sym)
8
8
  Anyicon::Collection.new(collection.to_sym).download_all
@@ -11,9 +11,9 @@ namespace :anyicon do
11
11
  end
12
12
  end
13
13
 
14
- desc 'Download all icon collections'
14
+ desc "Download all icon collections"
15
15
  task download_all_collections: :environment do
16
- puts 'Downloading all icon collections'
16
+ puts "Downloading all icon collections"
17
17
  Anyicon.configuration.collections.each_key do |collection|
18
18
  puts "Downloading #{collection}..."
19
19
  Anyicon::Collection.new(collection).download_all
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.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-03 00:00:00.000000000 Z
11
+ date: 2025-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails