Sha256: 32fd82cceae8bc9f8161b08b9b34743757a5b55e8f40db3b6a492f22a274c1a5

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

require 'redcarpet'
require_relative 'html_lazy_img/version'

module Redcarpet
  module Render
    module HTMLLazyImg
      class Base < ::Redcarpet::Render::HTML
        def image(*)
          raise NotImplementedError
        end

        private

        def image_tag_with_loading_attr(loading:, link:, alt_text:)
          "<img loading=\"#{loading}\" src=\"#{link}\" alt=\"#{alt_text}\" />"
        end
      end

      class Lazy < Base
        def image(link, _title, alt_text)
          image_tag_with_loading_attr(loading: 'lazy', link: link, alt_text: alt_text)
        end
      end

      class Auto < Base
        def image(link, _title, alt_text)
          image_tag_with_loading_attr(loading: 'auto', link: link, alt_text: alt_text)
        end
      end

      class Eager < Base
        def image(link, _title, alt_text)
          image_tag_with_loading_attr(loading: 'eager', link: link, alt_text: alt_text)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redcarpet-render-html_lazy_img-0.2.0 lib/redcarpet/render/html_lazy_img.rb