rails_icons 0.1.0 → 0.3.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: b9fa03b4c4eba2685fe4aec786f3c242f63b7b31768a5aa57787b0d8d6df62a3
4
- data.tar.gz: 40ed83028f4f8e0f34e9236c89fa0b99141bef97d5d52289b3977d9589a40f50
3
+ metadata.gz: 6c3ee60bafe9a9cffae818c8304e8a69abf56d8de147ff607db5d775137ab5ea
4
+ data.tar.gz: afacf89281c87e029a0866860ef6edf1a738e06d5918b5254524c2bbe803bbd3
5
5
  SHA512:
6
- metadata.gz: fe86f0d2d97bc7df912b7f0c7d74999550f3a83c217739c7ae3476b9cacaed44659d05c19a2e2b3bf950f1cc0fef1e95bfa5b30a8debe56619e4c1a787de19e4
7
- data.tar.gz: 170d73d5eec70f42b1eab1367d6f6faa145f6e5f5a8c645c875be939dd90efa0639b50936adfcc5f675f34d232eddb83804496f208522410c5fdc26eec4d5b8c
6
+ metadata.gz: f1f4ed187c437220dc0b081dbddb95f1204f65a30dca2b89c4b72aba7574888d5adee9766a69821ecb26d2f9e9adff2e78d8b585ec7f639dd8d9754b0cb9296f
7
+ data.tar.gz: e195bd6ade61e3018a478852d293c8437d0c0490c5d8727d774098c98a10189b4be7d982f73ebb191ce5486a947f46c424265f46fe79fec3fe03ae3e45be543a
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rails_icons.gemspec
6
+ gemspec
7
+
8
+ gem "rails", "~> 7.0.6"
9
+ gem "propshaft"
10
+
11
+ group :development do
12
+ gem "standard"
13
+ end
14
+
15
+ group :development, :test do
16
+ gem "minitest"
17
+ gem "debug", "~> 1.9", ">= 1.9.2"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,228 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_icons (0.3.0)
5
+ nokogiri (~> 1.16, >= 1.16.4)
6
+ rails (> 6.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.8.1)
12
+ actionpack (= 7.0.8.1)
13
+ activesupport (= 7.0.8.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.8.1)
17
+ actionpack (= 7.0.8.1)
18
+ activejob (= 7.0.8.1)
19
+ activerecord (= 7.0.8.1)
20
+ activestorage (= 7.0.8.1)
21
+ activesupport (= 7.0.8.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.8.1)
27
+ actionpack (= 7.0.8.1)
28
+ actionview (= 7.0.8.1)
29
+ activejob (= 7.0.8.1)
30
+ activesupport (= 7.0.8.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.8.1)
37
+ actionview (= 7.0.8.1)
38
+ activesupport (= 7.0.8.1)
39
+ rack (~> 2.0, >= 2.2.4)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.8.1)
44
+ actionpack (= 7.0.8.1)
45
+ activerecord (= 7.0.8.1)
46
+ activestorage (= 7.0.8.1)
47
+ activesupport (= 7.0.8.1)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.8.1)
51
+ activesupport (= 7.0.8.1)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.8.1)
57
+ activesupport (= 7.0.8.1)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.8.1)
60
+ activesupport (= 7.0.8.1)
61
+ activerecord (7.0.8.1)
62
+ activemodel (= 7.0.8.1)
63
+ activesupport (= 7.0.8.1)
64
+ activestorage (7.0.8.1)
65
+ actionpack (= 7.0.8.1)
66
+ activejob (= 7.0.8.1)
67
+ activerecord (= 7.0.8.1)
68
+ activesupport (= 7.0.8.1)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.8.1)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ ast (2.4.2)
77
+ builder (3.2.4)
78
+ concurrent-ruby (1.2.3)
79
+ crass (1.0.6)
80
+ date (3.3.4)
81
+ debug (1.9.2)
82
+ irb (~> 1.10)
83
+ reline (>= 0.3.8)
84
+ erubi (1.12.0)
85
+ globalid (1.2.1)
86
+ activesupport (>= 6.1)
87
+ i18n (1.14.4)
88
+ concurrent-ruby (~> 1.0)
89
+ io-console (0.7.2)
90
+ irb (1.12.0)
91
+ rdoc
92
+ reline (>= 0.4.2)
93
+ json (2.7.1)
94
+ language_server-protocol (3.17.0.3)
95
+ lint_roller (1.1.0)
96
+ loofah (2.22.0)
97
+ crass (~> 1.0.2)
98
+ nokogiri (>= 1.12.0)
99
+ mail (2.8.1)
100
+ mini_mime (>= 0.1.1)
101
+ net-imap
102
+ net-pop
103
+ net-smtp
104
+ marcel (1.0.4)
105
+ method_source (1.0.0)
106
+ mini_mime (1.1.5)
107
+ mini_portile2 (2.8.5)
108
+ minitest (5.22.3)
109
+ net-imap (0.4.10)
110
+ date
111
+ net-protocol
112
+ net-pop (0.1.2)
113
+ net-protocol
114
+ net-protocol (0.2.2)
115
+ timeout
116
+ net-smtp (0.5.0)
117
+ net-protocol
118
+ nio4r (2.7.1)
119
+ nokogiri (1.16.4)
120
+ mini_portile2 (~> 2.8.2)
121
+ racc (~> 1.4)
122
+ nokogiri (1.16.4-arm64-darwin)
123
+ racc (~> 1.4)
124
+ parallel (1.24.0)
125
+ parser (3.3.0.5)
126
+ ast (~> 2.4.1)
127
+ racc
128
+ propshaft (0.8.0)
129
+ actionpack (>= 7.0.0)
130
+ activesupport (>= 7.0.0)
131
+ rack
132
+ railties (>= 7.0.0)
133
+ psych (5.1.2)
134
+ stringio
135
+ racc (1.7.3)
136
+ rack (2.2.9)
137
+ rack-test (2.1.0)
138
+ rack (>= 1.3)
139
+ rails (7.0.8.1)
140
+ actioncable (= 7.0.8.1)
141
+ actionmailbox (= 7.0.8.1)
142
+ actionmailer (= 7.0.8.1)
143
+ actionpack (= 7.0.8.1)
144
+ actiontext (= 7.0.8.1)
145
+ actionview (= 7.0.8.1)
146
+ activejob (= 7.0.8.1)
147
+ activemodel (= 7.0.8.1)
148
+ activerecord (= 7.0.8.1)
149
+ activestorage (= 7.0.8.1)
150
+ activesupport (= 7.0.8.1)
151
+ bundler (>= 1.15.0)
152
+ railties (= 7.0.8.1)
153
+ rails-dom-testing (2.2.0)
154
+ activesupport (>= 5.0.0)
155
+ minitest
156
+ nokogiri (>= 1.6)
157
+ rails-html-sanitizer (1.6.0)
158
+ loofah (~> 2.21)
159
+ nokogiri (~> 1.14)
160
+ railties (7.0.8.1)
161
+ actionpack (= 7.0.8.1)
162
+ activesupport (= 7.0.8.1)
163
+ method_source
164
+ rake (>= 12.2)
165
+ thor (~> 1.0)
166
+ zeitwerk (~> 2.5)
167
+ rainbow (3.1.1)
168
+ rake (13.2.1)
169
+ rdoc (6.6.3.1)
170
+ psych (>= 4.0.0)
171
+ regexp_parser (2.9.0)
172
+ reline (0.5.0)
173
+ io-console (~> 0.5)
174
+ rexml (3.2.6)
175
+ rubocop (1.62.1)
176
+ json (~> 2.3)
177
+ language_server-protocol (>= 3.17.0)
178
+ parallel (~> 1.10)
179
+ parser (>= 3.3.0.2)
180
+ rainbow (>= 2.2.2, < 4.0)
181
+ regexp_parser (>= 1.8, < 3.0)
182
+ rexml (>= 3.2.5, < 4.0)
183
+ rubocop-ast (>= 1.31.1, < 2.0)
184
+ ruby-progressbar (~> 1.7)
185
+ unicode-display_width (>= 2.4.0, < 3.0)
186
+ rubocop-ast (1.31.2)
187
+ parser (>= 3.3.0.4)
188
+ rubocop-performance (1.20.2)
189
+ rubocop (>= 1.48.1, < 2.0)
190
+ rubocop-ast (>= 1.30.0, < 2.0)
191
+ ruby-progressbar (1.13.0)
192
+ standard (1.35.1)
193
+ language_server-protocol (~> 3.17.0.2)
194
+ lint_roller (~> 1.0)
195
+ rubocop (~> 1.62.0)
196
+ standard-custom (~> 1.0.0)
197
+ standard-performance (~> 1.3)
198
+ standard-custom (1.0.2)
199
+ lint_roller (~> 1.0)
200
+ rubocop (~> 1.50)
201
+ standard-performance (1.3.1)
202
+ lint_roller (~> 1.1)
203
+ rubocop-performance (~> 1.20.2)
204
+ stringio (3.1.0)
205
+ thor (1.3.1)
206
+ timeout (0.4.1)
207
+ tzinfo (2.0.6)
208
+ concurrent-ruby (~> 1.0)
209
+ unicode-display_width (2.5.0)
210
+ websocket-driver (0.7.6)
211
+ websocket-extensions (>= 0.1.0)
212
+ websocket-extensions (0.1.5)
213
+ zeitwerk (2.6.13)
214
+
215
+ PLATFORMS
216
+ arm64-darwin-22
217
+ ruby
218
+
219
+ DEPENDENCIES
220
+ debug (~> 1.9, >= 1.9.2)
221
+ minitest
222
+ propshaft
223
+ rails (~> 7.0.6)
224
+ rails_icons!
225
+ standard
226
+
227
+ BUNDLED WITH
228
+ 2.5.9
data/README.md CHANGED
@@ -1,39 +1,115 @@
1
- # RailsIcons
1
+ # Rails Icons
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Embed any library's icon in your Rails app. There are many icon gems for Rails already, but none are library-agnostic. This means you need to pull in other gems or add your logic to display that one specific icon.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_icons`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ The first-party supported icons are stored in a seperate repo: [rails_icons_vault](https://github.com/Rails-Designer/rails_icons_vault). This allows you to pull in only the icon libraries you need, keeping the rails_icons gem lean and lightweight.
6
6
 
