phosphor_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 +4 -4
- data/README.md +40 -4
- data/lib/build/data.json +1 -1
- data/lib/phosphor_icons/icon.rb +17 -1
- data/lib/phosphor_icons/version.rb +1 -1
- metadata +3 -3
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.3.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:
|
11
|
+
date: 2024-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.4.
|
91
|
+
rubygems_version: 3.4.19
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Phosphor Icons for Ruby and Rails
|