Class: Maglev::Content::Image

Inherits:
Base
  • Object
show all
Defined in:
app/components/maglev/content/image.rb

Instance Attribute Summary

Attributes inherited from Base

#content, #scope, #setting

Instance Method Summary collapse

Methods inherited from Base

#asset_host, #dom_data, #initialize, #tag_data, #tag_id

Constructor Details

This class inherits a constructor from Maglev::Content::Base

Instance Method Details

#alt_textObject



22
23
24
# File 'app/components/maglev/content/image.rb', line 22

def alt_text
  image[:alt_text]
end

#heightObject



18
19
20
# File 'app/components/maglev/content/image.rb', line 18

def height
  image[:height]
end

#tag(view_context, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/components/maglev/content/image.rb', line 30

def tag(view_context, options = {})
  view_context.tag(:img,
                   {
                     src: url,
                     alt: alt_text,
                     data: (options.delete(:data) || {}).merge(tag_data)
                   }.merge(options),
                   false)
end

#to_sObject



26
27
28
# File 'app/components/maglev/content/image.rb', line 26

def to_s
  url
end

#urlObject



8
9
10
11
12
# File 'app/components/maglev/content/image.rb', line 8

def url
  return image[:url] if asset_host.nil? || !hosted_on_platform?

  URI.join(asset_host, URI.parse(image[:url]).path).to_s
end

#widthObject



14
15
16
# File 'app/components/maglev/content/image.rb', line 14

def width
  image[:width]
end