Class: JekyllImgFlow::HtmlGenerator

Inherits:
Object
  • Object
show all
Includes:
ModalWrapper
Defined in:
lib/jekyll-imgflow/html_generator.rb

Overview

Unified HTML Generator for all markup formats Supports Picture Tag compatibility with multiple markup formats and attributes

Constant Summary

Constants included from ModalWrapper

ModalWrapper::NON_HTML_FORMATS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModalWrapper

#generated_modal_results, #html_element?, #modal_enabled?, #modal_fallback_format, #modal_image_path, #modal_max_width, #modal_variants, #modal_width, #wrap_with_modal

Constructor Details

#initialize(results, attributes, markup_format, context, config = nil) ⇒ HtmlGenerator

Returns a new instance of HtmlGenerator.



23
24
25
26
27
28
29
30
31
# File 'lib/jekyll-imgflow/html_generator.rb', line 23

def initialize(results, attributes, markup_format, context, config = nil)
  @results = results
  @attributes = normalize_attributes(attributes)
  @markup_format = markup_format || "img"
  @context = context
  @config = config
  @path_resolver = config ? JekyllImgFlow::PathResolver.new(config) : nil
  @fallback_formats = fallback_formats
end

Class Method Details

.generate(results, attributes, markup_format, context, config = nil) ⇒ String

Generate HTML based on markup format and attributes

Parameters:

  • Processed image paths

  • HTML attributes by element

  • Markup format (auto, picture, img, data_auto, etc.)

  • Liquid context

  • (defaults to: nil)

    ImgFlow configuration

Returns:

  • Generated HTML



16
17
18
19
20
21
# File 'lib/jekyll-imgflow/html_generator.rb', line 16

def self.generate(results, attributes, markup_format, context, config = nil)
  return "" if results.empty?

  generator = new(results, attributes, markup_format, context, config)
  generator.generate
end

Instance Method Details

#generateObject



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
# File 'lib/jekyll-imgflow/html_generator.rb', line 33

def generate
  html = case @markup_format
         when "picture", "auto"
           generate_picture_element
         when "data_picture"
           generate_data_picture_element
         when "data_img", "data_auto"
           generate_data_img_element
         when "direct_url"
           generate_direct_url
         when "naked_srcset"
           generate_naked_srcset
         else
           generate_img_element # Default fallback
         end

  # Wrap in link if specified
  html = wrap_with_link(html) if @attributes[:link]

  # Wrap in modal trigger if enabled (only for HTML elements, not raw URLs)
  html = wrap_with_modal(html) if modal_enabled? && html_element?

  # Wrap in parent container if specified
  html = wrap_with_parent(html) if @attributes[:parent]&.any?

  html
end