basicons 1.0.1
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 +7 -0
- data/lib/basicons/basicon.rb +111 -0
- data/lib/basicons/version.rb +3 -0
- data/lib/basicons.rb +15 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 39ac9c39a87e415dbbb109b87bbd686b5a64a73a69b36af4b5e184c154fef881
|
4
|
+
data.tar.gz: e640685c2fa60975f68475aab92ac71d5462f12390384ec3ec5e88392d705378
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63df6ac789c3b264d1ea3e03bf3950ca52c1aef1eaee5b49d51923133fc22c51614632486c1a6f7d463ab99629287f226770d8b9370fb6a8f1d96cc96cc05fb3
|
7
|
+
data.tar.gz: 15276f71908cf34d334388a708daec54988b86fda3dbb467a97c3b9d82ad97cd4753d4eac2068ecad8d63bb6a25d9a0ff9c00d62b30597e982c37ef7489da61e
|
@@ -0,0 +1,111 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
# basicon
|
5
|
+
# module Octicons
|
6
|
+
# class Octicon
|
7
|
+
# DEFAULT_HEIGHT = 16
|
8
|
+
|
9
|
+
# attr_reader :path, :options, :width, :height, :symbol, :keywords
|
10
|
+
|
11
|
+
# def initialize(symbol, options = {})
|
12
|
+
# @symbol = symbol.to_s
|
13
|
+
# if octicon = get_octicon(@symbol, options)
|
14
|
+
# @path = octicon["path"]
|
15
|
+
# @width = octicon["width"]
|
16
|
+
# @height = octicon["height"]
|
17
|
+
# @keywords = octicon["keywords"]
|
18
|
+
# @options = options.dup
|
19
|
+
# @options.merge!({
|
20
|
+
# class: classes,
|
21
|
+
# viewBox: viewbox,
|
22
|
+
# version: "1.1"
|
23
|
+
# })
|
24
|
+
# @options.merge!(size)
|
25
|
+
# @options.merge!(a11y)
|
26
|
+
# else
|
27
|
+
# raise "Couldn't find octicon symbol for #{@symbol.inspect}"
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
# # Returns an string representing a <svg> tag
|
32
|
+
# def to_svg
|
33
|
+
# "<svg #{html_attributes}>#{@path}</svg>"
|
34
|
+
# end
|
35
|
+
|
36
|
+
# private
|
37
|
+
|
38
|
+
# def html_attributes
|
39
|
+
# attrs = ""
|
40
|
+
# @options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
|
41
|
+
# attrs.strip
|
42
|
+
# end
|
43
|
+
|
44
|
+
# # add some accessibility features to svg
|
45
|
+
# def a11y
|
46
|
+
# accessible = {}
|
47
|
+
|
48
|
+
# if @options[:"aria-label"].nil? && @options["aria-label"].nil?
|
49
|
+
# accessible[:"aria-hidden"] = "true"
|
50
|
+
# else
|
51
|
+
# accessible[:role] = "img"
|
52
|
+
# end
|
53
|
+
|
54
|
+
# accessible
|
55
|
+
# end
|
56
|
+
|
57
|
+
# # prepare the octicon class
|
58
|
+
# def classes
|
59
|
+
# "octicon octicon-#{@symbol} #{@options[:class]} ".strip
|
60
|
+
# end
|
61
|
+
|
62
|
+
# def viewbox
|
63
|
+
# "0 0 #{@width} #{@height}"
|
64
|
+
# end
|
65
|
+
|
66
|
+
# # determine the height and width of the octicon based on :size option
|
67
|
+
# def size
|
68
|
+
# size = {
|
69
|
+
# width: @width,
|
70
|
+
# height: @height
|
71
|
+
# }
|
72
|
+
|
73
|
+
# # Specific size
|
74
|
+
# unless @options[:width].nil? && @options[:height].nil?
|
75
|
+
# size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
|
76
|
+
# size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
|
77
|
+
# end
|
78
|
+
|
79
|
+
# size
|
80
|
+
# end
|
81
|
+
|
82
|
+
# def calculate_width(height)
|
83
|
+
# (height.to_i * @width) / @height
|
84
|
+
# end
|
85
|
+
|
86
|
+
# def calculate_height(width)
|
87
|
+
# (width.to_i * @height) / @width
|
88
|
+
# end
|
89
|
+
|
90
|
+
# def get_octicon(symbol, options = {})
|
91
|
+
# if octicon = Octicons::OCTICON_SYMBOLS[symbol]
|
92
|
+
# # We're using width as an approximation for height if the height option is not passed in
|
93
|
+
# height = options[:height] || options[:width] || DEFAULT_HEIGHT
|
94
|
+
# natural_height = closest_natural_height(octicon["heights"].keys, height)
|
95
|
+
# return {
|
96
|
+
# "name" => octicon["name"],
|
97
|
+
# "keywords" => octicon["keywords"],
|
98
|
+
# "width" => octicon["heights"][natural_height.to_s]["width"].to_i,
|
99
|
+
# "height" => natural_height,
|
100
|
+
# "path" => octicon["heights"][natural_height.to_s]["path"]
|
101
|
+
# }
|
102
|
+
# end
|
103
|
+
# end
|
104
|
+
|
105
|
+
# def closest_natural_height(natural_heights, height)
|
106
|
+
# return natural_heights.reduce(natural_heights[0].to_i) do |acc, natural_height|
|
107
|
+
# natural_height.to_i <= height.to_i ? natural_height.to_i : acc
|
108
|
+
# end
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
# end
|
data/lib/basicons.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
require 'basicons/version'
|
5
|
+
require 'basicons/basicon'
|
6
|
+
|
7
|
+
module Basicons
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
# module Octicons
|
13
|
+
# file_data = File.read(File.join(File.dirname(__FILE__), "./build/data.json"))
|
14
|
+
# OCTICON_SYMBOLS = JSON.parse(file_data).freeze
|
15
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: basicons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- basicons's authors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/basicons.rb
|
20
|
+
- lib/basicons/basicon.rb
|
21
|
+
- lib/basicons/version.rb
|
22
|
+
homepage: https://basicons.xyz
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.1.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A simple basicons gem
|
45
|
+
test_files: []
|