7
- ## Installation
8
7
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+ ## Sponsored By [Rails Designer](https://railsdesigner.com/)
10
9
 
11
- Install the gem and add to the application's Gemfile by executing:
10
+ <a href="https://railsdesigner.com/" target="_blank">
11
+ <img src="https://raw.githubusercontent.com/Rails-Designer/rails_icons/main/docs/rails_designer_icon.jpg" alt="Rails Designer logo" width="300" />
12
+ </a>
12
13
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
14
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
15
+ ## Install
16
+
17
+ Add this line to your Gemfile:
18
+
19
+ ```ruby
20
+ gem "rails_icons"
21
+ ```
22
+
23
+ And run:
24
+
25
+ ```bash
26
+ bundle
27
+ ```
28
+
29
+ Sync any of the supported icon libraries from the
30
+ [rails_icons_vault](https://github.com/Rails-Designer/rails_icons_vault):
31
+
32
+ ```bash
33
+ rails generate rails_icons:sync heroicons
34
+ ```
16
35
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
36
 
19
37
  ## Usage
20
38
 
21
- TODO: Write usage instructions here
39
+ ```ruby
40
+ # The default library is Heroicons, with "outline" as the default set
41
+ icon "check"
22
42
 
23
- ## Development
43
+ # Use another set (options are: outline, solid, mini, micro)
44
+ icon "check", set: "solid"
24
45
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+ # Add CSS to the icon
47
+ icon "check", class: "text-green-500"
26
48
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+ # Add data attributes
50
+ icon "check", data: { controller: "swap" }
28
51
 
29
- ## Contributing
52
+ # Tweak the stroke-width
53
+ icon "check", stroke_width: 2
54
+ ```
30
55
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/eelcoj/rails_icons. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/eelcoj/rails_icons/blob/main/CODE_OF_CONDUCT.md).
32
56
 
