jekyll-tabler 0.1.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/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/assets/filled.yml +1737 -0
- data/assets/outline.yml +23899 -0
- data/lib/jekyll-tabler.rb +157 -0
- data/lib/version.rb +7 -0
- metadata +90 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "jekyll"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
require "shellwords"
|
|
6
|
+
require "yaml"
|
|
7
|
+
|
|
8
|
+
require_relative "version"
|
|
9
|
+
|
|
10
|
+
module Jekyll
|
|
11
|
+
# module Jekyll::Tabler
|
|
12
|
+
module Tabler
|
|
13
|
+
VARIABLE_LOOKUP = /\A[a-zA-Z_][\w-]*(?:\.[\w-]+|\[[^\]]+\])*\z/
|
|
14
|
+
OPTION_LOOKUP = /\A([^=\s]+)=(.+)\z/
|
|
15
|
+
VALID_OPTIONS = %w[size color].freeze
|
|
16
|
+
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
def tabler_icons(type)
|
|
20
|
+
data_path = File.join(
|
|
21
|
+
Gem.loaded_specs["jekyll-tabler"].full_gem_path,
|
|
22
|
+
"assets",
|
|
23
|
+
"#{type}.yml"
|
|
24
|
+
)
|
|
25
|
+
YAML.load_file(data_path)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def outline_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
|
|
29
|
+
icons = tabler_icons("outline")
|
|
30
|
+
ds = Array(icons[icon_name])
|
|
31
|
+
paths = ds.map { |d| %(<path d="#{d}" />) }.join("\n")
|
|
32
|
+
<<~HTML
|
|
33
|
+
<svg xmlns="http://www.w3.org/2000/svg"
|
|
34
|
+
viewBox="0 0 24 24"
|
|
35
|
+
fill="none"
|
|
36
|
+
stroke-width="2"
|
|
37
|
+
stroke-linecap="round"
|
|
38
|
+
stroke-linejoin="round"
|
|
39
|
+
stroke="#{color}"
|
|
40
|
+
width="#{size}"
|
|
41
|
+
height="#{size}"
|
|
42
|
+
class="jekyll-tabler-icon #{icon_name}"
|
|
43
|
+
>
|
|
44
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
45
|
+
#{paths}
|
|
46
|
+
</svg>
|
|
47
|
+
HTML
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def filled_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
|
|
51
|
+
icons = tabler_icons("filled")
|
|
52
|
+
ds = Array(icons[icon_name])
|
|
53
|
+
paths = ds.map { |d| %(<path d="#{d}" />) }.join("\n")
|
|
54
|
+
<<~HTML
|
|
55
|
+
<svg xmlns="http://www.w3.org/2000/svg"
|
|
56
|
+
viewBox="0 0 24 24"
|
|
57
|
+
width="#{size}"
|
|
58
|
+
height="#{size}"
|
|
59
|
+
fill="#{color}"
|
|
60
|
+
class="jekyll-tabler-icon #{icon_name}"
|
|
61
|
+
>
|
|
62
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
63
|
+
#{paths}
|
|
64
|
+
</svg>
|
|
65
|
+
HTML
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def resolve_argument(argument, context)
|
|
69
|
+
return argument unless argument.is_a?(String) && argument.match?(VARIABLE_LOOKUP)
|
|
70
|
+
|
|
71
|
+
resolved = context.evaluate(Liquid::Expression.parse(argument))
|
|
72
|
+
resolved.nil? ? argument : resolved
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def syntax_message
|
|
76
|
+
"Syntax: {% tabler|tabler_filled icon_name [size] [color] [size=value] [color=value] %}"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def parse_optional_args(arguments) # rubocop:disable Metrics/MethodLength
|
|
80
|
+
arguments.each_with_object([{}, []]) do |argument, memo|
|
|
81
|
+
options = memo[0]
|
|
82
|
+
positional_args = memo[1]
|
|
83
|
+
match = argument.match(OPTION_LOOKUP)
|
|
84
|
+
|
|
85
|
+
unless match
|
|
86
|
+
positional_args << argument
|
|
87
|
+
next
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
key = match[1]
|
|
91
|
+
raise Liquid::SyntaxError, "Unknown #{key} option in tabler tag" unless VALID_OPTIONS.include?(key)
|
|
92
|
+
raise Liquid::SyntaxError, "Duplicate #{key} option in tabler tag" if options.key?(key)
|
|
93
|
+
|
|
94
|
+
options[key] = match[2]
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# class Jekyll::Tabler::OutlineTag
|
|
99
|
+
class OutlineTag < Liquid::Tag
|
|
100
|
+
def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize
|
|
101
|
+
super
|
|
102
|
+
|
|
103
|
+
args = Shellwords.shellsplit(markup.to_s)
|
|
104
|
+
raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if args.empty?
|
|
105
|
+
|
|
106
|
+
@icon_name = args[0]
|
|
107
|
+
options, positional_args = Jekyll::Tabler.parse_optional_args(args.drop(1))
|
|
108
|
+
|
|
109
|
+
raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if positional_args.length > 2
|
|
110
|
+
|
|
111
|
+
@size = options.fetch("size", positional_args[0] || 24)
|
|
112
|
+
@color = options.fetch("color", positional_args[1] || "currentColor")
|
|
113
|
+
rescue ArgumentError => e
|
|
114
|
+
raise Liquid::SyntaxError, e.message
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def render(context)
|
|
118
|
+
icon_name = Jekyll::Tabler.resolve_argument(@icon_name, context)
|
|
119
|
+
size = Jekyll::Tabler.resolve_argument(@size, context)
|
|
120
|
+
color = Jekyll::Tabler.resolve_argument(@color, context)
|
|
121
|
+
|
|
122
|
+
Jekyll::Tabler.outline_wrapper(icon_name, size, color)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# class Jekyll::Tabler::OutlineTag
|
|
127
|
+
class FilledTag < Liquid::Tag
|
|
128
|
+
def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize
|
|
129
|
+
super
|
|
130
|
+
|
|
131
|
+
args = Shellwords.shellsplit(markup.to_s)
|
|
132
|
+
raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if args.empty?
|
|
133
|
+
|
|
134
|
+
@icon_name = args[0]
|
|
135
|
+
options, positional_args = Jekyll::Tabler.parse_optional_args(args.drop(1))
|
|
136
|
+
|
|
137
|
+
raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if positional_args.length > 2
|
|
138
|
+
|
|
139
|
+
@size = options.fetch("size", positional_args[0] || 24)
|
|
140
|
+
@color = options.fetch("color", positional_args[1] || "currentColor")
|
|
141
|
+
rescue ArgumentError => e
|
|
142
|
+
raise Liquid::SyntaxError, e.message
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def render(context)
|
|
146
|
+
icon_name = Jekyll::Tabler.resolve_argument(@icon_name, context)
|
|
147
|
+
size = Jekyll::Tabler.resolve_argument(@size, context)
|
|
148
|
+
color = Jekyll::Tabler.resolve_argument(@color, context)
|
|
149
|
+
|
|
150
|
+
Jekyll::Tabler.filled_wrapper(icon_name, size, color)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
Liquid::Template.register_tag("tabler", Jekyll::Tabler::OutlineTag)
|
|
157
|
+
Liquid::Template.register_tag("tabler_filled", Jekyll::Tabler::FilledTag)
|
data/lib/version.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-tabler
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- phothinmg
|
|
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: fileutils
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.8'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.8'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: jekyll
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '4.4'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '4.4'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: yaml
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 0.4.0
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 0.4.0
|
|
54
|
+
email:
|
|
55
|
+
- phothinmg@disroot.org
|
|
56
|
+
executables: []
|
|
57
|
+
extensions: []
|
|
58
|
+
extra_rdoc_files: []
|
|
59
|
+
files:
|
|
60
|
+
- LICENSE.txt
|
|
61
|
+
- README.md
|
|
62
|
+
- assets/filled.yml
|
|
63
|
+
- assets/outline.yml
|
|
64
|
+
- lib/jekyll-tabler.rb
|
|
65
|
+
- lib/version.rb
|
|
66
|
+
homepage: https://github.com/phothinmg/jekyll-tabler
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
homepage_uri: https://github.com/phothinmg/jekyll-tabler
|
|
71
|
+
changelog_uri: https://github.com/phothinmg/jekyll-tabler/blob/main/CHANGELOG.md
|
|
72
|
+
rubygems_mfa_required: 'true'
|
|
73
|
+
rdoc_options: []
|
|
74
|
+
require_paths:
|
|
75
|
+
- lib
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 3.2.0
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
requirements: []
|
|
87
|
+
rubygems_version: 4.0.11
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Tabler Icons plugin for Jekyll site as liquid tag
|
|
90
|
+
test_files: []
|