jekyll-tabler 0.1.0 → 0.1.1
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/README.md +54 -26
- data/assets/filled.yml +923 -47
- data/assets/outline.yml +5224 -3464
- data/lib/jekyll-tabler.rb +46 -4
- data/lib/version.rb +1 -1
- metadata +1 -1
data/lib/jekyll-tabler.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Copyright (c) 2026 phothinmg
|
|
4
|
+
# <https://github.com/phothinmg/jekyll-tabler>
|
|
5
|
+
|
|
3
6
|
require "jekyll"
|
|
4
7
|
require "fileutils"
|
|
5
8
|
require "shellwords"
|
|
@@ -7,8 +10,20 @@ require "yaml"
|
|
|
7
10
|
|
|
8
11
|
require_relative "version"
|
|
9
12
|
|
|
13
|
+
# Main plugin entrypoint.
|
|
14
|
+
#
|
|
15
|
+
# Flow overview for maintainers:
|
|
16
|
+
# 1. This file is required by Jekyll when the plugin is listed in `_config.yml`.
|
|
17
|
+
# 2. The two Liquid tags are registered at the bottom of the file.
|
|
18
|
+
# 3. When Jekyll parses a page containing `{% tabler %}` or
|
|
19
|
+
# `{% tabler_filled %}`, Liquid instantiates the matching tag class and
|
|
20
|
+
# runs `initialize` once to parse the markup.
|
|
21
|
+
# 4. During page rendering, Liquid calls `render`, which resolves literal
|
|
22
|
+
# values or Liquid variables from the page context.
|
|
23
|
+
# 5. The resolved icon name is looked up in the packaged YAML asset and then
|
|
24
|
+
# wrapped in SVG markup for the final HTML output.
|
|
10
25
|
module Jekyll
|
|
11
|
-
#
|
|
26
|
+
# Shared helpers and Liquid tag implementations for Tabler icons.
|
|
12
27
|
module Tabler
|
|
13
28
|
VARIABLE_LOOKUP = /\A[a-zA-Z_][\w-]*(?:\.[\w-]+|\[[^\]]+\])*\z/
|
|
14
29
|
OPTION_LOOKUP = /\A([^=\s]+)=(.+)\z/
|
|
@@ -16,6 +31,10 @@ module Jekyll
|
|
|
16
31
|
|
|
17
32
|
module_function
|
|
18
33
|
|
|
34
|
+
# Loads the icon path data that ships with the gem.
|
|
35
|
+
#
|
|
36
|
+
# The YAML files map an icon name to one or more SVG path definitions.
|
|
37
|
+
# This is the only place where the plugin reaches into packaged assets.
|
|
19
38
|
def tabler_icons(type)
|
|
20
39
|
data_path = File.join(
|
|
21
40
|
Gem.loaded_specs["jekyll-tabler"].full_gem_path,
|
|
@@ -25,6 +44,7 @@ module Jekyll
|
|
|
25
44
|
YAML.load_file(data_path)
|
|
26
45
|
end
|
|
27
46
|
|
|
47
|
+
# Builds the outline SVG after render-time values have been resolved.
|
|
28
48
|
def outline_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
|
|
29
49
|
icons = tabler_icons("outline")
|
|
30
50
|
ds = Array(icons[icon_name])
|
|
@@ -47,6 +67,7 @@ module Jekyll
|
|
|
47
67
|
HTML
|
|
48
68
|
end
|
|
49
69
|
|
|
70
|
+
# Builds the filled SVG after render-time values have been resolved.
|
|
50
71
|
def filled_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
|
|
51
72
|
icons = tabler_icons("filled")
|
|
52
73
|
ds = Array(icons[icon_name])
|
|
@@ -54,7 +75,7 @@ module Jekyll
|
|
|
54
75
|
<<~HTML
|
|
55
76
|
<svg xmlns="http://www.w3.org/2000/svg"
|
|
56
77
|
viewBox="0 0 24 24"
|
|
57
|
-
|
|
78
|
+
width="#{size}"
|
|
58
79
|
height="#{size}"
|
|
59
80
|
fill="#{color}"
|
|
60
81
|
class="jekyll-tabler-icon #{icon_name}"
|
|
@@ -65,6 +86,9 @@ module Jekyll
|
|
|
65
86
|
HTML
|
|
66
87
|
end
|
|
67
88
|
|
|
89
|
+
# Resolves a tag argument against the Liquid context when it looks like a
|
|
90
|
+
# variable lookup. Literal values such as `24` or `currentColor` pass
|
|
91
|
+
# through unchanged.
|
|
68
92
|
def resolve_argument(argument, context)
|
|
69
93
|
return argument unless argument.is_a?(String) && argument.match?(VARIABLE_LOOKUP)
|
|
70
94
|
|
|
@@ -72,10 +96,15 @@ module Jekyll
|
|
|
72
96
|
resolved.nil? ? argument : resolved
|
|
73
97
|
end
|
|
74
98
|
|
|
99
|
+
# Shared syntax error message used by both tags.
|
|
75
100
|
def syntax_message
|
|
76
101
|
"Syntax: {% tabler|tabler_filled icon_name [size] [color] [size=value] [color=value] %}"
|
|
77
102
|
end
|
|
78
103
|
|
|
104
|
+
# Splits optional arguments into named options and positional arguments.
|
|
105
|
+
#
|
|
106
|
+
# Named options are validated here so each tag class can keep its
|
|
107
|
+
# initializer focused on assigning the final values.
|
|
79
108
|
def parse_optional_args(arguments) # rubocop:disable Metrics/MethodLength
|
|
80
109
|
arguments.each_with_object([{}, []]) do |argument, memo|
|
|
81
110
|
options = memo[0]
|
|
@@ -95,7 +124,11 @@ module Jekyll
|
|
|
95
124
|
end
|
|
96
125
|
end
|
|
97
126
|
|
|
98
|
-
#
|
|
127
|
+
# Handles `{% tabler ... %}` tags.
|
|
128
|
+
#
|
|
129
|
+
# `initialize` runs during Liquid parsing, not page rendering, so this
|
|
130
|
+
# method only stores raw arguments. Variable resolution happens later in
|
|
131
|
+
# `render` when the page context is available.
|
|
99
132
|
class OutlineTag < Liquid::Tag
|
|
100
133
|
def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize
|
|
101
134
|
super
|
|
@@ -114,6 +147,8 @@ module Jekyll
|
|
|
114
147
|
raise Liquid::SyntaxError, e.message
|
|
115
148
|
end
|
|
116
149
|
|
|
150
|
+
# Converts stored arguments into final values for the current page and
|
|
151
|
+
# delegates SVG generation to the shared helper.
|
|
117
152
|
def render(context)
|
|
118
153
|
icon_name = Jekyll::Tabler.resolve_argument(@icon_name, context)
|
|
119
154
|
size = Jekyll::Tabler.resolve_argument(@size, context)
|
|
@@ -123,7 +158,10 @@ module Jekyll
|
|
|
123
158
|
end
|
|
124
159
|
end
|
|
125
160
|
|
|
126
|
-
#
|
|
161
|
+
# Handles `{% tabler_filled ... %}` tags.
|
|
162
|
+
#
|
|
163
|
+
# The control flow mirrors `OutlineTag`; the only behavior difference is
|
|
164
|
+
# the final SVG wrapper that uses filled icon data.
|
|
127
165
|
class FilledTag < Liquid::Tag
|
|
128
166
|
def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize
|
|
129
167
|
super
|
|
@@ -142,6 +180,8 @@ module Jekyll
|
|
|
142
180
|
raise Liquid::SyntaxError, e.message
|
|
143
181
|
end
|
|
144
182
|
|
|
183
|
+
# Converts stored arguments into final values for the current page and
|
|
184
|
+
# delegates SVG generation to the shared helper.
|
|
145
185
|
def render(context)
|
|
146
186
|
icon_name = Jekyll::Tabler.resolve_argument(@icon_name, context)
|
|
147
187
|
size = Jekyll::Tabler.resolve_argument(@size, context)
|
|
@@ -153,5 +193,7 @@ module Jekyll
|
|
|
153
193
|
end
|
|
154
194
|
end
|
|
155
195
|
|
|
196
|
+
# Register the Liquid tags once on load so Jekyll can resolve them while
|
|
197
|
+
# parsing site templates.
|
|
156
198
|
Liquid::Template.register_tag("tabler", Jekyll::Tabler::OutlineTag)
|
|
157
199
|
Liquid::Template.register_tag("tabler_filled", Jekyll::Tabler::FilledTag)
|
data/lib/version.rb
CHANGED