Class: Jekyll::UJLogoTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
Jekyll::UJPowertools::VariableResolver
Defined in:
lib/tags/logo.rb

Constant Summary collapse

DEFAULT_LOGO =

Default logo to show when requested logo is not found

'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Free v7.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 64C334.7 64 348.2 72.1 355.2 85L571.2 485C577.9 497.4 577.6 512.4 570.4 524.5C563.2 536.6 550.1 544 536 544L104 544C89.9 544 76.9 536.6 69.6 524.5C62.3 512.4 62.1 497.4 68.8 485L284.8 85C291.8 72.1 305.3 64 320 64zM320 232C306.7 232 296 242.7 296 256L296 368C296 381.3 306.7 392 320 392C333.3 392 344 381.3 344 368L344 256C344 242.7 333.3 232 320 232zM346.7 448C347.3 438.1 342.4 428.7 333.9 423.5C325.4 418.4 314.7 418.4 306.2 423.5C297.7 428.7 292.8 438.1 293.4 448C292.8 457.9 297.7 467.3 306.2 472.5C314.7 477.6 325.4 477.6 333.9 472.5C342.4 467.3 347.3 457.9 346.7 448z"/></svg>'
@@logo_cache =

Cache for loaded logos (raw SVG content) to improve performance

{}
@@instance_counter =

Counter for generating unique prefixes per logo instance

0

Instance Method Summary collapse

Methods included from Jekyll::UJPowertools::VariableResolver

#is_quoted?, #parse_arguments, #parse_options, #resolve_input, #resolve_variable

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ UJLogoTag

Returns a new instance of UJLogoTag.



18
19
20
21
# File 'lib/tags/logo.rb', line 18

def initialize(tag_name, markup, tokens)
  super
  @markup = markup.strip
end

Instance Method Details

#render(context) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tags/logo.rb', line 23

def render(context)
  # Parse arguments using helper
  parts = parse_arguments(@markup)
  
  # Resolve logo name (required)
  logo_name = parts[0]
  if logo_name
    resolved = resolve_input(context, logo_name, true)
    # If resolved value is not a string, treat the input as literal
    if resolved.is_a?(String)
      # Strip any quotes from the resolved string value
      logo_name = resolved.gsub(/^['"]|['"]$/, '')
    else
      # Strip quotes if present and use as literal
      logo_name = logo_name.gsub(/^['"]|['"]$/, '')
    end
  end
  
  # Return empty if no logo name provided
  return '' unless logo_name
  
  # Resolve type (brandmarks or combomarks) - defaults to brandmarks
  type = 'brandmarks'
  if parts[1] && !parts[1].empty?
    resolved_type = resolve_input(context, parts[1], true)
    if resolved_type.is_a?(String) && !resolved_type.empty?
      type = resolved_type.gsub(/^['"]|['"]$/, '')
    elsif !parts[1].gsub(/^['"]|['"]$/, '').empty?
      type = parts[1].gsub(/^['"]|['"]$/, '')
    end
  end
  
  # Resolve color - defaults to original
  color = 'original'
  if parts[2] && !parts[2].empty?
    resolved_color = resolve_input(context, parts[2], true)
    if resolved_color.is_a?(String) && !resolved_color.empty?
      color = resolved_color.gsub(/^['"]|['"]$/, '')
    elsif !parts[2].gsub(/^['"]|['"]$/, '').empty?
      color = parts[2].gsub(/^['"]|['"]$/, '')
    end
  end
  
  # Get site from context
  site = context.registers[:site]
  return '' unless site

  # Load the raw logo SVG from file (cached)
  raw_svg = load_logo_from_file(logo_name.to_s, type, color)
  return '' unless raw_svg

  # Generate unique prefix for this instance to prevent ID conflicts
  # when the same logo is used multiple times on a page
  @@instance_counter += 1
  unique_prefix = "#{logo_name}-#{@@instance_counter}"

  # Prefix all IDs with unique prefix
  prefix_svg_ids(raw_svg, unique_prefix)
end