Class: Jekyll::Tabler::OutlineTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-tabler.rb

Overview

Handles {% tabler ... %} tags.

initialize runs during Liquid parsing, not page rendering, so this method only stores raw arguments. Variable resolution happens later in render when the page context is available.

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ OutlineTag

rubocop:disable Metrics/AbcSize



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/jekyll-tabler.rb', line 133

def initialize(tag_name, markup, tokens) # rubocop:disable Metrics/AbcSize
  super

  args = Shellwords.shellsplit(markup.to_s)
  raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if args.empty?

  @icon_name = args[0]
  options, positional_args = Jekyll::Tabler.parse_optional_args(args.drop(1))

  raise Liquid::SyntaxError, Jekyll::Tabler.syntax_message if positional_args.length > 2

  @size = options.fetch("size", positional_args[0] || 24)
  @color = options.fetch("color", positional_args[1] || "currentColor")
rescue ArgumentError => e
  raise Liquid::SyntaxError, e.message
end

Instance Method Details

#render(context) ⇒ Object

Converts stored arguments into final values for the current page and delegates SVG generation to the shared helper.



152
153
154
155
156
157
158
# File 'lib/jekyll-tabler.rb', line 152

def render(context)
  icon_name = Jekyll::Tabler.resolve_argument(@icon_name, context)
  size = Jekyll::Tabler.resolve_argument(@size, context)
  color = Jekyll::Tabler.resolve_argument(@color, context)

  Jekyll::Tabler.outline_wrapper(icon_name, size, color)
end