jekyll-heroicons 0.1.1 → 0.2
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 +4 -4
- data/CHANGELOG.md +2 -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: d75f8059ea7aa63207d3554a911705015944ad140535354c3488869f1b2c1276
|
4
|
+
data.tar.gz: 3fa2aa1a5127b87a6c209d26e2a868eaf8eb4987a790f59401db1789f71e043d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57e8044b126bd1fb9839ff9c8eed9e6e33d247c0ef376a2311d6cbbc409cf2d1d9fe619ad9a651d9384b400544f87e9123a34107cfb602bf1681ec99dfabc5c1
|
7
|
+
data.tar.gz: 1091d7b8bd64b141ac8bb1ebf900f9be812179bf48f9198e6c45140c8e2a5e18dcb2d76da98810ce6199cb22d1b56c23d5a7e72ec7873e21c89023f99626a3c8
|
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
|
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'
|
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:
|