Class: Blacklight::ThumbnailPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/blacklight/thumbnail_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, view_context, view_config) ⇒ ThumbnailPresenter

Returns a new instance of ThumbnailPresenter.

Parameters:



11
12
13
14
15
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 11

def initialize(document, view_context, view_config)
  @document = document
  @view_context = view_context
  @view_config = view_config
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 5

def document
  @document
end

#view_configObject (readonly)

Returns the value of attribute view_config.



5
6
7
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 5

def view_config
  @view_config
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



5
6
7
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 5

def view_context
  @view_context
end

Instance Method Details

#exists?Boolean

Does the document have a thumbnail to render?

Returns:

  • (Boolean)


25
26
27
28
29
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 25

def exists?
  thumbnail_method.present? ||
    (thumbnail_field && thumbnail_value_from_document.present?) ||
    default_thumbnail.present?
end

#render(image_options = {}) ⇒ Object



17
18
19
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 17

def render(image_options = {})
  thumbnail_value(image_options)
end

#thumbnail_tag(image_options = {}, url_options = {}) ⇒ String

Render the thumbnail, if available, for a document and link it to the document record.

Parameters:

  • image_options (Hash) (defaults to: {})

    to pass to the image tag

  • url_options (Hash) (defaults to: {})

    to pass to #link_to_document

Returns:

  • (String)


38
39
40
41
42
43
# File 'app/presenters/blacklight/thumbnail_presenter.rb', line 38

def thumbnail_tag image_options = {}, url_options = {}
  value = thumbnail_value(image_options)
  return value if value.nil? || url_options[:suppress_link]

  view_context.link_to_document document, value, url_options
end