phosphor_icons 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -4
- data/lib/phosphor_icons/icon.rb +17 -1
- data/lib/phosphor_icons/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a63df93112504f36a0bfdaeab61b8258749b83277475b92d5ea8323c844a6755
|
4
|
+
data.tar.gz: 155858dc2cbd7588edd502e3470e0a3fcc996bc4dbe2f97c842a52d857e08514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40782061c0446fc20d04d4015d930ec552dd4cfecfa2769b1e529159de300eaaa266551889560a676c13d2422e3b59ca1070396390d7b93f872978fefb8c9f16
|
7
|
+
data.tar.gz: 20d489e20f9c81024572034b6baedb0ce2263928312865b50e46b48457e76d72f9b07d0662940681c2a058b6702c09fe230be7a12c06181039bdf3907084efbd
|
data/README.md
CHANGED
@@ -4,6 +4,13 @@
|
|
4
4
|
|
5
5
|
# Ruby Phosphor Icons
|
6
6
|
|
7
|
+
<a href="https://github.com/maful/ruby-phosphor-icons/actions?query=workflow%3ACI">
|
8
|
+
<img src="https://github.com/maful/ruby-phosphor-icons/actions/workflows/ci.yml/badge.svg" alt="Tests">
|
9
|
+
</a>
|
10
|
+
<a href="https://rubygems.org/gems/phosphor_icons">
|
11
|
+
<img src="https://img.shields.io/gem/v/phosphor_icons" alt="Latest Stable Version">
|
12
|
+
</a>
|
13
|
+
|
7
14
|
A gem to easily include [Phosphor Icons](https://phosphoricons.com) in your Ruby and Rails apps.
|
8
15
|
|
9
16
|
For a full list of available icons see [the assets directory](https://github.com/phosphor-icons/core/tree/c67d7a849f450be1bfe64fd5820471e4019e5ff0/assets) or preview them at [phosphoricons.com](https://phosphoricons.com/).
|
@@ -20,6 +27,12 @@ Install the gem and add to the application's Gemfile by executing:
|
|
20
27
|
bundle add phosphor_icons
|
21
28
|
```
|
22
29
|
|
30
|
+
or add this in your Gemfile
|
31
|
+
|
32
|
+
```rb
|
33
|
+
gem "phosphor_icons"
|
34
|
+
```
|
35
|
+
|
23
36
|
## Usage
|
24
37
|
|
25
38
|
```ruby
|
@@ -27,13 +40,14 @@ require "phosphor_icons"
|
|
27
40
|
|
28
41
|
icon = PhosphorIcons::Icon.new("alarm")
|
29
42
|
icon.to_svg
|
30
|
-
# <svg class="phosphor-icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M128,32a96,96,0,1,0,96,96A96.11,96.11,0,0,0,128,32Zm0,176a80,80,0,1,1,80-80A80.09,80.09,0,0,1,128,208ZM61.66,29.66l-32,32A8,8,0,0,1,18.34,50.34l32-32A8,8,0,1,1,61.66,29.66Zm176,32a8,8,0,0,1-11.32,0l-32-32a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,237.66,61.66ZM184,120a8,8,0,0,1,0,16H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48Z"/></svg>
|
43
|
+
# <svg class="phosphor-icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24"><path d="M128,32a96,96,0,1,0,96,96A96.11,96.11,0,0,0,128,32Zm0,176a80,80,0,1,1,80-80A80.09,80.09,0,0,1,128,208ZM61.66,29.66l-32,32A8,8,0,0,1,18.34,50.34l32-32A8,8,0,1,1,61.66,29.66Zm176,32a8,8,0,0,1-11.32,0l-32-32a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,237.66,61.66ZM184,120a8,8,0,0,1,0,16H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48Z"/></svg>
|
31
44
|
```
|
32
45
|
|
33
46
|
If you are using Ruby on Rails, you can use `phosphor_icon` helper in your views directly
|
34
47
|
|
35
48
|
```erb
|
36
|
-
<%= phosphor_icon "alarm", class: "h-5 w-5 %>
|
49
|
+
<%= phosphor_icon "alarm", class: "h-5 w-5" %>
|
50
|
+
<%= phosphor_icon "x", height: 48 %>
|
37
51
|
```
|
38
52
|
|
39
53
|
## Documentation
|
@@ -47,6 +61,8 @@ This is the name of the Phosphor Icon you want to use. For example `alarm`. [Ful
|
|
47
61
|
### Options
|
48
62
|
|
49
63
|
* `:style` - Apply a specific style to the icon. Available options are `regular` (default), `bold`, `light`, `duotone`, `fill` and `thin`.
|
64
|
+
* `:height` - When setting the height to a number, the icon will scale to that size. For example, passing `24`, will calculate the width based on the icon's natural size.
|
65
|
+
* `:width` - When setting the width to a number, the icon will scale to that size. For example, passing `24`, will calculate the width based on the icon's natural size.
|
50
66
|
|
51
67
|
### Attributes
|
52
68
|
|
@@ -89,7 +105,27 @@ This is a hash of all the `options` that will be added to the output tag.
|
|
89
105
|
```rb
|
90
106
|
icon = PhosphorIcons::Icon.new("alarm")
|
91
107
|
icon.options
|
92
|
-
# {:class=>"phosphor-icon", :viewBox=>"0 0 256 256", :xmlns=>"http://www.w3.org/2000/svg", :fill=>"currentColor"}
|
108
|
+
# {:class=>"phosphor-icon", :viewBox=>"0 0 256 256", :xmlns=>"http://www.w3.org/2000/svg", :fill=>"currentColor", :width=>24, :height=>24}
|
109
|
+
```
|
110
|
+
|
111
|
+
#### `width`
|
112
|
+
|
113
|
+
Width is the icon's true width.
|
114
|
+
|
115
|
+
```rb
|
116
|
+
icon = PhosphorIcons::Icon.new("alarm", width: 24)
|
117
|
+
icon.height
|
118
|
+
# 24
|
119
|
+
```
|
120
|
+
|
121
|
+
#### `height`
|
122
|
+
|
123
|
+
Height is the icon's true height.
|
124
|
+
|
125
|
+
```rb
|
126
|
+
icon = PhosphorIcons::Icon.new("alarm", height: 24)
|
127
|
+
icon.height
|
128
|
+
# 24
|
93
129
|
```
|
94
130
|
|
95
131
|
### Methods
|
@@ -101,7 +137,7 @@ Returns a string of the svg tag
|
|
101
137
|
```rb
|
102
138
|
icon = PhosphorIcons::Icon.new("alarm")
|
103
139
|
icon.to_svg
|
104
|
-
# <svg class="phosphor-icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><path d="M128,32a96,96,0,1,0,96,96A96.11,96.11,0,0,0,128,32Zm0,176a80,80,0,1,1,80-80A80.09,80.09,0,0,1,128,208ZM61.66,29.66l-32,32A8,8,0,0,1,18.34,50.34l32-32A8,8,0,1,1,61.66,29.66Zm176,32a8,8,0,0,1-11.32,0l-32-32a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,237.66,61.66ZM184,120a8,8,0,0,1,0,16H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48Z"/></svg>
|
140
|
+
# <svg class="phosphor-icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24"><path d="M128,32a96,96,0,1,0,96,96A96.11,96.11,0,0,0,128,32Zm0,176a80,80,0,1,1,80-80A80.09,80.09,0,0,1,128,208ZM61.66,29.66l-32,32A8,8,0,0,1,18.34,50.34l32-32A8,8,0,1,1,61.66,29.66Zm176,32a8,8,0,0,1-11.32,0l-32-32a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,237.66,61.66ZM184,120a8,8,0,0,1,0,16H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48Z"/></svg>
|
105
141
|
```
|
106
142
|
|
107
143
|
## Development
|
data/lib/phosphor_icons/icon.rb
CHANGED
@@ -4,19 +4,25 @@ module PhosphorIcons
|
|
4
4
|
class Icon
|
5
5
|
DEFAULT_STYLE = "regular"
|
6
6
|
SUPPORTED_STYLES = [DEFAULT_STYLE, "bold", "light", "duotone", "fill", "thin"]
|
7
|
+
NATURAL_HEIGHTS = [16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80]
|
8
|
+
DEFAULT_HEIGHT = 24
|
7
9
|
|
8
|
-
attr_reader :symbol, :style, :options, :path
|
10
|
+
attr_reader :symbol, :style, :options, :path, :width, :height
|
9
11
|
|
10
12
|
def initialize(symbol, options = {})
|
11
13
|
@symbol = symbol.to_s
|
12
14
|
@style = options[:style] || DEFAULT_STYLE
|
13
15
|
if (phosphor_icon = get_phosphor_icon(@symbol, options))
|
14
16
|
@path = phosphor_icon["path"]
|
17
|
+
@width = phosphor_icon["width"]
|
18
|
+
@height = phosphor_icon["height"]
|
15
19
|
@options = {
|
16
20
|
class: "phosphor-icon #{options[:class]}".strip,
|
17
21
|
viewBox: viewbox,
|
18
22
|
xmlns: "http://www.w3.org/2000/svg",
|
19
23
|
fill: "currentColor",
|
24
|
+
width: @width,
|
25
|
+
height: @height,
|
20
26
|
}
|
21
27
|
else
|
22
28
|
raise IconNotFoundError, "Couldn't find #{self}"
|
@@ -45,10 +51,14 @@ module PhosphorIcons
|
|
45
51
|
|
46
52
|
def get_phosphor_icon(symbol, options = {})
|
47
53
|
if (phosphor_icon = PhosphorIcons::ICON_SYMBOLS[symbol])
|
54
|
+
height = options[:height] || options[:width] || DEFAULT_HEIGHT
|
55
|
+
natural_height = closest_natural_height(height)
|
48
56
|
style = get_style(options[:style])
|
49
57
|
|
50
58
|
{
|
51
59
|
"name" => phosphor_icon["name"],
|
60
|
+
"width" => natural_height,
|
61
|
+
"height" => natural_height,
|
52
62
|
"path" => phosphor_icon["styles"][style.to_s]["path"],
|
53
63
|
}
|
54
64
|
end
|
@@ -59,5 +69,11 @@ module PhosphorIcons
|
|
59
69
|
def get_style(style)
|
60
70
|
SUPPORTED_STYLES.include?(style.to_s) ? style : DEFAULT_STYLE
|
61
71
|
end
|
72
|
+
|
73
|
+
def closest_natural_height(height)
|
74
|
+
NATURAL_HEIGHTS.reduce(NATURAL_HEIGHTS[0].to_i) do |acc, natural_height|
|
75
|
+
natural_height.to_i <= height.to_i ? natural_height.to_i : acc
|
76
|
+
end
|
77
|
+
end
|
62
78
|
end
|
63
79
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phosphor_icons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maful Prayoga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|