bootstrap-icons 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/bootstrap_icons/bootstrap_icon.rb +53 -37
- data/lib/bootstrap_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: 43602983de499c1a51f734370c8293c04033df383424de6c63c7e064541e567b
|
4
|
+
data.tar.gz: 44ea996ed14e47a1aa0f886cd7842d33eb6fa2686f1ea176b08b652fee392679
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0d94a34ddf968608f94116b6b3eeda9e8dda81161e650d2e09bf4222092279abdeb7992344bfa9a41e85a0fddd81a77fb7ad46791d2b1c30eeecd153718c767
|
7
|
+
data.tar.gz: a84e9fa58edfa28dd36208d78f490289c65c8e398afd55b773bf0f0da7257ab4434d0cb03e761fbabef42debace38d018e806046976d632712dac007c953b57a
|
data/CHANGELOG.md
CHANGED
@@ -1,50 +1,62 @@
|
|
1
1
|
module BootstrapIcons
|
2
2
|
class BootstrapIcon
|
3
|
-
attr_reader :path, :options, :width, :height, :symbol
|
3
|
+
attr_reader :path, :options, :width, :height, :fill, :viewBox, :symbol
|
4
4
|
|
5
5
|
def initialize(symbol, options = {})
|
6
6
|
@symbol = symbol.to_s
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
class: classes,
|
17
|
-
viewBox: bootstrap_icon["viewBox"],
|
18
|
-
fill: fill_with,
|
19
|
-
version: "1.1"
|
20
|
-
})
|
21
|
-
@options.merge!(size)
|
22
|
-
@options.merge!(a11y)
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
raise "Couldn't find bootstrap icon symbol for #{@symbol.inspect}"
|
27
|
-
end
|
7
|
+
@options = options
|
8
|
+
@bootstrap_icon = find_bootstrap_icon
|
9
|
+
@path = bootstrap_icon["path"]
|
10
|
+
@width = bootstrap_icon["width"].to_i
|
11
|
+
@height = bootstrap_icon["height"].to_i
|
12
|
+
@fill = bootstrap_icon["fill"]
|
13
|
+
@viewBox = bootstrap_icon["viewBox"]
|
14
|
+
|
15
|
+
prepare_icon_options
|
28
16
|
end
|
29
17
|
|
30
18
|
# Returns an string representing a <svg> tag
|
31
19
|
def to_svg
|
32
|
-
"<svg #{html_attributes}>#{
|
20
|
+
"<svg #{html_attributes}>#{path}</svg>"
|
33
21
|
end
|
34
22
|
|
35
23
|
private
|
36
24
|
|
25
|
+
attr_reader :bootstrap_icon
|
26
|
+
|
37
27
|
def html_attributes
|
38
28
|
attrs = ""
|
39
|
-
|
29
|
+
options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
|
40
30
|
attrs.strip
|
41
31
|
end
|
42
32
|
|
33
|
+
def find_bootstrap_icon
|
34
|
+
icon = BootstrapIcons::BOOTSTRAP_ICONS_SYMBOLS[symbol]
|
35
|
+
raise_icon_not_found if icon.nil?
|
36
|
+
|
37
|
+
icon
|
38
|
+
end
|
39
|
+
|
40
|
+
def raise_icon_not_found
|
41
|
+
raise "Couldn't find bootstrap icon symbol for #{symbol.inspect}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare_icon_options
|
45
|
+
options.merge!({
|
46
|
+
class: classes,
|
47
|
+
viewBox: viewBox,
|
48
|
+
fill: fill_with,
|
49
|
+
version: "1.1"
|
50
|
+
})
|
51
|
+
options.merge!(size)
|
52
|
+
options.merge!(a11y)
|
53
|
+
end
|
54
|
+
|
43
55
|
# add some accessibility features to svg
|
44
56
|
def a11y
|
45
57
|
accessible = {}
|
46
58
|
|
47
|
-
if
|
59
|
+
if options[:"aria-label"].nil? && options["aria-label"].nil?
|
48
60
|
accessible[:"aria-hidden"] = "true"
|
49
61
|
else
|
50
62
|
accessible[:role] = "img"
|
@@ -55,25 +67,25 @@ module BootstrapIcons
|
|
55
67
|
|
56
68
|
# prepare the bootstrap_icon class
|
57
69
|
def classes
|
58
|
-
"bi bi-#{
|
70
|
+
"bi bi-#{symbol} #{options[:class]} ".strip
|
59
71
|
end
|
60
72
|
|
61
73
|
def fill_with
|
62
|
-
fill_option =
|
63
|
-
fill_option.nil? ?
|
74
|
+
fill_option = options[:fill]
|
75
|
+
fill_option.nil? ? fill : fill_option
|
64
76
|
end
|
65
77
|
|
66
78
|
# determine the height and width of the bootstrap_icon based on :size option
|
67
79
|
def size
|
68
80
|
size = {
|
69
|
-
width:
|
70
|
-
height:
|
81
|
+
width: width,
|
82
|
+
height: height
|
71
83
|
}
|
72
84
|
|
73
85
|
# Specific size
|
74
|
-
|
75
|
-
size[:width] =
|
76
|
-
size[:height] =
|
86
|
+
if custom_size_option_provided?
|
87
|
+
size[:width] = options.has_key?(:width) ? options[:width] : calculate_width(options[:height])
|
88
|
+
size[:height] = options.has_key?(:height) ? options[:height] : calculate_height(options[:width])
|
77
89
|
end
|
78
90
|
|
79
91
|
size[:width] = size[:width].to_s + "em"
|
@@ -81,12 +93,16 @@ module BootstrapIcons
|
|
81
93
|
size
|
82
94
|
end
|
83
95
|
|
84
|
-
def
|
85
|
-
(
|
96
|
+
def custom_size_option_provided?
|
97
|
+
options.has_key?(:width) || options.has_key?(:height)
|
98
|
+
end
|
99
|
+
|
100
|
+
def calculate_width(custom_height)
|
101
|
+
(custom_height.to_i * width) / height
|
86
102
|
end
|
87
103
|
|
88
|
-
def calculate_height(
|
89
|
-
(
|
104
|
+
def calculate_height(custom_width)
|
105
|
+
(custom_width.to_i * height) / width
|
90
106
|
end
|
91
107
|
end
|
92
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap-icons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Lauxen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|