crypticons 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +112 -0
- data/lib/crypticons.rb +8 -0
- data/lib/crypticons/crypticon.rb +88 -0
- data/lib/crypticons/version.rb +3 -0
- data/lib/data.json +1 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f3e63d9adeee648934bf87f87ab909f68991afe
|
4
|
+
data.tar.gz: fe7264ddd976d52115bbc69a9aada16996380fe9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9020a553edc89780672f6dc48461ba8fd364b40d9798fa150b63b8892bc6ab05332369907397ac366c30f1b3aa325911186a1dc4a59693e2b1a2749355456d5
|
7
|
+
data.tar.gz: f2d27612fd18e3e4a21f51226c18545429f6deeafada7040603a085ab82c5eb853a51af7fef00361e8e9371820996adb40160302d7a283562c9836340c5760a5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Mitchell Cash
|
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
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Crypticons gem
|
2
|
+
|
3
|
+
[![Gem version](https://img.shields.io/gem/v/crypticons.svg)](https://rubygems.org/gems/crypticons)
|
4
|
+
[![Build Status](https://travis-ci.org/mitchellcash/crypticons.svg?branch=master)](https://travis-ci.org/mitchellcash/crypticons)
|
5
|
+
|
6
|
+
> Crypticons gem to distribute crypticons svg
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Add this to your `Gemfile`
|
11
|
+
|
12
|
+
```rb
|
13
|
+
gem 'crypticons'
|
14
|
+
```
|
15
|
+
|
16
|
+
Then `bundle install`.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```rb
|
21
|
+
require 'crypticons'
|
22
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
23
|
+
icon.to_svg
|
24
|
+
# <svg class="crypticon crypticon-bitcoin" viewBox="0 0 16 16" width="16" height="16" version="1.1" aria-hidden="true"><path d="M13.638 9.521A5.906 5.906 0 1 1 2.177 6.664 5.906 5.906 0 0 1 13.638 9.52z"></path><path d="M10.512 7.25c.118-.785-.48-1.208-1.299-1.49l.266-1.065-.649-.161-.258 1.036c-.17-.042-.345-.082-.52-.122l.261-1.043-.648-.162L7.4 5.308c-.142-.033-.28-.064-.414-.098v-.003l-.894-.223-.172.692s.48.11.47.117c.263.066.31.24.303.377L6.39 7.383a.537.537 0 0 1 .068.022l-.069-.017-.424 1.7c-.032.079-.113.199-.297.153.007.01-.47-.117-.47-.117l-.323.742.844.21.462.12-.268 1.076.647.162.266-1.066c.177.048.348.092.516.134l-.264 1.06.648.162.268-1.075c1.105.21 1.937.125 2.286-.875.282-.805-.014-1.269-.595-1.572.423-.097.742-.376.827-.951zm-1.48 2.077c-.2.805-1.556.37-1.995.261l.355-1.427c.44.11 1.849.327 1.64 1.166zm.2-2.088c-.183.732-1.31.36-1.677.269l.323-1.294c.366.091 1.544.261 1.354 1.025z"></path></svg>
|
25
|
+
```
|
26
|
+
|
27
|
+
## Documentation
|
28
|
+
|
29
|
+
The `Crypticon` class takes two arguments. The first is the symbol of the icon, and the second is a hash of arguments representing html attributes
|
30
|
+
|
31
|
+
#### `symbol` _(required)_
|
32
|
+
|
33
|
+
This is the name of the crypticon you want to use. For example `bitcoin`.
|
34
|
+
|
35
|
+
#### Options
|
36
|
+
|
37
|
+
* `: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.
|
38
|
+
* `: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.
|
39
|
+
|
40
|
+
If both `:width, :height` are passed into the options hash, then the icon will be sized exactly at those dimensions.
|
41
|
+
|
42
|
+
#### Attributes
|
43
|
+
|
44
|
+
Once initialized, you can read a few properties from the icon.
|
45
|
+
|
46
|
+
##### `symbol`
|
47
|
+
|
48
|
+
Returns the string of the symbol name
|
49
|
+
|
50
|
+
```rb
|
51
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
52
|
+
icon.symbol
|
53
|
+
# "bitcoin"
|
54
|
+
```
|
55
|
+
|
56
|
+
##### `path`
|
57
|
+
|
58
|
+
Path returns the string representation of the path of the icon.
|
59
|
+
|
60
|
+
```rb
|
61
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
62
|
+
icon.path
|
63
|
+
# <path d="M13.638 9.521A5.906 5.906 0 1 1 2.177 6.664 5.906 5.906 0 0 1 13.638 9.52z"/><path d="M10.512 7.25c.118-.785-.48-1.208-1.299-1.49l.266-1.065-.649-.161-.258 1.036c-.17-.042-.345-.082-.52-.122l.261-1.043-.648-.162L7.4 5.308c-.142-.033-.28-.064-.414-.098v-.003l-.894-.223-.172.692s.48.11.47.117c.263.066.31.24.303.377L6.39 7.383a.537.537 0 0 1 .068.022l-.069-.017-.424 1.7c-.032.079-.113.199-.297.153.007.01-.47-.117-.47-.117l-.323.742.844.21.462.12-.268 1.076.647.162.266-1.066c.177.048.348.092.516.134l-.264 1.06.648.162.268-1.075c1.105.21 1.937.125 2.286-.875.282-.805-.014-1.269-.595-1.572.423-.097.742-.376.827-.951zm-1.48 2.077c-.2.805-1.556.37-1.995.261l.355-1.427c.44.11 1.849.327 1.64 1.166zm.2-2.088c-.183.732-1.31.36-1.677.269l.323-1.294c.366.091 1.544.261 1.354 1.025z"/>
|
64
|
+
```
|
65
|
+
|
66
|
+
##### `options`
|
67
|
+
|
68
|
+
This is a hash of all the `options` that will be added to the output tag.
|
69
|
+
|
70
|
+
```rb
|
71
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
72
|
+
icon.options
|
73
|
+
# {:class=>"crypticon crypticon-bitcoin", :viewBox=>"0 0 16 16", :version=>"1.1", :width=>16, :height=>16, :"aria-hidden"=>"true"}
|
74
|
+
```
|
75
|
+
|
76
|
+
##### `width`
|
77
|
+
|
78
|
+
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_
|
79
|
+
|
80
|
+
##### `height`
|
81
|
+
|
82
|
+
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_
|
83
|
+
|
84
|
+
##### `keywords`
|
85
|
+
|
86
|
+
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.
|
87
|
+
|
88
|
+
```rb
|
89
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
90
|
+
icon.keywords
|
91
|
+
# ["bitcoin"]
|
92
|
+
```
|
93
|
+
|
94
|
+
#### Methods
|
95
|
+
|
96
|
+
##### `to_svg`
|
97
|
+
|
98
|
+
Returns a string of the svg tag
|
99
|
+
|
100
|
+
```rb
|
101
|
+
icon = Crypticons::Crypticon.new("bitcoin")
|
102
|
+
icon.to_svg
|
103
|
+
# <svg class="crypticon crypticon-bitcoin" viewBox="0 0 16 16" width="16" height="16" version="1.1" aria-hidden="true"><path d="M13.638 9.521A5.906 5.906 0 1 1 2.177 6.664 5.906 5.906 0 0 1 13.638 9.52z"></path><path d="M10.512 7.25c.118-.785-.48-1.208-1.299-1.49l.266-1.065-.649-.161-.258 1.036c-.17-.042-.345-.082-.52-.122l.261-1.043-.648-.162L7.4 5.308c-.142-.033-.28-.064-.414-.098v-.003l-.894-.223-.172.692s.48.11.47.117c.263.066.31.24.303.377L6.39 7.383a.537.537 0 0 1 .068.022l-.069-.017-.424 1.7c-.032.079-.113.199-.297.153.007.01-.47-.117-.47-.117l-.323.742.844.21.462.12-.268 1.076.647.162.266-1.066c.177.048.348.092.516.134l-.264 1.06.648.162.268-1.075c1.105.21 1.937.125 2.286-.875.282-.805-.014-1.269-.595-1.572.423-.097.742-.376.827-.951zm-1.48 2.077c-.2.805-1.556.37-1.995.261l.355-1.427c.44.11 1.849.327 1.64 1.166zm.2-2.088c-.183.732-1.31.36-1.677.269l.323-1.294c.366.091 1.544.261 1.354 1.025z"></path></svg>
|
104
|
+
```
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
(c) Mitchell Cash
|
109
|
+
|
110
|
+
[MIT](./LICENSE)
|
111
|
+
|
112
|
+
[crypticons]: https://github.com/mitchellcash/crypticons
|
data/lib/crypticons.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Crypticons
|
2
|
+
class Crypticon
|
3
|
+
|
4
|
+
attr_reader :path, :options, :width, :height, :symbol, :keywords
|
5
|
+
|
6
|
+
def initialize(symbol, options = {})
|
7
|
+
@symbol = symbol.to_s
|
8
|
+
if crypticon = Crypticons::CRYPTICON_SYMBOLS[@symbol]
|
9
|
+
|
10
|
+
@path = crypticon["path"]
|
11
|
+
@width = crypticon["width"].to_i
|
12
|
+
@height = crypticon["height"].to_i
|
13
|
+
|
14
|
+
@keywords = crypticon["keywords"]
|
15
|
+
|
16
|
+
@options = options
|
17
|
+
@options.merge!({
|
18
|
+
class: classes,
|
19
|
+
viewBox: viewbox,
|
20
|
+
version: "1.1"
|
21
|
+
})
|
22
|
+
@options.merge!(size)
|
23
|
+
@options.merge!(a11y)
|
24
|
+
else
|
25
|
+
raise "Couldn't find crypticon symbol for #{@symbol.inspect}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns an string representing a <svg> tag
|
30
|
+
def to_svg
|
31
|
+
"<svg #{html_attributes}>#{@path}</svg>"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def html_attributes
|
37
|
+
attrs = ""
|
38
|
+
@options.each { |attr, value| attrs += "#{attr}=\"#{value}\" " }
|
39
|
+
attrs.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
# add some accessibility features to svg
|
43
|
+
def a11y
|
44
|
+
accessible = {}
|
45
|
+
|
46
|
+
if @options[:'aria-label'].nil?
|
47
|
+
accessible[:'aria-hidden'] = "true"
|
48
|
+
else
|
49
|
+
accessible[:role] = "img"
|
50
|
+
end
|
51
|
+
|
52
|
+
accessible
|
53
|
+
end
|
54
|
+
|
55
|
+
# prepare the crypticon class
|
56
|
+
def classes
|
57
|
+
"crypticon crypticon-#{@symbol} #{@options[:class]} ".strip
|
58
|
+
end
|
59
|
+
|
60
|
+
def viewbox
|
61
|
+
"0 0 #{@width} #{@height}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# determine the height and width of the crypticon based on :size option
|
65
|
+
def size
|
66
|
+
size = {
|
67
|
+
width: @width,
|
68
|
+
height: @height
|
69
|
+
}
|
70
|
+
|
71
|
+
# Specific size
|
72
|
+
unless @options[:width].nil? && @options[:height].nil?
|
73
|
+
size[:width] = @options[:width].nil? ? calculate_width(@options[:height]) : @options[:width]
|
74
|
+
size[:height] = @options[:height].nil? ? calculate_height(@options[:width]) : @options[:height]
|
75
|
+
end
|
76
|
+
|
77
|
+
size
|
78
|
+
end
|
79
|
+
|
80
|
+
def calculate_width(height)
|
81
|
+
(height.to_i * @width) / @height
|
82
|
+
end
|
83
|
+
|
84
|
+
def calculate_height(width)
|
85
|
+
(width.to_i * @height) / @width
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/data.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"bitcoin":{"keywords":["bitcoin"],"path":"<path fill=\"#F7931A\" fill-rule=\"nonzero\" d=\"M13.638 9.521A5.906 5.906 0 1 1 2.177 6.664 5.906 5.906 0 0 1 13.638 9.52zm-3.126-2.27c.118-.786-.48-1.209-1.299-1.49l.266-1.066-.649-.161-.258 1.036c-.17-.042-.345-.082-.52-.122l.261-1.043-.648-.162L7.4 5.308c-.142-.033-.28-.064-.414-.098v-.003l-.894-.223-.172.692s.48.11.47.117c.263.066.31.24.303.377L6.39 7.383a.537.537 0 0 1 .068.022l-.069-.017-.424 1.7c-.032.079-.113.199-.297.153.007.01-.47-.117-.47-.117l-.323.742.844.21.462.12-.268 1.076.647.162.266-1.066c.177.048.348.092.516.134l-.264 1.06.648.162.268-1.075c1.105.21 1.937.125 2.286-.875.282-.805-.014-1.269-.595-1.572.423-.097.742-.376.827-.951zm-1.48 2.076c-.2.805-1.556.37-1.995.261l.355-1.427c.44.11 1.849.327 1.64 1.166zm.2-2.088c-.183.732-1.31.36-1.677.269l.323-1.294c.366.091 1.544.261 1.354 1.025z\"/>","height":"16","width":"16"},"litecoin":{"keywords":["litecoin"],"path":"<path fill=\"#BEBEBE\" fill-rule=\"nonzero\" d=\"M13.967 8A5.968 5.968 0 1 1 2.031 8a5.968 5.968 0 0 1 11.936 0M7.65 9.595l.388-1.46.918-.336.228-.857-.008-.022-.903.33.65-2.45H7.079l-.852 3.198-.71.26-.235.884.71-.26-.502 1.886h4.913l.315-1.173H7.65\"/>","height":"16","width":"16"},"ethereum":{"keywords":["ethereum"],"path":"<g fill=\"none\" fill-rule=\"nonzero\"><path fill=\"#343434\" d=\"M7.682 2l-.08.273v7.933l.08.08 3.683-2.176z\"/><path fill=\"#3C3C3B\" d=\"M7.682 10.984l-.045.055v2.826l.045.132 3.685-5.189z\"/><path fill=\"#8C8C8C\" d=\"M7.682 2L4 8.11l3.682 2.177v-3.85zM7.682 13.997v-3.013L4 8.808z\"/><path fill=\"#141414\" d=\"M7.682 10.287l3.683-2.177-3.683-1.674z\"/><path fill=\"#393939\" d=\"M4 8.11l3.682 2.177v-3.85z\"/></g>","height":"16","width":"16"},"dash":{"keywords":["dash"],"path":"<path fill=\"#1C75BC\" fill-rule=\"nonzero\" d=\"M4.515 4.256l-.49 1.5-.004.014h7.346l-.003.013-.58 1.768-.576 1.757s-1.654.002-3.675.002H2.859l-.096.292c-.233.71-.481 1.471-.481 1.474 0 .006 8.112.004 8.226-.002.288-.015.55-.09.858-.246.287-.145.527-.323.777-.572.283-.284.487-.583.608-.892.036-.092 1.172-3.56 1.194-3.646a1.5 1.5 0 0 0 .053-.39 1.368 1.368 0 0 0-.07-.508 1.133 1.133 0 0 0-.603-.692 1.24 1.24 0 0 0-.387-.114c-.065-.01-.295-.011-4.204-.012L4.599 4l-.084.256zM2.283 7.533C2.127 7.984 2 8.357 2 8.36c0 .005.491.007 2.183.007h2.184l.007-.02a957.892 957.892 0 0 0 .561-1.626c.004-.01-.102-.01-2.182-.01H2.566l-.283.82z\"/>","height":"16","width":"16"},"ripple":{"keywords":["ripple"],"path":"<defs><linearGradient x1=\"28.201%\" x2=\"103.372%\" y1=\"15.347%\" y2=\"84.653%\"><stop offset=\"0%\" stop-color=\"#00AAE4\"/><stop offset=\"100%\" stop-color=\"#006097\"/></linearGradient></defs><path fill=\"url(#a)\" fill-rule=\"nonzero\" d=\"M11.81 9.323c-.424-.245-.902-.316-1.375-.332-.397-.014-.99-.269-.99-.991 0-.538.437-.971.99-.99.473-.017.951-.088 1.375-.333a2.506 2.506 0 1 0-3.759-2.17c0 .485.173.932.393 1.346.185.349.28.996-.356 1.363-.473.273-1.064.1-1.358-.372-.25-.398-.55-.771-.97-1.014a2.506 2.506 0 1 0 0 4.34c.42-.242.72-.616.97-1.014.204-.327.714-.744 1.357-.372.473.273.619.87.357 1.363-.22.414-.393.861-.393 1.347a2.506 2.506 0 1 0 3.76-2.17z\"/>","height":"16","width":"16"}}
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crypticons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mitchell Cash
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.3.1
|
27
|
+
description: A package that distributes Crypticons in a gem
|
28
|
+
email:
|
29
|
+
- mitchell@mitchellcash.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/crypticons.rb
|
37
|
+
- lib/crypticons/crypticon.rb
|
38
|
+
- lib/crypticons/version.rb
|
39
|
+
- lib/data.json
|
40
|
+
homepage: https://github.com/mitchellcash/crypticons
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.6.13
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: The crypticons gem
|
64
|
+
test_files: []
|