Sha256: 8913be0d325a989a7fac84d37c52dffa88f66eb95cd762fab9a8b1167eb8a40e
Contents?: true
Size: 1.65 KB
Versions: 206
Compression:
Stored size: 1.65 KB
Contents
# frozen_string_literal: true module Ariadne # Use `Image` to render images. # # @accessibility # Always provide a meaningful `alt`. class ImageComponent < Ariadne::Component DEFAULT_TAG = :img # @example Default # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub")) %> # # @example Helper # # <%= ariadne_image(src: "https://github.com/github.png", alt: "GitHub") %> # # @example Lazy loading # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub", lazy: true)) %> # # @example Custom size # # <%= render(Ariadne::ImageComponent.new(src: "https://github.com/github.png", alt: "GitHub", attributes: { height: 100, width: 100 })) %> # # @param tag [Symbol, String] The rendered tag name # @param src [String] The source url of the image. # @param alt [String] Specifies an alternate text for the image. # @param lazy [Boolean] Whether or not to lazily load the image. # @param classes [String] <%= link_to_classes_docs %> # @param attributes [Hash] <%= link_to_attributes_docs %> def initialize(tag: DEFAULT_TAG, src:, alt:, lazy: false, classes: "", attributes: {}) @attributes = attributes @src = src @tag = check_incoming_tag(DEFAULT_TAG, tag) @classes = classes @attributes[:alt] = alt @attributes[:src] = @src return unless lazy @attributes[:loading] = :lazy @attributes[:decoding] = :async end def call render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) end end end
Version data entries
206 entries across 206 versions & 1 rubygems