Class: JekyllHighlightCards::PolaroidTag

Inherits:
Liquid::Tag
  • Object
show all
Includes:
ArchiveHelper, ExpressionEvaluator, TemplateRenderer
Defined in:
lib/jekyll-highlight-cards/polaroid_tag.rb

Overview

Liquid tag for creating styled polaroid photo components

Syntax:

{% polaroid IMAGE_URL [size=WxH] [alt="..."] [title="..."] [link="..."] [image_link="..."] [archive="..."] %}

Parameters:

- IMAGE_URL (required): Path or URL to the image (can be Liquid expression)
- size=WxH (optional): Image dimensions (e.g., size=300x200, size=400x, size=x300)
- alt="..." (optional): Alt text for the image (can be Liquid expression)
- title="..." (optional): Title text to display (can be Liquid expression, also used as alt fallback)
- link="..." (optional): URL to link to (can be Liquid expression)
- image_link="..." (optional): URL for the image to link to, overrides default behavior (can be Liquid expression)
- archive="..." (optional): Archive URL or "none" to opt out

Note: Alt text priority: alt parameter > title parameter > empty string This allows setting alt text without a visible title for accessibility

Note: Image link behavior: - No link or image_link: image links to itself - link only: image links to link URL - image_link: image links to image_link URL (overrides default)

Examples:

{% polaroid /assets/img/photo.jpg %}
{% polaroid /img/photo.jpg size=300x200 title="My Photo" %}
{% polaroid /img/photo.jpg alt="Screen reader description" %}
{% polaroid /img/photo.jpg alt="Detailed alt" title="Short Title" %}
{% polaroid {{ page.image }} size=x400 title={{ page.title }} %}
{% polaroid /img.jpg link="https://example.com" archive="none" %}
{% polaroid /img.jpg link="https://example.com" image_link="https://other.com" %}

Instance Method Summary collapse

Methods included from TemplateRenderer

#find_template_path, #render_template, #safe_template_path

Methods included from ExpressionEvaluator

#evaluate_expression, #log_debug, #log_error, #log_info, #log_warn, #quote_wrapped?, #strip_outer_quotes, #variable_lookup?

Methods included from ArchiveHelper

#archive_enabled?, #archive_save_enabled?, #archive_url_for, #archive_user_agent

Instance Method Details

#render(context) ⇒ String

Render the polaroid tag

Parameters:

  • context (Liquid::Context)

    the Liquid rendering context

Returns:

  • (String)

    rendered HTML

Raises:

  • (ArgumentError)


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
# File 'lib/jekyll-highlight-cards/polaroid_tag.rb', line 43

def render(context)
  params = parse_markup(@markup, context)

  raise ArgumentError, "polaroid tag requires an image URL" if params.fetch(:image_url).empty?

  width, height = DimensionParser.parse_dimensions(params[:size])

  explicit_link = !params[:link].to_s.empty?
  link_url = if params[:link].to_s.empty?
               params.fetch(:image_url)
             else
               params.fetch(:link)
             end
  image_link_url = if params[:image_link].to_s.empty?
                     link_url
                   else
                     params.fetch(:image_link)
                   end
  archive_url = resolve_archive(params[:archive], link_url)

  variables = build_template_variables(
    params.fetch(:image_url),
    width,
    height,
    params[:title],
    params[:alt],
    link_url,
    image_link_url,
    explicit_link,
    archive_url
  )

  render_template(context.registers[:site], "polaroid", variables)
end