Class: Mtl::Rails::CardFilePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/mtl/rails/card_file_presenter.rb

Overview

Private Specialised renderer for the file card element used in a file collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ CardFilePresenter

Returns a new instance of CardFilePresenter.



10
11
12
# File 'lib/mtl/rails/card_file_presenter.rb', line 10

def initialize(view)
  @view = view
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



8
9
10
# File 'lib/mtl/rails/card_file_presenter.rb', line 8

def view
  @view
end

Instance Method Details

#render(filename, href, params = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mtl/rails/card_file_presenter.rb', line 14

def render(filename, href, params = {})
  params = params.reverse_merge type: File.extname(filename).delete('.')
  params[:href] = href
  card_params = { title: params[:title] || filename,
                  class: ['card-panel', params[:preview] ? 'card-panel-image' : nil],
                  data: data(filename, params),
                  style: if params[:preview]
                           "background-image: url(#{URI.encode(params[:preview])})"
                         end }
  if params[:modal]
    view. :div, render_body(filename, params), card_params
  else
    view.link_to render_body(filename, params), href, card_params.merge(target: '_blank')
  end
end

#render_body(filename, params) ⇒ Object



30
31
32
# File 'lib/mtl/rails/card_file_presenter.rb', line 30

def render_body(filename, params)
  view.safe_join [label(filename, params[:title]), infos(params), delete(params), download(filename, params)]
end