forticons 0.0.3 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79a59826e00fecb1797a7d45728b744f963ff5d14f1e55563d0173e9b85b6636
4
- data.tar.gz: 1da920e31762df27e254b5c11ea7dd491a2e8382b459780d88a729cceac4b826
3
+ metadata.gz: d49d670571fabb9f19ebd5504db77e539ec057b0c8b698909f054ac41f1fcb4d
4
+ data.tar.gz: e1507fb4094794f888975b962ba575fa6aac510044eb299bed7ea319b79d7690
5
5
  SHA512:
6
- metadata.gz: b42e4147527e1da5c333b17790e913e0808e95caf9a7665d948583e6a908a8f3f6036daca59b7a5afe368cf12995ff9d83adb864661662e02fa3a9c46dbd2bb4
7
- data.tar.gz: 596d3b3b7624e2dcb128b94d3201a01401f7c625993a0ceb1d127264f3b41910a3677ab2f8110af1acc519c2509ee5bf6ef0a751522cff5230dc2cb658442563
6
+ metadata.gz: 19de8ed75e6b347e1fa1df9657c54185d4e029bd1367969ab756cde3cb39b534e6233c89bda186d72c4ddc8c1acbb95675afb7e8f49992012ea6695e2130c3d9
7
+ data.tar.gz: 9e0980764ffc6c19989eb709cad61edf7dd68eb32068cf8db96c64e794d7890e3d0a537ad146c954f78b775f13f0f3a9b6524cdd92a9d16d0d8b7262da0f2c9f
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.1.0".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,14 +1,14 @@
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.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - anosim114
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-02 00:00:00.000000000 Z
11
+ date: 2025-04-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A package that distributes FontAwesome icons in a gem
14
14
  email:
@@ -19,7 +19,6 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - LICENSE
21
21
  - README.md
22
- - lib/build/data.json
23
22
  - lib/forticons.rb
24
23
  - lib/forticons/forticon.rb
25
24
  - lib/forticons/version.rb
@@ -27,7 +26,7 @@ homepage: https://github.com/anosim114/forticons
27
26
  licenses:
28
27
  - MIT
29
28
  metadata: {}
30
- post_install_message:
29
+ post_install_message:
31
30
  rdoc_options: []
32
31
  require_paths:
33
32
  - lib
@@ -42,8 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
41
  - !ruby/object:Gem::Version
43
42
  version: '0'
44
43
  requirements: []
45
- rubygems_version: 3.4.10
46
- signing_key:
44
+ rubygems_version: 3.5.16
45
+ signing_key:
47
46
  specification_version: 4
48
47
  summary: Octicons like FontAwesome icon library
49
48
  test_files: []