heroicons-rb 0.5.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 +7 -0
- data/data/icons.json +1 -0
- data/lib/heroicons/helper.rb +10 -0
- data/lib/heroicons/icon.rb +69 -0
- data/lib/heroicons/railtie.rb +11 -0
- data/lib/heroicons/version.rb +3 -0
- data/lib/heroicons.rb +22 -0
- metadata +61 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
module Heroicons
|
2
|
+
# Represents a single Heroicon that can be rendered as SVG
|
3
|
+
#
|
4
|
+
# Style mapping:
|
5
|
+
# - :micro (16px) and :mini (20px) styles always use solid variants
|
6
|
+
# - :outline and :solid styles are available for standard 24px icons
|
7
|
+
class Icon
|
8
|
+
def initialize(name:, style:, class_name: nil)
|
9
|
+
@name = name
|
10
|
+
@class_name = class_name
|
11
|
+
@style = style
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_svg
|
15
|
+
validate!
|
16
|
+
|
17
|
+
return icon if (@class_name.nil? || @class_name.empty?)
|
18
|
+
|
19
|
+
svg = Nokogiri::HTML.fragment(icon)
|
20
|
+
return icon unless svg.child
|
21
|
+
|
22
|
+
svg.child.set_attribute("class", @class_name)
|
23
|
+
svg.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def icon
|
29
|
+
@icon ||= icons_data.fetch(key, nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
def icons_data
|
33
|
+
Heroicons::ICONS
|
34
|
+
end
|
35
|
+
|
36
|
+
def key
|
37
|
+
"#{size}/#{style}/#{@name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def style
|
41
|
+
case @style
|
42
|
+
when :micro, :mini
|
43
|
+
"solid"
|
44
|
+
else
|
45
|
+
@style
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def size
|
50
|
+
case @style
|
51
|
+
when :micro
|
52
|
+
16
|
53
|
+
when :mini
|
54
|
+
20
|
55
|
+
else
|
56
|
+
24
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate!
|
61
|
+
raise Heroicons::InvalidStyleError.new(@style) unless valid_style?
|
62
|
+
raise Heroicons::NoSuchIconError.new(key) if icon.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
def valid_style?
|
66
|
+
Heroicons::VALID_STYLES.include?(@style)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/heroicons.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "json"
|
2
|
+
require "nokogiri"
|
3
|
+
require_relative "heroicons/version"
|
4
|
+
require_relative "heroicons/icon"
|
5
|
+
require_relative "heroicons/railtie" if defined?(Rails)
|
6
|
+
|
7
|
+
module Heroicons
|
8
|
+
ICONS = JSON.parse(File.read(File.dirname(__FILE__) + "/../data/icons.json")).freeze
|
9
|
+
VALID_STYLES = %i[outline solid mini micro]
|
10
|
+
|
11
|
+
class NoSuchIconError < StandardError
|
12
|
+
def initialize(key)
|
13
|
+
super("No such icon: #{key}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class InvalidStyleError < StandardError
|
18
|
+
def initialize(style)
|
19
|
+
super("Invalid Style. Style must be one of #{Heroicons::VALID_STYLES.join(", ")}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroicons-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Levi Kennedy
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: nokogiri
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 1.18.0
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.18.0
|
26
|
+
description: Adds heroicons support to rails
|
27
|
+
email:
|
28
|
+
- lckennedy@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- data/icons.json
|
34
|
+
- lib/heroicons.rb
|
35
|
+
- lib/heroicons/helper.rb
|
36
|
+
- lib/heroicons/icon.rb
|
37
|
+
- lib/heroicons/railtie.rb
|
38
|
+
- lib/heroicons/version.rb
|
39
|
+
homepage: https://github.com/levicole/heroicons-rb.com
|
40
|
+
licenses: []
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/levicole/heroicons-rb.com
|
43
|
+
source_code_uri: https://github.com/levicole/heroicons-rb.com
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 3.1.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.6.7
|
59
|
+
specification_version: 4
|
60
|
+
summary: Adds heroicons support to rails
|
61
|
+
test_files: []
|