Module: Jekyll::Tabler

Defined in:
lib/jekyll-tabler.rb,
lib/version.rb

Overview

module Jekyll::Tabler

Defined Under Namespace

Classes: FilledTag, OutlineTag

Constant Summary collapse

VERSION =
"0.1.0"
VARIABLE_LOOKUP =
/\A[a-zA-Z_][\w-]*(?:\.[\w-]+|\[[^\]]+\])*\z/
OPTION_LOOKUP =
/\A([^=\s]+)=(.+)\z/
VALID_OPTIONS =
%w[size color].freeze

Class Method Summary collapse

Class Method Details

.filled_wrapper(icon_name, size = 24, color = "currentColor") ⇒ Object

rubocop:disable Metrics/MethodLength



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/jekyll-tabler.rb', line 50

def filled_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
  icons = tabler_icons("filled")
  ds = Array(icons[icon_name])
  paths = ds.map { |d| %(<path d="#{d}" />) }.join("\n")
  <<~HTML
    <svg xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 24 24"
     width="#{size}"
    height="#{size}"
    fill="#{color}"
    class="jekyll-tabler-icon #{icon_name}"
    >
    <path stroke="none" d="M0 0h24v24H0z" fill="none" />
    #{paths}
    </svg>
  HTML
end

.outline_wrapper(icon_name, size = 24, color = "currentColor") ⇒ Object

rubocop:disable Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/jekyll-tabler.rb', line 28

def outline_wrapper(icon_name, size = 24, color = "currentColor") # rubocop:disable Metrics/MethodLength
  icons = tabler_icons("outline")
  ds = Array(icons[icon_name])
  paths = ds.map { |d| %(<path d="#{d}" />) }.join("\n")
  <<~HTML
    <svg xmlns="http://www.w3.org/2000/svg"
    viewBox="0 0 24 24"
    fill="none"
    stroke-width="2"
    stroke-linecap="round"
    stroke-linejoin="round"
    stroke="#{color}"
    width="#{size}"
    height="#{size}"
    class="jekyll-tabler-icon #{icon_name}"
    >
    <path stroke="none" d="M0 0h24v24H0z" fill="none" />
    #{paths}
    </svg>
  HTML
end

.parse_optional_args(arguments) ⇒ Object

rubocop:disable Metrics/MethodLength



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jekyll-tabler.rb', line 79

def parse_optional_args(arguments) # rubocop:disable Metrics/MethodLength
  arguments.each_with_object([{}, []]) do |argument, memo|
    options = memo[0]
    positional_args = memo[1]
    match = argument.match(OPTION_LOOKUP)

    unless match
      positional_args << argument
      next
    end

    key = match[1]
    raise Liquid::SyntaxError, "Unknown #{key} option in tabler tag" unless VALID_OPTIONS.include?(key)
    raise Liquid::SyntaxError, "Duplicate #{key} option in tabler tag" if options.key?(key)

    options[key] = match[2]
  end
end

.resolve_argument(argument, context) ⇒ Object



68
69
70
71
72
73
# File 'lib/jekyll-tabler.rb', line 68

def resolve_argument(argument, context)
  return argument unless argument.is_a?(String) && argument.match?(VARIABLE_LOOKUP)

  resolved = context.evaluate(Liquid::Expression.parse(argument))
  resolved.nil? ? argument : resolved
end

.syntax_messageObject



75
76
77
# File 'lib/jekyll-tabler.rb', line 75

def syntax_message
  "Syntax: {% tabler|tabler_filled icon_name [size] [color] [size=value] [color=value] %}"
end

.tabler_icons(type) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/jekyll-tabler.rb', line 19

def tabler_icons(type)
  data_path = File.join(
    Gem.loaded_specs["jekyll-tabler"].full_gem_path,
    "assets",
    "#{type}.yml"
  )
  YAML.load_file(data_path)
end