Class: Yattho::Alpha::Image

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/alpha/image.rb

Overview

Use ‘Image` to render images.

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(src:, alt:, lazy: false, **system_arguments) ⇒ Image

Returns a new instance of Image.

Examples:

Default


<%= render(Yattho::Alpha::Image.new(src: Yattho::ExampleImage::BASE64_SRC, alt: "GitHub")) %>

Helper


<%= yattho_image(src: Yattho::ExampleImage::BASE64_SRC, alt: "GitHub") %>

Lazy loading


<%= render(Yattho::Alpha::Image.new(src: Yattho::ExampleImage::BASE64_SRC, alt: "GitHub", lazy: true)) %>

Custom size


<%= render(Yattho::Alpha::Image.new(src: Yattho::ExampleImage::BASE64_SRC, alt: "GitHub", height: 100, width: 100)) %>

Parameters:

  • src (String)

    The source url of the image.

  • alt (String)

    Specifies an alternate text for the image.

  • lazy (Boolean) (defaults to: false)

    Whether or not to lazily load the image.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/yattho/alpha/image.rb', line 32

def initialize(src:, alt:, lazy: false, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)

  @src = src
  @system_arguments[:tag] = :img
  @system_arguments[:alt] = alt

  return unless lazy

  @system_arguments[:loading] = :lazy
  @system_arguments[:decoding] = :async
end

Instance Method Details

#callObject



45
46
47
# File 'app/components/yattho/alpha/image.rb', line 45

def call
  render(Yattho::BaseComponent.new(src: image_path(@src), **@system_arguments))
end