forticons 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: 79a59826e00fecb1797a7d45728b744f963ff5d14f1e55563d0173e9b85b6636
4
- data.tar.gz: 1da920e31762df27e254b5c11ea7dd491a2e8382b459780d88a729cceac4b826
3
+ metadata.gz: 77b60bc441307613bc40a5fe23d0ba56fa22c6dbd5007f2a3d210cd6bebac87c
4
+ data.tar.gz: c22f5342d5e871bc8dc0f1e0769ba360d9f6b507dbeecc2d1465032588bfa0ff
5
5
  SHA512:
6
- metadata.gz: b42e4147527e1da5c333b17790e913e0808e95caf9a7665d948583e6a908a8f3f6036daca59b7a5afe368cf12995ff9d83adb864661662e02fa3a9c46dbd2bb4
7
- data.tar.gz: 596d3b3b7624e2dcb128b94d3201a01401f7c625993a0ceb1d127264f3b41910a3677ab2f8110af1acc519c2509ee5bf6ef0a751522cff5230dc2cb658442563
6
+ metadata.gz: d2a1ad75460301064b6f36d2123b23531e2d5c18a9ba099e272e334418b842876aefdbacff812a021179b404328ba0047d6a5ff45d27ac087c8b731e48e87fb7
7
+ data.tar.gz: 3cbbd257e5208c68212c6e9b2f7dc4b8d5d85e3d59c0aec942f1f64694e40c2a1571c5e4d7a680eef7f9eb14d29dd9b949a9d5c447f756a1351be2c06e8761a2
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 GitHub Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 GitHub Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,103 +1,103 @@
1
- # forticons
2
-
3
- [![Gem version](https://img.shields.io/gem/v/forticons.svg)](https://rubygems.org/gems/forticons)
4
-
5
- ## Install
6
-
7
- Add this to your `Gemfile`
8
-
9
- ```rb
10
- gem 'forticons'
11
- ```
12
-
13
- Then `bundle install`.
14
-
15
- If using a framework like Rails, please follow the [installation instructions](https://primer.style/view-components/#installation) in the [Primer ViewComponents](https://primer.style/view-components) documentation.
16
-
17
- ## Usage
18
-
19
- ```rb
20
- require 'forticons'
21
- icon = Forticons::Forticon.new("x")
22
- icon.to_svg
23
- # <svg class="forticon forticon-x" viewBox="0 0 16 16" width="16" height="16" version="1.1" "aria-hidden"="true"><path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
24
- ```
25
-
26
- ## Documentation
27
-
28
- The `Forticon` class takes two arguments. The first is the symbol of the icon, and the second is a hash of arguments representing html attributes
29
-
30
- ### `symbol` _(required)_
31
-
32
- This is the name of the forticon you want to use. For example `alert`. [Full list of icons](/)
33
-
34
- ### Options
35
-
36
- * `:height` - When setting the height to a number, the icon will scale to that size. For example, passing `32`, will calculate the width based on the icon's natural size.
37
- * `:width` - When setting the width to a number, the icon will scale to that size. For example, passing `32`, will calculate the width based on the icon's natural size.
38
-
39
- If both `:width, :height` are passed into the options hash, then the icon will be sized exactly at those dimensions.
40
-
41
- ### Attributes
42
-
43
- Once initialized, you can read a few properties from the icon.
44
-
45
- #### `symbol`
46
-
47
- Returns the string of the symbol name
48
-
49
- ```rb
50
- icon = Forticons::Forticon.new("x")
51
- icon.symbol
52
- # "x"
53
- ```
54
-
55
- #### `path`
56
-
57
- Path returns the string representation of the path of the icon.
58
-
59
- ```rb
60
- icon = Forticons::Forticon.new("x")
61
- icon.path
62
- # <path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path>
63
- ```
64
-
65
- #### `options`
66
-
67
- This is a hash of all the `options` that will be added to the output tag.
68
-
69
- ```rb
70
- icon = Forticons::Forticon.new("x")
71
- icon.options
72
- # {:class=>"forticon forticon-x", :viewBox=>"0 0 12 16", :version=>"1.1", :width=>12, :height=>16, :"aria-hidden"=>"true"}
73
- ```
74
-
75
- #### `width`
76
-
77
- Width is the icon's true width. Based on the svg view box width. _Note, this doesn't change if you scale it up with size options, it only is the natural width of the icon_
78
-
79
- #### `height`
80
-
81
- Height is the icon's true height. Based on the svg view box height. _Note, this doesn't change if you scale it up with size options, it only is the natural height of the icon_
82
-
83
- #### `keywords`
84
-
85
- Returns an array of keywords for the icon. The data comes from the [data file in lib](../data.json). Consider contributing more aliases for the icons.
86
-
87
- ```rb
88
- icon = Forticons::Forticon.new("x")
89
- icon.keywords
90
- # ["remove", "close", "delete"]
91
- ```
92
-
93
- ### Methods
94
-
95
- #### `to_svg`
96
-
97
- Returns a string of the svg tag
98
-
99
- ```rb
100
- icon = Forticons::Forticon.new("x")
101
- icon.to_svg
102
- # <svg class="forticon forticon-x" viewBox="0 0 16 16" width="16" height="16" version="1.1" "aria-hidden"="true"><path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
103
- ```
1
+ # forticons
2
+
3
+ [![Gem version](https://img.shields.io/gem/v/forticons.svg)](https://rubygems.org/gems/forticons)
4
+
5
+ ## Install
6
+
7
+ Add this to your `Gemfile`
8
+
9
+ ```rb
10
+ gem 'forticons'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ If using a framework like Rails, please follow the [installation instructions](https://primer.style/view-components/#installation) in the [Primer ViewComponents](https://primer.style/view-components) documentation.
16
+
17
+ ## Usage
18
+
19
+ ```rb
20
+ require 'forticons'
21
+ icon = Forticons::Forticon.new("x")
22
+ icon.to_svg
23
+ # <svg class="forticon forticon-x" viewBox="0 0 16 16" width="16" height="16" version="1.1" "aria-hidden"="true"><path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
24
+ ```
25
+
26
+ ## Documentation
27
+
28
+ The `Forticon` class takes two arguments. The first is the symbol of the icon, and the second is a hash of arguments representing html attributes
29
+
30
+ ### `symbol` _(required)_
31
+
32
+ This is the name of the forticon you want to use. For example `alert`. [Full list of icons](/)
33
+
34
+ ### Options
35
+
36
+ * `:height` - When setting the height to a number, the icon will scale to that size. For example, passing `32`, will calculate the width based on the icon's natural size.
37
+ * `:width` - When setting the width to a number, the icon will scale to that size. For example, passing `32`, will calculate the width based on the icon's natural size.
38
+
39
+ If both `:width, :height` are passed into the options hash, then the icon will be sized exactly at those dimensions.
40
+
41
+ ### Attributes
42
+
43
+ Once initialized, you can read a few properties from the icon.
44
+
45
+ #### `symbol`
46
+
47
+ Returns the string of the symbol name
48
+
49
+ ```rb
50
+ icon = Forticons::Forticon.new("x")
51
+ icon.symbol
52
+ # "x"
53
+ ```
54
+
55
+ #### `path`
56
+
57
+ Path returns the string representation of the path of the icon.
58
+
59
+ ```rb
60
+ icon = Forticons::Forticon.new("x")
61
+ icon.path
62
+ # <path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path>
63
+ ```
64
+
65
+ #### `options`
66
+
67
+ This is a hash of all the `options` that will be added to the output tag.
68
+
69
+ ```rb
70
+ icon = Forticons::Forticon.new("x")
71
+ icon.options
72
+ # {:class=>"forticon forticon-x", :viewBox=>"0 0 12 16", :version=>"1.1", :width=>12, :height=>16, :"aria-hidden"=>"true"}
73
+ ```
74
+
75
+ #### `width`
76
+
77
+ Width is the icon's true width. Based on the svg view box width. _Note, this doesn't change if you scale it up with size options, it only is the natural width of the icon_
78
+
79
+ #### `height`
80
+
81
+ Height is the icon's true height. Based on the svg view box height. _Note, this doesn't change if you scale it up with size options, it only is the natural height of the icon_
82
+
83
+ #### `keywords`
84
+
85
+ Returns an array of keywords for the icon. The data comes from the [data file in lib](../data.json). Consider contributing more aliases for the icons.
86
+
87
+ ```rb
88
+ icon = Forticons::Forticon.new("x")
89
+ icon.keywords
90
+ # ["remove", "close", "delete"]
91
+ ```
92
+
93
+ ### Methods
94
+
95
+ #### `to_svg`
96
+
97
+ Returns a string of the svg tag
98
+
99
+ ```rb
100
+ icon = Forticons::Forticon.new("x")
101
+ icon.to_svg
102
+ # <svg class="forticon forticon-x" viewBox="0 0 16 16" width="16" height="16" version="1.1" "aria-hidden"="true"><path d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48z"></path></svg>
103
+ ```
@@ -1,107 +1,107 @@
1
- module Forticons
2
- class Forticon
3
- DEFAULT_HEIGHT = 16
4
-
5
- attr_reader :path, :options, :width, :height, :symbol, :keywords
6
-
7
- def initialize(symbol, options = {})
8
- @symbol = symbol.to_s
9
- if forticon = get_forticon(@symbol, options)
10
- @path = forticon["path"]
11
- @width = forticon["width"]
12
- @height = forticon["height"]
13
- @keywords = forticon["keywords"]
14
- @options = options.dup
15
- @options.merge!({
16
- class: classes,
17
- viewBox: viewbox,
18
- version: "1.1"
19
- })
20
- @options.merge!(size)
21
- @options.merge!(a11y)
22
- else
23
- raise "Couldn't find forticon symbol for #{@symbol.inspect}"
24
- end
25
- end
26
-
27
- # Returns an string representing a <svg> tag
28
- def to_svg
29
- "<svg #{html_attributes}>#{@path}</svg>"
30
- end
31
-
32
- private
33
-
34
- def html_attributes
35
- attrs = ""
36
- @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
37
- attrs.strip
38
- end
39
-
40
- # add some accessibility features to svg
41
- def a11y
42
- accessible = {}
43
-
44
- if @options[:"aria-label"].nil? && @options["aria-label"].nil?
45
- accessible[:"aria-hidden"] = "true"
46
- else
47
- accessible[:role] = "img"
48
- end
49
-
50
- accessible
51
- end
52
-
53
- # prepare the forticon class
54
- def classes
55
- "forticon forticon-#{@symbol} #{@options[:class]} ".strip
56
- end
57
-
58
- def viewbox
59
- "0 0 #{@width} #{@height}"
60
- end
61
-
62
- # determine the height and width of the forticon based on :size option
63
- def size
64
- size = {
65
- width: @width,
66
- height: @height
67
- }
68
-
69
- # Specific size
70
- unless @options[:width].nil? && @options[:height].nil?
71
- size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
72
- size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
73
- end
74
-
75
- size
76
- end
77
-
78
- def calculate_width(height)
79
- (height.to_i * @width) / @height
80
- end
81
-
82
- def calculate_height(width)
83
- (width.to_i * @height) / @width
84
- end
85
-
86
- def get_forticon(symbol, options = {})
87
- if forticon = Forticons::FORTICON_SYMBOLS[symbol]
88
- # We're using width as an approximation for height if the height option is not passed in
89
- height = options[:height] || options[:width] || DEFAULT_HEIGHT
90
- natural_height = closest_natural_height(forticon["heights"].keys, height)
91
- return {
92
- "name" => forticon["name"],
93
- "keywords" => forticon["keywords"],
94
- "width" => forticon["heights"][natural_height.to_s]["width"].to_i,
95
- "height" => natural_height,
96
- "path" => forticon["heights"][natural_height.to_s]["path"]
97
- }
98
- end
99
- end
100
-
101
- def closest_natural_height(natural_heights, height)
102
- return natural_heights.reduce(natural_heights[0].to_i) do |acc, natural_height|
103
- natural_height.to_i <= height.to_i ? natural_height.to_i : acc
104
- end
105
- end
106
- end
107
- end
1
+ module Forticons
2
+ class Forticon
3
+ DEFAULT_HEIGHT = 16
4
+
5
+ attr_reader :path, :options, :width, :height, :symbol, :keywords
6
+
7
+ def initialize(symbol, options = {})
8
+ @symbol = symbol.to_s
9
+ if forticon = get_forticon(@symbol, options)
10
+ @path = forticon["path"]
11
+ @width = forticon["width"]
12
+ @height = forticon["height"]
13
+ @keywords = forticon["keywords"]
14
+ @options = options.dup
15
+ @options.merge!({
16
+ class: classes,
17
+ viewBox: viewbox,
18
+ version: "1.1"
19
+ })
20
+ @options.merge!(size)
21
+ @options.merge!(a11y)
22
+ else
23
+ raise "Couldn't find forticon symbol for #{@symbol.inspect}"
24
+ end
25
+ end
26
+
27
+ # Returns an string representing a <svg> tag
28
+ def to_svg
29
+ "<svg #{html_attributes}>#{@path}</svg>"
30
+ end
31
+
32
+ private
33
+
34
+ def html_attributes
35
+ attrs = ""
36
+ @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
37
+ attrs.strip
38
+ end
39
+
40
+ # add some accessibility features to svg
41
+ def a11y
42
+ accessible = {}
43
+
44
+ if @options[:"aria-label"].nil? && @options["aria-label"].nil?
45
+ accessible[:"aria-hidden"] = "true"
46
+ else
47
+ accessible[:role] = "img"
48
+ end
49
+
50
+ accessible
51
+ end
52
+
53
+ # prepare the forticon class
54
+ def classes
55
+ "forticon forticon-#{@symbol} #{@options[:class]} ".strip
56
+ end
57
+
58
+ def viewbox
59
+ "0 0 #{@width} #{@height}"
60
+ end
61
+
62
+ # determine the height and width of the forticon based on :size option
63
+ def size
64
+ size = {
65
+ width: @width,
66
+ height: @height
67
+ }
68
+
69
+ # Specific size
70
+ unless @options[:width].nil? && @options[:height].nil?
71
+ size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
72
+ size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
73
+ end
74
+
75
+ size
76
+ end
77
+
78
+ def calculate_width(height)
79
+ (height.to_i * @width) / @height
80
+ end
81
+
82
+ def calculate_height(width)
83
+ (width.to_i * @height) / @width
84
+ end
85
+
86
+ def get_forticon(symbol, options = {})
87
+ if forticon = Forticons::FORTICON_SYMBOLS[symbol]
88
+ # We're using width as an approximation for height if the height option is not passed in
89
+ height = options[:height] || options[:width] || DEFAULT_HEIGHT
90
+ natural_height = closest_natural_height(forticon["heights"].keys, height)
91
+ return {
92
+ "name" => forticon["name"],
93
+ "keywords" => forticon["keywords"],
94
+ "width" => forticon["heights"][natural_height.to_s]["width"].to_i,
95
+ "height" => natural_height,
96
+ "path" => forticon["heights"][natural_height.to_s]["path"]
97
+ }
98
+ end
99
+ end
100
+
101
+ def closest_natural_height(natural_heights, height)
102
+ return natural_heights.reduce(natural_heights[0].to_i) do |acc, natural_height|
103
+ natural_height.to_i <= height.to_i ? natural_height.to_i : acc
104
+ end
105
+ end
106
+ end
107
+ end
@@ -1,3 +1,3 @@
1
- module Forticons
2
- VERSION = "0.0.3".freeze
3
- end
1
+ module Forticons
2
+ VERSION = "0.0.4".freeze
3
+ end
data/lib/forticons.rb CHANGED
@@ -1,8 +1,8 @@
1
- require "forticons/version"
2
- require "forticons/forticon"
3
- require "json"
4
-
5
- module Forticons
6
- file_data = File.read(File.join(File.dirname(__FILE__), "./build/data.json"))
7
- FORTICON_SYMBOLS = JSON.parse(file_data).freeze
8
- end
1
+ require "forticons/version"
2
+ require "forticons/forticon"
3
+ require "json"
4
+
5
+ module Forticons
6
+ file_data = File.read(File.join(File.dirname(__FILE__), "./build/data.json"))
7
+ FORTICON_SYMBOLS = JSON.parse(file_data).freeze
8
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forticons
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
  - anosim114
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2023-12-02 00:00:00.000000000 Z
@@ -27,7 +27,7 @@ homepage: https://github.com/anosim114/forticons
27
27
  licenses:
28
28
  - MIT
29
29
  metadata: {}
30
- post_install_message:
30
+ post_install_message:
31
31
  rdoc_options: []
32
32
  require_paths:
33
33
  - lib
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubygems_version: 3.4.10
46
- signing_key:
46
+ signing_key:
47
47
  specification_version: 4
48
48
  summary: Octicons like FontAwesome icon library
49
49
  test_files: []