33
- ## License
57
+ ## Initializer
58
+
59
+ ```ruby
60
+ RailsIcons.configure do |config|
61
+ # Set the default set for the library
62
+ config.default_library = "heroicons"
63
+ config.default_set = "outline"
64
+
65
+ config.libraries.heroicons.solid.default.css = "w-6 h-6"
66
+ config.libraries.heroicons.solid.default.data = {}
67
+
68
+ config.libraries.heroicons.outline.default.css = "w-6 h-6"
69
+ config.libraries.heroicons.outline.default.stroke_width = "1.5"
70
+ config.libraries.heroicons.outline.default.data = {}
34
71
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
72
+ config.libraries.heroicons.mini.default.css = "w-5 h-5"
73
+ config.libraries.heroicons.mini.default.data = {}
36
74
 
37
- ## Code of Conduct
75
+ config.libraries.heroicons.micro.default.css = "w-4 h-4"
76
+ config.libraries.heroicons.micro.default.data = {}
77
+ end
78
+ ```
79
+
80
+ Or run `rails generate rails_icons:initializer`.
81
+
82
+
83
+ ## Add a custom icon library
84
+
85
+ ```ruby
86
+ RailsIcons.configure do |config|
87
+ # …
88
+ config.libraries.merge!(
89
+ {
90
+ custom: {
91
+ simple_icons: {
92
+ solid: {
93
+ path: "app/assets/svg/simple_icons/solid", # optional: the default lookup path is: `app/assets/svg/#{library_name}/#{set}`
94
+ default: {
95
+ css: "w-6 h-6"
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ )
102
+ # …
103
+ end
104
+ ```
105
+
106
+ You can now use any svg-icon in the `app/assets/svg/simple_icons/solid` folder as a first-party icon:
107
+
108
+ ```ruby
109
+ icon "reddit", library: "simple_icons", set: "solid"
110
+ ```
111
+
112
+
113
+ ## License
38
114
 
39
- Everyone interacting in the RailsIcons project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/eelcoj/rails_icons/blob/main/CODE_OF_CONDUCT.md).
115
+ Rails Icons is released under the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rails_icons"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path("..", __dir__)
6
+ ENGINE_PATH = File.expand_path("../lib/rails_icons/engine", __dir__)
7
+ APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
11
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
12
+
13
+ require "rails"
14
+
15
+ require "action_controller/railtie"
16
+ require "action_view/railtie"
17
+
18
+ require "rails/engine/commands"
data/bin/release ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ VERSION=$1
4
+
5
+ if [ -z "$VERSION" ]; then
6
+ echo "Error: The version number is required."
7
+ echo "Usage: $0 <version-number>"
8
+ exit 1
9
+ fi
10
+
11
+ printf "module RailsIcons\n VERSION = \"$VERSION\"\nend\n" > ./lib/rails_icons/version.rb
12
+ bundle
13
+ git add Gemfile.lock lib/rails_icons/version.rb
14
+ git commit -m "Bump version for $VERSION"
15
+ git push
16
+ git tag v$VERSION
17
+ git push --tags
18
+ gem build rails_icons.gemspec
19
+ gem push "rails_icons-$VERSION.gem"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ module RailsIcons
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ def copy_initializer
6
+ copy_file "initializer.rb", "config/initializers/rails_icons.rb"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require "fileutils"
2
+
3
+ module RailsIcons
4
+ class SyncGenerator < Rails::Generators::Base
5
+ ICON_VAULT_REPO_URL = "https://github.com/Rails-Designer/rails_icons_vault.git".freeze
6
+
7
+ argument :libraries, type: :array, default: [], banner: "heroicons lucide"
8
+
9
+ class_option :destination, type: :string, default: nil, desc: "Custom destination folder for icons (default: `app/assets/svg/icons/`)"
10
+
11
+ desc "Sync a specified icon set(s) from the Rails Icons Vault (https://github.com/Rails-Designer/rails_icons_vault)"
12
+ source_root File.expand_path("templates", __dir__)
13
+
14
+ def sync_icons
15
+ icons_dir = options[:destination] || Rails.root.join("app/assets/svg/icons")
16
+ tmp_dir = Rails.root.join("tmp/icons")
17
+
18
+ FileUtils.rm_rf(tmp_dir) if Dir.exist?(tmp_dir)
19
+ FileUtils.mkdir_p(tmp_dir)
20
+
21
+ if system("git clone '#{ICON_VAULT_REPO_URL}' '#{tmp_dir}'")
22
+ say "Repository cloned successfully.", :green
23
+ else
24
+ say "Failed to clone repository.", :red
25
+
26
+ exit 1
27
+ end
28
+
29
+ libraries.each do |set|
30
+ set_path = File.join(tmp_dir, "icons", set)
31
+
32
+ if Dir.exist?(set_path)
33
+ destination_path = File.join(icons_dir, set)
34
+
35
+ FileUtils.mkdir_p(destination_path)
36
+ FileUtils.cp_r(Dir.glob("#{set_path}/*"), destination_path)
37
+
38
+ say "Synced `#{set}` icons for set", :green
39
+ else
40
+ say "Icon set `#{set}` not found", :red
41
+
42
+ exit 1
43
+ end
44
+ end
45
+
46
+ FileUtils.rm_rf(tmp_dir)
47
+
48
+ say "Icons synced successfully", :green
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ RailsIcons.configure do |config|
2
+ # Set the default set for the library
3
+ config.default_library = "heroicons" # https://heroicons.com/
4
+ config.default_set = "outline" # other sets for Heroicons are: solid, mini, micro
5
+
6
+ config.libraries.heroicons.solid.default.css = "w-6 h-6"
7
+ config.libraries.heroicons.solid.default.data = {}
8
+
9
+ config.libraries.heroicons.outline.default.css = "w-6 h-6"
10
+ config.libraries.heroicons.outline.default.stroke_width = "1.5"
11
+ config.libraries.heroicons.outline.default.data = {}
12
+
13
+ config.libraries.heroicons.mini.default.css = "w-5 h-5"
14
+ config.libraries.heroicons.mini.default.data = {}
15
+
16
+ config.libraries.heroicons.micro.default.css = "w-4 h-4"
17
+ config.libraries.heroicons.micro.default.data = {}
18
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsIcons
4
+ class Configuration
5
+ def initialize
6
+ @config = ActiveSupport::OrderedOptions.new
7
+
8
+ set_default_config
9
+ set_libraries_config
10
+ end
11
+
12
+ def method_missing(method_name, ...)
13
+ if @config.respond_to?(method_name)
14
+ @config.send(method_name, ...)
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def respond_to_missing?(method_name)
21
+ @config.respond_to?(method_name) || super
22
+ end
23
+
24
+ private
25
+
26
+ def set_default_config
27
+ @config.helper_name = "icon"
28
+ @config.default_library = "heroicons"
29
+ @config.default_set = "outline"
30
+ end
31
+
32
+ def set_libraries_config
33
+ @config.libraries = ActiveSupport::OrderedOptions.new
34
+
35
+ heroicons_config
36
+ lucide_config
37
+ end
38
+
39
+ def heroicons_config
40
+ @config.libraries.heroicons = ActiveSupport::OrderedOptions.new
41
+
42
+ @config.libraries.heroicons.solid = ActiveSupport::OrderedOptions.new
43
+ @config.libraries.heroicons.solid.default = ActiveSupport::OrderedOptions.new
44
+ @config.libraries.heroicons.solid.default.css = "w-6 h-6"
45
+ @config.libraries.heroicons.solid.default.data = {}
46
+
47
+ @config.libraries.heroicons.outline = ActiveSupport::OrderedOptions.new
48
+ @config.libraries.heroicons.outline.default = ActiveSupport::OrderedOptions.new
49
+ @config.libraries.heroicons.outline.default.stroke_width = 1.5
50
+ @config.libraries.heroicons.outline.default.css = "w-6 h-6"
51
+ @config.libraries.heroicons.outline.default.data = {}
52
+
53
+ @config.libraries.heroicons.mini = ActiveSupport::OrderedOptions.new
54
+ @config.libraries.heroicons.mini.default = ActiveSupport::OrderedOptions.new
55
+ @config.libraries.heroicons.mini.default.css = "w-5 h-5"
56
+ @config.libraries.heroicons.mini.default.data = {}
57
+
58
+ @config.libraries.heroicons.micro = ActiveSupport::OrderedOptions.new
59
+ @config.libraries.heroicons.micro.default = ActiveSupport::OrderedOptions.new
60
+ @config.libraries.heroicons.micro.default.css = "w-4 h-4"
61
+ @config.libraries.heroicons.micro.default.data = {}
62
+ end
63
+
64
+ def lucide_config
65
+ @config.libraries.lucide = ActiveSupport::OrderedOptions.new
66
+
67
+ @config.libraries.lucide.outline = ActiveSupport::OrderedOptions.new
68
+ @config.libraries.lucide.outline.default = ActiveSupport::OrderedOptions.new
69
+ @config.libraries.lucide.outline.default.stroke_width = 2
70
+ @config.libraries.lucide.outline.default.css = "w-6 h-6"
71
+ @config.libraries.lucide.outline.default.data = {}
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsIcons
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace RailsIcons
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsIcons
4
+ class NotFound < StandardError; end
5
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../configuration"
4
+
5
+ module RailsIcons
6
+ module Helpers
7
+ module IconHelper
8
+ def icon(name, library: RailsIcons.configuration.default_library, set: nil, **args)
9
+ RailsIcons::Icon.new(
10
+ name: name,
11
+ library: library,
12
+ set: set,
13
+ args: args
14
+ ).svg
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ module RailsIcons
2
+ class Icon
3
+ class Attributes
4
+ def initialize(default_attributes: {}, args: {})
5
+ @merged_attributes = default_attributes.merge(args)
6
+ end
7
+
8
+ def attach(to:)
9
+ @merged_attributes.each do |key, value|
10
+ if value.is_a?(Hash)
11
+ hash_attributes(key, value, to)
12
+ else
13
+ string_attributes(key, value, to)
14
+ end
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def hash_attributes(key, value, to)
21
+ value.each do |nested_key, nested_value|
22
+ nested_attribute_name = format_attribute_name("#{key}-#{nested_key}")
23
+
24
+ to[nested_attribute_name] = nested_value
25
+ end
26
+ end
27
+
28
+ def string_attributes(key, value, to)
29
+ normalized_key = format_attribute_name(key.to_s)
30
+
31
+ to[normalized_key] = value
32
+ end
33
+
34
+ def format_attribute_name(name)
35
+ name.tr("_", "-")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,82 @@
1
+ require "rails_icons/icon/attributes"
2
+
3
+ class RailsIcons::Icon
4
+ def initialize(name:, library:, set:, args:)
5
+ @name = name
6
+ @library = library.to_s
7
+ @set = set
8
+ @args = args
9
+ end
10
+
11
+ def svg
12
+ raise RailsIcons::NotFound, error_message unless File.exist?(file_path)
13
+
14
+ svg_file = Nokogiri::HTML::DocumentFragment.parse(File.read(file_path)).at_css("svg")
15
+
16
+ attach_attributes to: svg_file
17
+
18
+ svg_file.to_html.html_safe
19
+ end
20
+
21
+ private
22
+
23
+ def error_message
24
+ "Icon not found: `#{@library} / #{set} / #{@name}`"
25
+ end
26
+
27
+ def file_path
28
+ custom_library.dig("path") ||
29
+ Rails.root.join("app", "assets", "svg", "icons", @library, set, "#{@name}.svg")
30
+ end
31
+
32
+ def custom_library?
33
+ custom_library.present?
34
+ end
35
+
36
+ def attach_attributes(to:)
37
+ RailsIcons::Icon::Attributes
38
+ .new(default_attributes: default_attributes, args: @args)
39
+ .attach(to: to)
40
+ end
41
+
42
+ def default_attributes
43
+ {
44
+ "stroke-width": default_stroke_width,
45
+ class: default_css,
46
+ data: default_data
47
+ }
48
+ end
49
+
50
+ def set
51
+ return @set if @set.present?
52
+
53
+ RailsIcons.configuration.default_set
54
+ end
55
+
56
+ def default_css
57
+ library_set_attributes.dig(:default, :css)
58
+ end
59
+
60
+ def default_data
61
+ library_set_attributes.dig(:default, :data)
62
+ end
63
+
64
+ def default_stroke_width
65
+ library_set_attributes.dig(:default, :stroke_width)
66
+ end
67
+
68
+ def library_set_attributes
69
+ return custom_library || {} if custom_library?
70
+
71
+ RailsIcons.configuration.libraries.dig(@library, set) || {}
72
+ end
73
+
74
+ def custom_library
75
+ RailsIcons
76
+ .configuration
77
+ .libraries
78
+ .dig("custom")
79
+ &.with_indifferent_access
80
+ &.dig(@library, set) || {}
81
+ end
82
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_icons/helpers/icon_helper"
4
+
5
+ module RailsIcons
6
+ class Railtie < Rails::Railtie
7
+ initializer "rails_icons.view_helpers" do
8
+ ActiveSupport.on_load(:action_view) do
9
+ include RailsIcons::Helpers::IconHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsIcons
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/rails_icons.rb CHANGED
@@ -1,8 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rails_icons/version"
4
+ require_relative "rails_icons/engine"
5
+ require_relative "rails_icons/configuration"
6
+ require_relative "rails_icons/errors"
7
+ require_relative "rails_icons/railtie"
8
+ require_relative "rails_icons/icon"
4
9
 
