iconify-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +40 -0
- data/lib/iconify/engine.rb +8 -0
- data/lib/iconify/helpers.rb +28 -0
- data/lib/iconify/version.rb +3 -0
- data/lib/iconify-rails.rb +33 -0
- data/lib/install/iconify.rb +4 -0
- data/lib/install.rb +2 -0
- data/lib/tasks/iconify/install.rake +6 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b13d5388ff61d0a4f97bb15cf98a14e28a6f1dd758d83ca4a04d8f6a6d21f353
|
4
|
+
data.tar.gz: 1789c4d741a0ca3f1cdd47492bff872f0dfa9fcf4ab7b097180ec4b844617637
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8a2d05f5a4b52e5b21d7b216fc98f4b9f1de10a63c76fbf72a89136451ddb45c1eaf6de69f1915987d11e7672e9ad6ef19c2c5b64320c443fb918b13da848c1
|
7
|
+
data.tar.gz: ff2a0f976b6049a8dbe1592fd91ed382402de90a5c8c51969a06dd6e86b26d101741108ac37755f6376e1940ef695452c0f18a86494b4aab980397b624c9bbc4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Ethan Kircher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Easy to use Icons for Rails
|
2
|
+
|
3
|
+
This gem provides an easy integration with the icons from [iconify](https://github.com/iconify/icon-sets/tree/master).
|
4
|
+
|
5
|
+
Take any of the icons from their [json icon sets](https://github.com/iconify/icon-sets/tree/master/json).
|
6
|
+
|
7
|
+
They can be previewed at [iconify.design](https://iconify.design)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Grab a json file from [iconify](https://github.com/iconify/icon-sets/tree/master/json).
|
12
|
+
|
13
|
+
```bash
|
14
|
+
./bin/bundle add iconify-rails
|
15
|
+
```
|
16
|
+
|
17
|
+
```bash
|
18
|
+
./bin/rails iconify:install
|
19
|
+
```
|
20
|
+
|
21
|
+
Now setup the location of the json, and the preferred variant if there is one.
|
22
|
+
|
23
|
+
```rb
|
24
|
+
Iconify.configure do |config|
|
25
|
+
config.file = "vendor/icons/heroicons.json"
|
26
|
+
config.suffix = :suffix
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
In any view just use ye olde `icon` helper.
|
33
|
+
|
34
|
+
```erb
|
35
|
+
<%= icon(:house, class: 'size-6') %>
|
36
|
+
```
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
`iconify-rails` is released under the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Iconify::Helpers
|
2
|
+
def icon(name, suffix: Iconify.configuration.default_suffix, **attrs)
|
3
|
+
suffix = suffix.to_s
|
4
|
+
icon_name = name.to_s.dasherize
|
5
|
+
icon_name = "#{icon_name}-#{suffix}" if suffix.present?
|
6
|
+
|
7
|
+
icon = Iconify::ICON_DATA["icons"][icon_name]
|
8
|
+
|
9
|
+
tag.span { "#{icon_name} missing" } if icon.nil?
|
10
|
+
|
11
|
+
viewbox = read_view_box(icon)
|
12
|
+
|
13
|
+
tag.svg(xlmns: "http://www.w3.org/2000/svg", viewBox: viewbox, **attrs) do
|
14
|
+
raw(icon["body"])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def read_view_box(icon)
|
21
|
+
left = icon["left"] || Iconify::ICON_DATA["left"] || 0
|
22
|
+
right = icon["right"] || Iconify::ICON_DATA["right"] || 0
|
23
|
+
width = icon["width"] || Iconify::ICON_DATA["width"] || 16
|
24
|
+
height = icon["height"] || Iconify::ICON_DATA["height"] || 16
|
25
|
+
|
26
|
+
"#{left} #{right} #{width} #{height}"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Iconify
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :file, :default_suffix
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@file = "vendor/icons/heroicons.json"
|
7
|
+
@default_suffix = nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
path = Rails.root.join(configuration.file)
|
22
|
+
raw = File.read(path)
|
23
|
+
parsed = JSON.parse(raw)
|
24
|
+
raw_suffixes = parsed.delete("suffixes")
|
25
|
+
|
26
|
+
self.const_set("ICON_DATA", parsed.freeze)
|
27
|
+
self.const_set("SUFFIXES", raw_suffixes&.keys.freeze)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
require "iconify/version"
|
33
|
+
require "iconify/engine"
|
data/lib/install.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iconify-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ethan Kircher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-20 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.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- ethanmichaelk@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/iconify-rails.rb
|
37
|
+
- lib/iconify/engine.rb
|
38
|
+
- lib/iconify/helpers.rb
|
39
|
+
- lib/iconify/version.rb
|
40
|
+
- lib/install.rb
|
41
|
+
- lib/install/iconify.rb
|
42
|
+
- lib/tasks/iconify/install.rake
|
43
|
+
homepage: https://github.com/rails/jsbundling-rails
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.9
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Use @iconify/json icon sets with Rails for inline SVGs
|
66
|
+
test_files: []
|