Class: Jekyll::UJImageTag

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

Constant Summary collapse

PLACEHOLDER =
"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="

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) ⇒ UJImageTag

Returns a new instance of UJImageTag.



10
11
12
13
# File 'lib/tags/image.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
42
43
44
45
# File 'lib/tags/image.rb', line 15

def render(context)
  # Parse arguments
  args = parse_arguments(@markup)
  src_input = args[0]

  # Parse options and resolve their values
  options = parse_options(args[1..-1], context)

  # Resolve source path (treat unquoted strings as literals)
  src = resolve_input(context, src_input, true)
  return '' unless src

  # Check if this is an external URL
  is_external = !!(src =~ /^https?:\/\//)

  if is_external
    # For external URLs, just create a simple responsive img tag
    build_external_image(src, options)
  else
    # Extract file extension
    extension = File.extname(src)
    src_path = src.chomp(extension)

    # Determine max width
    max_width = options['max_width'] || options['max-width'] || false
    max_width = max_width.to_s if max_width

    # Build picture element for local images
    build_picture_element(src, src_path, extension, max_width, options)
  end
end