5
10
  module RailsIcons
6
- class Error < StandardError; end
7
- # Your code goes here...
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield(configuration)
17
+ end
18
+
19
+ def self.icons_directory
20
+ File.join("lib", "assets", "rails_icons")
21
+ end
8
22
  end
data/rails_icons.gemspec CHANGED
@@ -6,33 +6,19 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "rails_icons"
7
7
  spec.version = RailsIcons::VERSION
8
8
  spec.authors = ["Rails Designer Developers"]
9
- spec.email = ["developers@railsdesigner.com"]
9
+ spec.email = ["devs@railsdesigner.com"]
10
10
 
11
11
  spec.summary = "Add icons from multiple icons in your Rails app"
12
12
  spec.description = "Add SVG icons from multiple libraries, or your own custom icon set with this one gem."
13
- spec.homepage = "https://github.com/Rails-Designer/rails_icons/"
13
+ spec.homepage = "https://railsdesigner.com/rails-icons/"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.0.0"
16
15
 
17
16
  spec.metadata["homepage_uri"] = spec.homepage
18
17
  spec.metadata["source_code_uri"] = "https://github.com/Rails-Designer/rails_icons/"
19
- spec.metadata["changelog_uri"] = "https://github.com/Rails-Designer/rails_icons/blob/main/CHANGELOG.md"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (File.expand_path(f) == __FILE__) ||
26
- f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
18
 
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
19
+ spec.files = Dir["{bin,app,config,db,lib,public}/**/*", "Rakefile", "README.md", "rails_icons.gemspec", "Gemfile", "Gemfile.lock"]
35
20
 
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
21
+ spec.required_ruby_version = ">= 3.0.0"
22
+ spec.add_dependency "rails", "> 6.1"
23
+ spec.add_runtime_dependency "nokogiri", "~> 1.16", ">= 1.16.4"
38
24
  end
