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
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of EssencePictureView.



15
16
17
18
19
20
21
# File 'app/models/alchemy/essence_picture_view.rb', line 15

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'app/models/alchemy/essence_picture_view.rb', line 8

def content
  @content
end

#essenceObject (readonly)

Returns the value of attribute essence.



8
9
10
# File 'app/models/alchemy/essence_picture_view.rb', line 8

def essence
  @essence
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



8
9
10
# File 'app/models/alchemy/essence_picture_view.rb', line 8

def html_options
  @html_options
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'app/models/alchemy/essence_picture_view.rb', line 8

def options
  @options
end

#pictureObject (readonly)

Returns the value of attribute picture.



8
9
10
# File 'app/models/alchemy/essence_picture_view.rb', line 8

def picture
  @picture
end

Instance Method Details

#renderObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/alchemy/essence_picture_view.rb', line 23

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