hanami_icons 0.5.0 → 0.6.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 +4 -4
- data/README.md +57 -42
- data/hanami_icons.gemspec +1 -1
- data/lib/hanami_icons/cli/commands/generate/icons.rb +4 -2
- data/lib/hanami_icons/cli/commands/generate/initializer.rb +4 -2
- data/lib/hanami_icons/cli/commands/generate/sprite.rb +2 -0
- data/lib/hanami_icons/cli/commands/generate/sync.rb +2 -0
- data/lib/hanami_icons/version.rb +1 -1
- data/lib/hanami_icons.rb +21 -8
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b676ab621f60364217f28420be21eec51a36c4b7128ae562d271b8941f4134b
|
|
4
|
+
data.tar.gz: fb4ec56edaf60459102657f6ba811c1c9f322bbc28af3107695a1f7a81225112
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5513690d48a3ad7a1fa303c314873d869efaa1332fb96cb2d1c539f04eb05f8cb382bbf239deab010c9bb6884d494e92bc38b098761a8d30f01f05b768c1d63
|
|
7
|
+
data.tar.gz: 9c681679074b35d827f28af8fbb3ec50b78c38ee0cf51531a64369511ce664efbc0aaedfa01c97fcaff6c96283207890fc26ac712d14b969a3a14c7ed6bc285c
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Hanami Icons
|
|
2
2
|
|
|
3
|
-
Add any icon library to a Hanami app. Hanami Icons has first-party support for
|
|
3
|
+
Add any icon library to a Hanami app. Hanami Icons has first-party support for [several libraries](#first-party-libraries) and one interface for all of them. It is a Hanami wrapper for the [Icons Ruby gem](https://github.com/Rails-Designer/icons).
|
|
4
4
|
|
|
5
5
|
```erb
|
|
6
6
|
# Using the default icon library
|
|
@@ -10,68 +10,72 @@ Add any icon library to a Hanami app. Hanami Icons has first-party support for a
|
|
|
10
10
|
<%== icon "apple", library: "simple_icons", class: "text-black" %>
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
The
|
|
13
|
+
The [Icons](https://github.com/Rails-Designer/icons) gem reads icons from their source repositories, so Hanami Icons stays small.
|
|
14
14
|
|
|
15
15
|
**Sponsored By [Rails Designer](https://railsdesigner.com/)**
|
|
16
16
|
|
|
17
17
|
## Install
|
|
18
18
|
|
|
19
|
-
Add the gem:
|
|
19
|
+
Hanami loads CLI extensions from the `:cli` Bundler group. The view helpers also need the gem at runtime. Add the gem to both groups:
|
|
20
20
|
|
|
21
|
-
```
|
|
22
|
-
|
|
21
|
+
```ruby
|
|
22
|
+
gem "hanami_icons", group: [:default, :cli]
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Then run:
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
|
|
28
|
+
bundle install
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Generate the provider and sync a library:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
34
|
hanami generate icons --library=heroicons
|
|
35
|
+
```
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
More examples:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Multiple libraries
|
|
37
41
|
hanami generate icons --libraries=heroicons lucide
|
|
38
42
|
|
|
39
|
-
#
|
|
43
|
+
# Selected variants only
|
|
40
44
|
hanami generate icons --library=heroicons --variants solid outline
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
The command creates `config/providers/icons.rb`, registers the `icons` provider, and adds the helpers to `app/views/helpers.rb`.
|
|
44
48
|
|
|
45
49
|
## Usage
|
|
46
50
|
|
|
47
51
|
```ruby
|
|
48
|
-
#
|
|
52
|
+
# Default library and variant from config/providers/icons.rb
|
|
49
53
|
icon "check"
|
|
50
54
|
|
|
51
|
-
#
|
|
55
|
+
# Another variant
|
|
52
56
|
icon "check", variant: "solid"
|
|
53
57
|
|
|
54
|
-
#
|
|
58
|
+
# Explicit library
|
|
55
59
|
icon "check", library: "heroicons"
|
|
56
60
|
|
|
57
|
-
#
|
|
61
|
+
# CSS class
|
|
58
62
|
icon "check", class: "text-green-500"
|
|
59
63
|
|
|
60
|
-
#
|
|
64
|
+
# Data attributes
|
|
61
65
|
icon "check", data: { controller: "swap" }
|
|
62
66
|
|
|
63
|
-
#
|
|
67
|
+
# Stroke width
|
|
64
68
|
icon "check", stroke_width: 2
|
|
65
69
|
|
|
66
|
-
# Base64
|
|
70
|
+
# Base64 data URI
|
|
67
71
|
encoded_icon "check"
|
|
68
72
|
```
|
|
69
73
|
|
|
70
|
-
The helpers return `Hanami::View::HTML::SafeString
|
|
74
|
+
The helpers return `Hanami::View::HTML::SafeString`. Use `<%== %>` in ERB or `==` in Slim.
|
|
71
75
|
|
|
72
76
|
## Sprites
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
A sprite references shared `<symbol>` definitions with `<use href="…">`. Use a sprite when a page shows many icons.
|
|
75
79
|
|
|
76
80
|
### Configuration
|
|
77
81
|
|
|
@@ -81,13 +85,13 @@ HanamiIcons.configure do |config|
|
|
|
81
85
|
config.default_library = "heroicons"
|
|
82
86
|
config.default_variant = "outline"
|
|
83
87
|
|
|
84
|
-
#
|
|
88
|
+
# URL for `sprite_icon`. Set to nil for an inline sprite.
|
|
85
89
|
config.default_sprite_location = "/sprite.svg"
|
|
86
90
|
|
|
87
|
-
#
|
|
91
|
+
# Check that referenced icons exist on disk.
|
|
88
92
|
config.validate_sprite_icons = false
|
|
89
93
|
|
|
90
|
-
#
|
|
94
|
+
# Icons to include in the sprite.
|
|
91
95
|
config.sprite = {
|
|
92
96
|
heroicons: {
|
|
93
97
|
outline: %w[check chevron-down menu search x],
|
|
@@ -99,24 +103,26 @@ end
|
|
|
99
103
|
|
|
100
104
|
### External sprite
|
|
101
105
|
|
|
102
|
-
Generate a
|
|
106
|
+
Generate a sprite file:
|
|
103
107
|
|
|
104
108
|
```bash
|
|
105
109
|
hanami generate icons:sprite
|
|
106
110
|
```
|
|
107
111
|
|
|
112
|
+
Then reference it:
|
|
113
|
+
|
|
108
114
|
```erb
|
|
109
115
|
<%== sprite_icon "check" %>
|
|
110
|
-
<%#
|
|
116
|
+
<%# => <svg><use href="/sprite.svg#heroicons_outline_check"></use></svg> %>
|
|
111
117
|
```
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
Use a CDN or a different file:
|
|
114
120
|
|
|
115
121
|
```ruby
|
|
116
122
|
config.default_sprite_location = "https://cdn.example.com/sprite_icons.svg"
|
|
117
123
|
```
|
|
118
124
|
|
|
119
|
-
Override
|
|
125
|
+
Override the location for one icon:
|
|
120
126
|
|
|
121
127
|
```erb
|
|
122
128
|
<%== sprite_icon "check", sprite_location: "/assets/sprites.svg" %>
|
|
@@ -124,7 +130,7 @@ Override per icon:
|
|
|
124
130
|
|
|
125
131
|
### Inline sprite
|
|
126
132
|
|
|
127
|
-
Set the location to `nil` and embed the sprite
|
|
133
|
+
Set the location to `nil` and embed the sprite in your layout:
|
|
128
134
|
|
|
129
135
|
```ruby
|
|
130
136
|
config.default_sprite_location = nil
|
|
@@ -140,7 +146,7 @@ config.default_sprite_location = nil
|
|
|
140
146
|
</body>
|
|
141
147
|
```
|
|
142
148
|
|
|
143
|
-
|
|
149
|
+
Build a sprite for selected icons:
|
|
144
150
|
|
|
145
151
|
```erb
|
|
146
152
|
<%== icons_sprite ["check", "search"], library: "heroicons", variant: "outline" %>
|
|
@@ -148,46 +154,53 @@ You can also generate a sprite for a specific set of icons:
|
|
|
148
154
|
|
|
149
155
|
## Sync icons
|
|
150
156
|
|
|
151
|
-
|
|
157
|
+
Sync every first-party library:
|
|
152
158
|
|
|
153
159
|
```bash
|
|
154
160
|
hanami generate icons:sync
|
|
155
161
|
```
|
|
156
162
|
|
|
157
|
-
|
|
163
|
+
Sync one library:
|
|
158
164
|
|
|
159
165
|
```bash
|
|
160
166
|
hanami generate icons:sync --library=heroicons
|
|
167
|
+
```
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
Sync several libraries:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
163
172
|
hanami generate icons:sync --libraries=heroicons lucide
|
|
164
173
|
```
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
Sync selected variants:
|
|
167
176
|
|
|
168
177
|
```bash
|
|
169
178
|
hanami generate icons:sync --library=heroicons --variants solid outline
|
|
170
179
|
```
|
|
171
180
|
|
|
181
|
+
The `icons:sync` command runs before the app boots, so it does not load `config/providers/icons.rb`. It sees first-party libraries only.
|
|
182
|
+
|
|
172
183
|
## Custom icon libraries
|
|
173
184
|
|
|
174
|
-
Hanami Icons
|
|
185
|
+
Hanami Icons reads SVGs from `<icons_path>/<library>/<name>.svg`. Libraries with variants add a variant directory, such as `<icons_path>/heroicons/outline/check.svg`.
|
|
175
186
|
|
|
176
|
-
|
|
187
|
+
Local libraries need no configuration. Create the directory and add SVGs:
|
|
177
188
|
|
|
178
189
|
```
|
|
179
190
|
app/assets/svg/icons/simple_icons/apple.svg
|
|
180
191
|
```
|
|
181
192
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Use them like any other library:
|
|
193
|
+
Then use the library:
|
|
185
194
|
|
|
186
195
|
```ruby
|
|
187
196
|
icon "apple", library: "simple_icons"
|
|
188
197
|
```
|
|
189
198
|
|
|
190
|
-
To
|
|
199
|
+
To scaffold a custom library, run `hanami generate icons --library=simple_icons`. The command creates the directory and adds `config.custom_library :simple_icons` to the provider.
|
|
200
|
+
|
|
201
|
+
### Git-sourced libraries
|
|
202
|
+
|
|
203
|
+
Add the source to the provider:
|
|
191
204
|
|
|
192
205
|
```ruby
|
|
193
206
|
HanamiIcons.configure do |config|
|
|
@@ -198,12 +211,14 @@ HanamiIcons.configure do |config|
|
|
|
198
211
|
end
|
|
199
212
|
```
|
|
200
213
|
|
|
201
|
-
|
|
214
|
+
`icons:sync` cannot see this library because it does not load providers. Sync it in the app context:
|
|
202
215
|
|
|
203
216
|
```bash
|
|
204
|
-
hanami
|
|
217
|
+
bundle exec hanami run 'Icons::Sync.new(:my_icons).now'
|
|
205
218
|
```
|
|
206
219
|
|
|
220
|
+
You can also run the same call in `hanami console`.
|
|
221
|
+
|
|
207
222
|
## First-party libraries
|
|
208
223
|
|
|
209
224
|
- [Boxicons](https://railsdesigner.com/open-source/rails-icons/boxicons/) (1600+ icons)
|
|
@@ -221,7 +236,7 @@ hanami generate icons:sync --library=my_icons
|
|
|
221
236
|
|
|
222
237
|
## Contributing
|
|
223
238
|
|
|
224
|
-
This project uses [Standard](https://github.com/testdouble/standard) for
|
|
239
|
+
This project uses [Standard](https://github.com/testdouble/standard) for Ruby formatting. Run `bundle exec standardrb` before you open a pull request. Run the tests with `bundle exec rake`.
|
|
225
240
|
|
|
226
241
|
## License
|
|
227
242
|
|
data/hanami_icons.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
|
|
11
11
|
spec.summary = "Add any icon library to a Hanami app"
|
|
12
12
|
spec.description = "Add any icon library to a Hanami app, from Heroicons, to Lucide to Tabler (and others). Hanami Icons is library-agnostic, so you can add any library while using the same interface."
|
|
13
|
-
spec.homepage = "https://railsdesigner.com/open-source/
|
|
13
|
+
spec.homepage = "https://railsdesigner.com/open-source/hanami_icons/"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
@@ -17,7 +17,7 @@ module HanamiIcons
|
|
|
17
17
|
option :library, desc: "Choose a library"
|
|
18
18
|
option :libraries, type: :array, default: [], desc: "Choose libraries"
|
|
19
19
|
option :variants, type: :array, desc: "Only sync specific variants (e.g. solid outline)"
|
|
20
|
-
option :destination, type: :string,
|
|
20
|
+
option :destination, type: :string, desc: "Specify destination folder for icons"
|
|
21
21
|
option :skip_sync, type: :boolean, default: false
|
|
22
22
|
|
|
23
23
|
# @param library [String, nil]
|
|
@@ -28,7 +28,9 @@ module HanamiIcons
|
|
|
28
28
|
#
|
|
29
29
|
# @api public
|
|
30
30
|
# @since 0.1.0
|
|
31
|
-
def call(library: nil, libraries: [], variants: nil, destination:
|
|
31
|
+
def call(library: nil, libraries: [], variants: nil, destination: nil, skip_sync: false, **)
|
|
32
|
+
destination ||= HanamiIcons.configuration.icons_path
|
|
33
|
+
|
|
32
34
|
run_initializer(library: library, libraries: libraries, variants: variants, destination: destination)
|
|
33
35
|
|
|
34
36
|
if !skip_sync && selected_libraries(library, libraries).any?
|
|
@@ -18,7 +18,7 @@ module HanamiIcons
|
|
|
18
18
|
option :library, desc: "Choose a library"
|
|
19
19
|
option :libraries, type: :array, default: [], desc: "Choose libraries"
|
|
20
20
|
option :variants, type: :array, desc: "Only sync specific variants (e.g. solid outline)"
|
|
21
|
-
option :destination, type: :string,
|
|
21
|
+
option :destination, type: :string, desc: "Specify destination folder for icons"
|
|
22
22
|
|
|
23
23
|
PROVIDER = "config/providers/icons.rb"
|
|
24
24
|
HELPERS = "app/views/helpers.rb"
|
|
@@ -31,7 +31,9 @@ module HanamiIcons
|
|
|
31
31
|
#
|
|
32
32
|
# @api public
|
|
33
33
|
# @since 0.1.0
|
|
34
|
-
def call(library: nil, libraries: [], variants: nil, destination:
|
|
34
|
+
def call(library: nil, libraries: [], variants: nil, destination: nil, **)
|
|
35
|
+
destination ||= HanamiIcons.configuration.icons_path
|
|
36
|
+
|
|
35
37
|
copy_provider
|
|
36
38
|
|
|
37
39
|
insert_default_configuration(selected_libraries(library, libraries).first)
|
|
@@ -24,6 +24,8 @@ module HanamiIcons
|
|
|
24
24
|
# @api public
|
|
25
25
|
# @since 0.1.0
|
|
26
26
|
def call(library: nil, libraries: [], variants: nil, **)
|
|
27
|
+
HanamiIcons.configuration
|
|
28
|
+
|
|
27
29
|
selected_libraries(library, libraries).each do |name|
|
|
28
30
|
::Icons::Sync.new(name, variants: variants&.map(&:to_sym)).now
|
|
29
31
|
end
|
data/lib/hanami_icons/version.rb
CHANGED
data/lib/hanami_icons.rb
CHANGED
|
@@ -27,16 +27,25 @@ module HanamiIcons
|
|
|
27
27
|
class << self
|
|
28
28
|
# @yield [config] Yields the Icons configuration
|
|
29
29
|
# @yieldparam config [Icons::Configuration]
|
|
30
|
+
# @return [Icons::Configuration]
|
|
30
31
|
#
|
|
31
32
|
# @api public
|
|
32
33
|
# @since 0.1.0
|
|
33
|
-
def configure(&block)
|
|
34
|
+
def configure(&block)
|
|
35
|
+
Icons.configure(&block)
|
|
36
|
+
|
|
37
|
+
Icons.configuration
|
|
38
|
+
end
|
|
34
39
|
|
|
35
40
|
# @return [Icons::Configuration]
|
|
36
41
|
#
|
|
37
42
|
# @api public
|
|
38
43
|
# @since 0.1.0
|
|
39
|
-
def configuration
|
|
44
|
+
def configuration
|
|
45
|
+
Icons.configure {} unless Icons.configuration
|
|
46
|
+
|
|
47
|
+
Icons.configuration
|
|
48
|
+
end
|
|
40
49
|
|
|
41
50
|
alias_method :config, :configuration
|
|
42
51
|
|
|
@@ -45,12 +54,16 @@ module HanamiIcons
|
|
|
45
54
|
# @api public
|
|
46
55
|
# @since 0.1.0
|
|
47
56
|
def libraries = Icons.libraries
|
|
48
|
-
end
|
|
49
57
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
# @api private
|
|
59
|
+
# @since 0.1.0
|
|
60
|
+
def register_cli_commands!
|
|
61
|
+
Hanami::CLI.register "generate icons", CLI::Commands::Generate::Icons
|
|
62
|
+
Hanami::CLI.register "generate icons:initializer", CLI::Commands::Generate::Initializer
|
|
63
|
+
Hanami::CLI.register "generate icons:sync", CLI::Commands::Generate::Sync
|
|
64
|
+
Hanami::CLI.register "generate icons:sprite", CLI::Commands::Generate::Sprite
|
|
65
|
+
end
|
|
55
66
|
end
|
|
67
|
+
|
|
68
|
+
register_cli_commands! if Hanami::CLI.within_hanami_app?
|
|
56
69
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hanami_icons
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rails Designer
|
|
@@ -87,15 +87,15 @@ files:
|
|
|
87
87
|
- lib/hanami_icons/helpers/icon_helper.rb
|
|
88
88
|
- lib/hanami_icons/helpers/sprite_helper.rb
|
|
89
89
|
- lib/hanami_icons/version.rb
|
|
90
|
-
homepage: https://railsdesigner.com/open-source/
|
|
90
|
+
homepage: https://railsdesigner.com/open-source/hanami_icons/
|
|
91
91
|
licenses:
|
|
92
92
|
- MIT
|
|
93
93
|
metadata:
|
|
94
|
-
homepage_uri: https://railsdesigner.com/open-source/
|
|
94
|
+
homepage_uri: https://railsdesigner.com/open-source/hanami_icons/
|
|
95
95
|
source_code_uri: https://github.com/Rails-Designer/hanami_icons
|
|
96
96
|
changelog_uri: https://github.com/Rails-Designer/hanami_icons/releases
|
|
97
97
|
bug_tracker_uri: https://github.com/Rails-Designer/hanami_icons/issues
|
|
98
|
-
documentation_uri: https://railsdesigner.com/open-source/
|
|
98
|
+
documentation_uri: https://railsdesigner.com/open-source/hanami_icons/
|
|
99
99
|
rubygems_mfa_required: 'true'
|
|
100
100
|
rdoc_options: []
|
|
101
101
|
require_paths:
|