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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db7363124b9e26ee4b4bbbd9374476656a9fa4b2e4c3310a4a9e7c0f24b1b7f3
4
- data.tar.gz: a0d9326b0bff91d2e02a509fa7df63d0c4a86a49e7c795e70d97ff104533cb10
3
+ metadata.gz: 43602983de499c1a51f734370c8293c04033df383424de6c63c7e064541e567b
4
+ data.tar.gz: 44ea996ed14e47a1aa0f886cd7842d33eb6fa2686f1ea176b08b652fee392679
5
5
  SHA512:
6
- metadata.gz: 307e30cd3ec30e24d8f1ebdec17b653d43ba0b822d2432100dfeaef91e8b98444327c81d06da5aecf2ca9a37da0e618795d294c6d80a876942fbbf405645b707
7
- data.tar.gz: d6478224c30bf440dc9572f4f3e31db701dfde557fc31ecfe5c8e8f1d09035f6bc6436125928a39a7e4aa92d3763b015593ed23827a443573af6ef039bb5e1db
6
+ metadata.gz: b0d94a34ddf968608f94116b6b3eeda9e8dda81161e650d2e09bf4222092279abdeb7992344bfa9a41e85a0fddd81a77fb7ad46791d2b1c30eeecd153718c767
7
+ data.tar.gz: a84e9fa58edfa28dd36208d78f490289c65c8e398afd55b773bf0f0da7257ab4434d0cb03e761fbabef42debace38d018e806046976d632712dac007c953b57a
data/CHANGELOG.md CHANGED
@@ -8,4 +8,9 @@
8
8
 
9
9
  ## 0.0.3
10
10
 
11
- - Add support to fill icon.
11
+ - Add support to fill icon.
12
+
13
+ ## 0.0.4
14
+
15
+ - Expose fill and viewBox.
16
+ - Internal refactorings.
@@ -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
- if bootstrap_icon = BootstrapIcons::BOOTSTRAP_ICONS_SYMBOLS[@symbol]
8
-
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
-
14
- @options = options
15
- @options.merge!({
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}>#{@path}</svg>"
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
- @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
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 @options[:"aria-label"].nil? && @options["aria-label"].nil?
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-#{@symbol} #{@options[:class]} ".strip
70
+ "bi bi-#{symbol} #{options[:class]} ".strip
59
71
  end
60
72
 
61
73
  def fill_with
62
- fill_option = @options[:fill]
63
- fill_option.nil? ? @fill : fill_option
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: @width,
70
- height: @height
81
+ width: width,
82
+ height: height
71
83
  }
72
84
 
73
85
  # Specific size
74
- unless @options[:width].nil? && @options[:height].nil?
75
- size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
76
- size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[: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 calculate_width(height)
85
- (height.to_i * @width) / @height
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(width)
89
- (width.to_i * @height) / @width
104
+ def calculate_height(custom_width)
105
+ (custom_width.to_i * height) / width
90
106
  end
91
107
  end
92
108
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapIcons
2
- VERSION = "0.0.3".freeze
2
+ VERSION = "0.0.4".freeze
3
3
  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.3
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-22 00:00:00.000000000 Z
11
+ date: 2020-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri