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



20
21
22
# File 'app/components/maglev/content/image.rb', line 20

def alt_text
  image[:alt_text]
end

#heightObject



16
17
18
# File 'app/components/maglev/content/image.rb', line 16

def height
  image[:height]
end

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



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

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



24
25
26
# File 'app/components/maglev/content/image.rb', line 24

def to_s
  url
end

#urlObject



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

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



12
13
14
# File 'app/components/maglev/content/image.rb', line 12

def width
  image[:width]
end