Module: JekyllImgFlow::ModalWrapper

Included in:
HtmlGenerator
Defined in:
lib/jekyll-imgflow/modal_assets.rb

Overview

Modal wrapping logic for HtmlGenerator — extracted to keep HtmlGenerator under the RuboCop class length limit.

Constant Summary collapse

NON_HTML_FORMATS =

Formats that produce raw URLs/srcsets (not wrappable HTML elements)

%w[direct_url naked_srcset].freeze

Instance Method Summary collapse

Instance Method Details

#html_element?Boolean

Check if the current markup format produces an HTML element

Returns:

  • (Boolean)


71
72
73
# File 'lib/jekyll-imgflow/modal_assets.rb', line 71

def html_element?
  !NON_HTML_FORMATS.include?(@markup_format)
end

Determine if modal behavior is enabled for this image Per-image modal:true/false overrides config default Modal is skipped when an explicit link is set

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
# File 'lib/jekyll-imgflow/modal_assets.rb', line 78

def modal_enabled?
  return false if @attributes[:link]

  modal_attr = @attributes[:modal]
  return modal_attr.to_s == "true" if modal_attr

  @config&.image_modal ? true : false
end

Pick the best image path for the modal — prefer the fallback format (e.g. jpg) for maximum browser compatibility



89
90
91
92
93
# File 'lib/jekyll-imgflow/modal_assets.rb', line 89

def modal_image_path
  fallback_ext = @config&.fallback_format ? ".#{@config.fallback_format}" : ".jpg"
  fallback = @results.find { |r| File.extname(r).downcase == fallback_ext }
  fallback || @results.last
end

#wrap_with_modal(html) ⇒ Object

Wrap HTML in modal trigger anchor



96
97
98
99
100
101
102
103
104
105
# File 'lib/jekyll-imgflow/modal_assets.rb', line 96

def wrap_with_modal(html)
  modal_href = html_path(modal_image_path)
  return html unless modal_href

  data_attrs = " data-imgflow-modal"
  alt = @attributes[:alt]
  data_attrs += " data-imgflow-alt=\"#{escape_attr_value(alt)}\"" if alt

  "<a href=\"#{modal_href}\"#{data_attrs}>#{html}</a>"
end