octicons 1.1.0 → 2.0.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.
@@ -1,10 +1,14 @@
1
1
  require "octicons/version"
2
2
  require "octicons/octicon"
3
3
  require "nokogiri"
4
+ require "json"
4
5
 
5
6
  module Octicons
6
7
  OCTICONS_SVG_PATH = File.join(File.dirname(__FILE__), "svg/*.svg")
7
8
 
9
+ KEYWORDS = JSON.parse(File.read(File.join(File.dirname(__FILE__), "keywords.json")))
10
+ CODEPOINTS = JSON.parse(File.read(File.join(File.dirname(__FILE__), "codepoints.json")))
11
+
8
12
  OCTICON_SYMBOLS = {}
9
13
  Dir[OCTICONS_SVG_PATH].each do |svg_path|
10
14
  id = File.basename(svg_path, ".svg")
@@ -1,36 +1,59 @@
1
1
  module Octicons
2
2
  class Octicon
3
3
 
4
- def initialize(options)
5
- @options = options
6
- if symbol = Octicons::OCTICON_SYMBOLS[@options[:symbol]]
7
- @path = symbol[:path]
8
- @width = symbol[:width]
9
- @height = symbol[:height]
10
-
11
- # create html_options from options, except for a few
12
- @html_options = @options.reject { |d| [:symbol, :size].include? d }
13
- @html_options.merge!({
4
+ attr_reader :path, :options, :width, :height, :symbol
5
+
6
+ def initialize(symbol, options = {})
7
+ @symbol = symbol.to_s
8
+ if octicon = Octicons::OCTICON_SYMBOLS[@symbol]
9
+
10
+ @path = octicon[:path]
11
+ @width = octicon[:width]
12
+ @height = octicon[:height]
13
+
14
+ @options = options
15
+ @options.merge!({
14
16
  :class => classes,
15
17
  :viewBox => viewbox,
16
18
  :version => "1.1"
17
19
  })
18
- @html_options.merge!(size)
19
- @html_options.merge!(a11y)
20
+ @options.merge!(size)
21
+ @options.merge!(a11y)
20
22
  else
21
- raise "Couldn't find octicon symbol for #{options[:symbol].inspect}"
23
+ raise "Couldn't find octicon symbol for #{@symbol.inspect}"
22
24
  end
23
25
  end
24
26
 
27
+ # Returns an string representing a <svg> tag
25
28
  def to_svg
26
29
  "<svg #{html_attributes}>#{@path}</svg>"
27
30
  end
28
31
 
32
+ # Returns an array of keywords similar to the icon
33
+ def keywords
34
+ Octicons::KEYWORDS[@symbol]["keywords"]
35
+ end
36
+
37
+ # Returns the decimal codepoint of the character
38
+ def decimal
39
+ Octicons::CODEPOINTS[@symbol]
40
+ end
41
+
42
+ # Returns the hexidecimal version of the character
43
+ def hexadecimal
44
+ decimal.to_s(16)
45
+ end
46
+
47
+ # Returns the unicode character
48
+ def character
49
+ [decimal].pack("U")
50
+ end
51
+
29
52
  private
30
53
 
31
54
  def html_attributes
32
55
  attrs = ""
33
- @html_options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
56
+ @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
34
57
  attrs.strip
35
58
  end
36
59
 
@@ -49,7 +72,7 @@ module Octicons
49
72
 
50
73
  # prepare the octicon class
51
74
  def classes
52
- "octicon octicon-#{@options[:symbol]} #{@options[:class]} ".strip
75
+ "octicon octicon-#{@symbol} #{@options[:class]} ".strip
53
76
  end
54
77
 
55
78
  def viewbox
@@ -63,18 +86,8 @@ module Octicons
63
86
  :height => @height
64
87
  }
65
88
 
66
- # When size is "large"
67
- if @options[:size] == "large"
68
- size[:width] = 2 * @width
69
- size[:height] = 2 * @height
70
-
71
- # When size is an integer
72
- elsif @options[:size].is_a?(Integer) || !!(@options[:size] =~ /\A[0-9]+\z/)
73
- size[:width] = calculate_width(@options[:size])
74
- size[:height] = @options[:size]
75
-
76
- # Specific size
77
- elsif !@options[:width].nil? || !@options[:height].nil?
89
+ # Specific size
90
+ unless @options[:width].nil? && @options[:height].nil?
78
91
  size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
79
92
  size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
80
93
  end
@@ -1,3 +1,3 @@
1
1
  module Octicons
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octicons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.6.3.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.3.1
27
27
  description: A package that distributes Octicons in a gem
@@ -31,9 +31,13 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/codepoints.json
37
+ - lib/keywords.json
38
+ - lib/octicons.rb
34
39
  - lib/octicons/octicon.rb
35
40
  - lib/octicons/version.rb
36
- - lib/octicons.rb
37
41
  - lib/svg/alert.svg
38
42
  - lib/svg/arrow-down.svg
39
43
  - lib/svg/arrow-left.svg
@@ -206,8 +210,6 @@ files:
206
210
  - lib/svg/watch.svg
207
211
  - lib/svg/x.svg
208
212
  - lib/svg/zap.svg
209
- - LICENSE
210
- - README.md
211
213
  homepage: https://github.com/primer/octicons_gem
212
214
  licenses:
213
215
  - MIT
@@ -218,17 +220,17 @@ require_paths:
218
220
  - lib
219
221
  required_ruby_version: !ruby/object:Gem::Requirement
220
222
  requirements:
221
- - - ">="
223
+ - - ! '>='
222
224
  - !ruby/object:Gem::Version
223
225
  version: '0'
224
226
  required_rubygems_version: !ruby/object:Gem::Requirement
225
227
  requirements:
226
- - - ">="
228
+ - - ! '>='
227
229
  - !ruby/object:Gem::Version
228
230
  version: '0'
229
231
  requirements: []
230
232
  rubyforge_project:
231
- rubygems_version: 2.0.14.1
233
+ rubygems_version: 2.4.5
232
234
  signing_key:
233
235
  specification_version: 4
234
236
  summary: GitHub's octicons gem