Class: Alchemy::EssencePictureView

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::UrlHelper
Defined in:
app/models/alchemy/essence_picture_view.rb

Overview

Renders an essence picture view

Constant Summary collapse

DEFAULT_OPTIONS =
{
  show_caption: true,
  disable_link: false,
  srcset: [],
  sizes: []
}.with_indifferent_access

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, options = {}, html_options = {}) ⇒ EssencePictureView

Returns a new instance of EssencePictureView.


19
20
21
22
23
24
25
# File 'app/models/alchemy/essence_picture_view.rb', line 19

def initialize(content, options = {}, html_options = {})
  @content = content
  @options = DEFAULT_OPTIONS.merge(content.settings).merge(options)
  @html_options = html_options
  @essence = content.essence
  @picture = essence.picture
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content


10
11
12
# File 'app/models/alchemy/essence_picture_view.rb', line 10

def content
  @content
end

#essenceObject (readonly)

Returns the value of attribute essence


10
11
12
# File 'app/models/alchemy/essence_picture_view.rb', line 10

def essence
  @essence
end

#html_optionsObject (readonly)

Returns the value of attribute html_options


10
11
12
# File 'app/models/alchemy/essence_picture_view.rb', line 10

def html_options
  @html_options
end

#optionsObject (readonly)

Returns the value of attribute options


10
11
12
# File 'app/models/alchemy/essence_picture_view.rb', line 10

def options
  @options
end

#pictureObject (readonly)

Returns the value of attribute picture


10
11
12
# File 'app/models/alchemy/essence_picture_view.rb', line 10

def picture
  @picture
end

Instance Method Details

#renderObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/alchemy/essence_picture_view.rb', line 27

def render
  return if picture.blank?

  output = caption ? img_tag + caption : img_tag

  if is_linked?
    output = link_to(output, url_for(essence.link), {
      title: essence.link_title.presence,
      target: essence.link_target == "blank" ? "_blank" : nil,
      data: {link_target: essence.link_target.presence}
    })
  end

  if caption
    (:figure, output, {class: essence.css_class.presence}.merge(html_options))
  else
    output
  end
end