Class: JekyllImgFlow::HtmlGenerator
- Inherits:
-
Object
- Object
- JekyllImgFlow::HtmlGenerator
- 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
-
.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.
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
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
#generate ⇒ Object
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 |