Class: JekyllImgFlow::HtmlGenerator

Inherits:
Object
  • Object
show all
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 collapse

MARKUP_FORMATS =
%w[auto picture img data_auto data_picture data_img direct_url
naked_srcset].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HtmlGenerator.



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

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:

  • results (Array<String>)

    Processed image paths

  • attributes (Hash)

    HTML attributes by element

  • markup_format (String)

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

  • context (Liquid::Context)

    Liquid context

  • config (JekyllImgFlow::Config) (defaults to: nil)

    ImgFlow configuration

Returns:

  • (String)

    Generated HTML



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

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jekyll-imgflow/html_generator.rb', line 34

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 parent container if specified
  html = wrap_with_parent(html) if @attributes[:parent]&.any?

  html
end