Class: Jekyll::UJPowertools::ExternalTag

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

Instance Method Summary collapse

Methods included from VariableResolver

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

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ExternalTag

Returns a new instance of ExternalTag.



10
11
12
13
# File 'lib/tags/external.rb', line 10

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

Instance Method Details

#render(context) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tags/external.rb', line 15

def render(context)
  # Resolve input path (handles both literals and variables)
  path = resolve_input(context, @markup)
  return '' if path.nil? || path.empty?
  
  # Check if path already has a protocol (http:// or https://)
  if path =~ /^https?:\/\//
    # Already has protocol, return as-is
    path
  elsif path =~ /^\/\//
    # Protocol-relative URL, return as-is
    path
  else
    # Get site URL from context
    site = context.registers[:site]
    site_url = site.config['url'] || ''
    
    # Remove trailing slash from site_url if present
    site_url = site_url.chomp('/')
    
    # Ensure path starts with /
    path = "/#{path}" unless path.start_with?('/')
    
    # Combine site URL with path
    "#{site_url}#{path}"
  end
end