metadata CHANGED
@@ -1,40 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer Developers
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.16.4
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.16'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.16.4
13
47
  description: Add SVG icons from multiple libraries, or your own custom icon set with
14
48
  this one gem.
15
49
  email:
16
- - developers@railsdesigner.com
50
+ - devs@railsdesigner.com
17
51
  executables: []
18
52
  extensions: []
19
53
  extra_rdoc_files: []
20
54
  files:
21
- - ".standard.yml"
22
- - CHANGELOG.md
23
- - CODE_OF_CONDUCT.md
24
- - LICENSE.txt
55
+ - Gemfile
56
+ - Gemfile.lock
25
57
  - README.md
26
58
  - Rakefile
59
+ - bin/console
60
+ - bin/rails
61
+ - bin/release
62
+ - bin/setup
63
+ - lib/generators/rails_icons/initializer_generator.rb
64
+ - lib/generators/rails_icons/sync_generator.rb
65
+ - lib/generators/rails_icons/templates/initializer.rb.tt
27
66
  - lib/rails_icons.rb
67
+ - lib/rails_icons/configuration.rb
68
+ - lib/rails_icons/engine.rb
69
+ - lib/rails_icons/errors.rb
70
+ - lib/rails_icons/helpers/icon_helper.rb
71
+ - lib/rails_icons/icon.rb
72
+ - lib/rails_icons/icon/attributes.rb
73
+ - lib/rails_icons/railtie.rb
28
74
  - lib/rails_icons/version.rb
