Class: JekyllImgFlow::HtmlGenerator
- Inherits:
-
Object
- Object
- JekyllImgFlow::HtmlGenerator
- 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
-
.generate(results, attributes, markup_format, context, config = nil) ⇒ String
Generate HTML based on markup format and attributes.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(results, attributes, markup_format, context, config = nil) ⇒ HtmlGenerator
constructor
A new instance of HtmlGenerator.
Methods included from ModalWrapper
#html_element?, #modal_enabled?, #modal_image_path, #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
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
#generate ⇒ Object
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 |