jekyll-heroicons 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -0
- data/lib/jekyll-heroicons/icon.rb +44 -0
- data/lib/jekyll-heroicons/version.rb +2 -2
- data/lib/jekyll-heroicons.rb +28 -23
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 112fbd4869748edda881eba9c9ef2ee54455adc9bd02f9459f2b6f6283561242
|
4
|
+
data.tar.gz: fd5b1f750f6a421d0ec7666a653c572d468cd7e3d062bc0dbe635641d8f40f87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3f32efc24439124b355dd25a95265c7253045864de3a4bf513b63d4c1cc1451bfb4c17602cdf1b192d260b6eebcc05e187128d8a2cef738e94f91c07bfefc2
|
7
|
+
data.tar.gz: 6da0122ce4bac2056602a170e1a02d522e0d12f744fb7f76bc10b4b7832e2f391415b1658d5dce1e8a0879ccf895ab6395012126c48e097e478d01f0dd196120
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class Heroicons < Liquid::Tag
|
5
|
+
class Icon
|
6
|
+
def initialize(symbol, variant, options = {})
|
7
|
+
@symbol = symbol
|
8
|
+
@variant = variant
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw
|
13
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(file)
|
14
|
+
svg = doc.at_css "svg"
|
15
|
+
|
16
|
+
prepend_default_classes
|
17
|
+
|
18
|
+
@options.each do |key, value|
|
19
|
+
svg[key.to_s] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
doc.to_html.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def prepend_default_classes
|
28
|
+
if @options[:class]
|
29
|
+
@options[:class] += " size-6"
|
30
|
+
else
|
31
|
+
@options[:class] = "size-6"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def file
|
36
|
+
@file ||= File.read(file_path).force_encoding("UTF-8")
|
37
|
+
end
|
38
|
+
|
39
|
+
def file_path
|
40
|
+
File.join(Jekyll::Heroicons.root, "icons/#{@variant}/#{@symbol}.svg")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/jekyll-heroicons.rb
CHANGED
@@ -1,39 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
|
5
|
-
require
|
3
|
+
require_relative "jekyll-heroicons/version"
|
4
|
+
require_relative "jekyll-heroicons/icon"
|
5
|
+
require "liquid"
|
6
|
+
require "jekyll/liquid_extensions"
|
6
7
|
|
7
8
|
module Jekyll
|
8
9
|
class Heroicons < Liquid::Tag
|
9
10
|
include Jekyll::LiquidExtensions
|
10
11
|
|
12
|
+
def self.root
|
13
|
+
File.dirname(__dir__)
|
14
|
+
end
|
15
|
+
|
11
16
|
# Syntax for the heroicon symbol
|
12
|
-
|
17
|
+
SYNTAX = /\A(#{Liquid::VariableSignature}+)/
|
13
18
|
|
14
19
|
# For interpolation, look for liquid variables
|
15
|
-
|
20
|
+
VARIABLE = /\{\{\s*([\w]+\.?[\w]*)\s*\}\}/i
|
16
21
|
|
17
22
|
# Copied from Liquid::TagAttributes to allow dashes in tag names:
|
18
23
|
#
|
19
24
|
# {% heroicon alert area-label:"Hello World!" %}
|
20
25
|
#
|
21
|
-
|
26
|
+
TAG_ATTRIBUTES = /([\w-]+)\s*:\s*(#{Liquid::QuotedFragment})/o
|
22
27
|
|
23
28
|
def initialize(tag_name, markup, options)
|
24
29
|
super
|
25
30
|
@markup = markup
|
26
31
|
|
27
32
|
# If there's interpolation going on, we need to do this in render
|
28
|
-
prepare(markup) unless markup.match(
|
33
|
+
prepare(markup) unless markup.match(VARIABLE)
|
29
34
|
end
|
30
35
|
|
31
36
|
def render(context)
|
32
|
-
prepare(interpolate(@markup, context)) if @markup.match(
|
37
|
+
prepare(interpolate(@markup, context)) if @markup.match(VARIABLE)
|
33
38
|
|
34
39
|
return nil if @symbol.nil?
|
35
40
|
|
36
|
-
|
41
|
+
Icon.new(@symbol, @variant, @options.except(:variant)).raw
|
37
42
|
end
|
38
43
|
|
39
44
|
private
|
@@ -41,16 +46,16 @@ module Jekyll
|
|
41
46
|
def prepare(markup)
|
42
47
|
@symbol = symbol(markup)
|
43
48
|
@options = string_to_hash(markup)
|
44
|
-
@variant = if (match = markup.split(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
@variant = if (match = markup.split("/")).length > 1
|
50
|
+
match.first
|
51
|
+
elsif @options.key?(:variant)
|
52
|
+
@options[:variant]
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
def interpolate(markup, context)
|
52
|
-
markup.scan
|
53
|
-
markup = markup.gsub(
|
57
|
+
markup.scan VARIABLE do |variable|
|
58
|
+
markup = markup.gsub(VARIABLE, lookup_variable(context, variable.first))
|
54
59
|
end
|
55
60
|
markup
|
56
61
|
end
|
@@ -59,9 +64,9 @@ module Jekyll
|
|
59
64
|
def string_to_hash(markup)
|
60
65
|
options = {}
|
61
66
|
|
62
|
-
if markup.match(
|
63
|
-
markup.scan(
|
64
|
-
options[key.to_sym] = value.gsub(/\A"|"\z/,
|
67
|
+
if markup.match(SYNTAX)
|
68
|
+
markup.scan(TAG_ATTRIBUTES) do |key, value|
|
69
|
+
options[key.to_sym] = value.gsub(/\A"|"\z/, "")
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
@@ -69,13 +74,13 @@ module Jekyll
|
|
69
74
|
end
|
70
75
|
|
71
76
|
def symbol(markup)
|
72
|
-
if (match = markup.split(
|
73
|
-
match[1].match(
|
77
|
+
if (match = markup.split("/")).length > 1
|
78
|
+
match[1].match(SYNTAX)
|
74
79
|
else
|
75
|
-
markup.match(
|
80
|
+
markup.match(SYNTAX)
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
81
|
-
Liquid::Template.register_tag(
|
86
|
+
Liquid::Template.register_tag("heroicon", Jekyll::Heroicons)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-heroicons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stanislav (Stas) Katkov
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Jekyll liquid tags for the beautiful hand-crafted SVG icons, Heroicons.
|
28
42
|
email:
|
29
43
|
- github@skatkov.com
|
@@ -1326,6 +1340,7 @@ files:
|
|
1326
1340
|
- icons/solid/x-circle.svg
|
1327
1341
|
- icons/solid/x-mark.svg
|
1328
1342
|
- lib/jekyll-heroicons.rb
|
1343
|
+
- lib/jekyll-heroicons/icon.rb
|
1329
1344
|
- lib/jekyll-heroicons/version.rb
|
1330
1345
|
homepage: https://github.com/skatkov/jekyll-heroicons
|
1331
1346
|
licenses:
|