basicons 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- if basicon = find_basicon(@symbol, options)
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 "Couldn't find basicon symbol for #{@symbol.inspect}"
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}>#{@path}</svg>"
30
+ "<svg #{html_attributes}>#{@data}</svg>"
32
31
  end
33
32
 
34
33
  private
35
34
 
36
- def html_attributes
37
-
38
- # attrs = ""
39
- # @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
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
@@ -1,3 +1,3 @@
1
1
  module Basicons
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basicons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - basicons's authors