basicons 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/data.json +320 -320
- data/lib/basicons/basicon.rb +28 -51
- data/lib/basicons/version.rb +1 -1
- metadata +1 -1
data/lib/basicons/basicon.rb
CHANGED
@@ -1,74 +1,51 @@
|
|
1
1
|
module Basicons
|
2
2
|
class Basicon
|
3
3
|
DEFAULT_HEIGHT = 16
|
4
|
-
|
5
|
-
attr_reader :data, :symbol
|
6
|
-
attr_reader :width, :height, :options
|
4
|
+
attr_reader :data, :symbol, :options
|
7
5
|
|
8
6
|
def initialize(symbol, options = {})
|
9
7
|
@symbol = symbol.to_s
|
10
|
-
|
11
|
-
|
8
|
+
@options = options.dup
|
9
|
+
|
10
|
+
if @data = Basicons::SVG_DATA[@symbol]
|
11
|
+
@options.merge!({
|
12
|
+
class: classes,
|
13
|
+
width: svg_size,
|
14
|
+
height: svg_size,
|
15
|
+
viewBox: '0 0 24 24',
|
16
|
+
stroke: 'currentColor',
|
17
|
+
fill: 'none'
|
18
|
+
})
|
19
|
+
|
20
|
+
@options['stroke-width'] = 2
|
21
|
+
@options['stroke-linecap'] = 'round'
|
22
|
+
@options['stroke-linejoin'] = 'round'
|
23
|
+
@options['xmlns'] = 'http://www.w3.org/2000/svg'
|
12
24
|
else
|
13
|
-
raise "
|
25
|
+
raise "<#{@symbol}> not found"
|
14
26
|
end
|
15
|
-
|
16
|
-
# @path = octicon["path"]
|
17
|
-
# @width = octicon["width"]
|
18
|
-
# @height = octicon["height"]
|
19
|
-
# @options = options.dup
|
20
|
-
# @options.merge!({
|
21
|
-
# class: classes,
|
22
|
-
# viewBox: viewbox,
|
23
|
-
# version: "1.1"
|
24
|
-
# })
|
25
|
-
# @options.merge!(size)
|
26
|
-
# @options.merge!(a11y)
|
27
|
-
|
28
27
|
end
|
29
28
|
|
30
29
|
def to_svg
|
31
|
-
"<svg #{html_attributes}>#{@
|
30
|
+
"<svg #{html_attributes}>#{@data}</svg>"
|
32
31
|
end
|
33
32
|
|
34
33
|
private
|
35
34
|
|
36
|
-
def html_attributes
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# attrs.strip
|
35
|
+
def html_attributes(result = '')
|
36
|
+
@options.each { |key, value| result += "#{key}=\"#{value}\" " }
|
37
|
+
result.strip
|
38
|
+
end
|
41
39
|
|
40
|
+
def svg_size
|
41
|
+
return @size unless @size.nil?
|
42
|
+
@size = @options[:size].to_i
|
43
|
+
@size = 24 if @size.zero?
|
44
|
+
@size
|
42
45
|
end
|
43
46
|
|
44
47
|
def classes
|
45
48
|
"basicon basicon-#{@symbol} #{@options[:class]}".strip
|
46
49
|
end
|
47
|
-
|
48
|
-
def viewbox
|
49
|
-
"0 0 #{@width} #{@height}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def find_basicon(symbol, options = {})
|
53
|
-
basicon = Basicons::SVG_DATA[symbol]
|
54
|
-
return if basicon.nil?
|
55
|
-
|
56
|
-
{}
|
57
|
-
|
58
|
-
# return {
|
59
|
-
# "name" => octicon["name"],
|
60
|
-
# "width" => octicon["heights"][natural_height.to_s]["width"].to_i,
|
61
|
-
# "height" => natural_height,
|
62
|
-
# "path" => octicon["heights"][natural_height.to_s]["path"]
|
63
|
-
# }
|
64
|
-
end
|
65
50
|
end
|
66
51
|
end
|
67
|
-
|
68
|
-
# def size
|
69
|
-
# size = {
|
70
|
-
# width: @width,
|
71
|
-
# height: @height
|
72
|
-
# }
|
73
|
-
# size
|
74
|
-
# end
|
data/lib/basicons/version.rb
CHANGED