29
75
  - rails_icons.gemspec
30
- - sig/rails_icons.rbs
31
- homepage: https://github.com/Rails-Designer/rails_icons/
76
+ homepage: https://railsdesigner.com/rails-icons/
32
77
  licenses:
33
78
  - MIT
34
79
  metadata:
35
- homepage_uri: https://github.com/Rails-Designer/rails_icons/
80
+ homepage_uri: https://railsdesigner.com/rails-icons/
36
81
  source_code_uri: https://github.com/Rails-Designer/rails_icons/
37
- changelog_uri: https://github.com/Rails-Designer/rails_icons/blob/main/CHANGELOG.md
38
82
  post_install_message:
39
83
  rdoc_options: []
40
84
  require_paths:
@@ -50,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
94
  - !ruby/object:Gem::Version
51
95
  version: '0'
52
96
  requirements: []
53
- rubygems_version: 3.5.7
97
+ rubygems_version: 3.5.15
54
98
  signing_key:
55
99
  specification_version: 4
56
100
  summary: Add icons from multiple icons in your Rails app
data/.standard.yml DELETED
@@ -1,3 +0,0 @@
1
- # For available configuration options, see:
2
- # https://github.com/standardrb/standard
3
- ruby_version: 3.0
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2024-02-28
4
-
5
- - Initial release
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at git@eelcoj.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2024 eelco
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/sig/rails_icons.rbs DELETED
@@ -1,4 +0,0 @@
1
- module RailsIcons
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end