Class: Alchemy::Ingredients::FileView

Inherits:
BaseView
  • Object
show all
Defined in:
app/components/alchemy/ingredients/file_view.rb

Instance Attribute Summary

Attributes inherited from BaseView

#html_options, #ingredient

Instance Method Summary collapse

Constructor Details

#initialize(ingredient, link_text: nil, html_options: {}) ⇒ FileView

Returns a new instance of FileView.

Parameters:

  • ingredient (Alchemy::Ingredient)
  • link_text (String) (defaults to: nil)

    The link text. If not given, the ingredients link_text setting or the attachments name will be used.

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

    Options that will be passed to the a tag.



9
10
11
12
# File 'app/components/alchemy/ingredients/file_view.rb', line 9

def initialize(ingredient, link_text: nil, html_options: {})
  super(ingredient, html_options: html_options)
  @link_text = settings_value(:link_text, value: link_text, default: attachment&.name)
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/alchemy/ingredients/file_view.rb', line 14

def call
  link_to(
    link_text,
    attachment.url(
      download: true,
      name: attachment.slug,
      format: attachment.suffix
    ),
    {
      class: ingredient.css_class.presence,
      title: ingredient.title.presence
    }.merge(html_options)
  ).html_safe
end

#render?Boolean

Returns:



29
30
31
# File 'app/components/alchemy/ingredients/file_view.rb', line 29

def render?
  !attachment.nil?
end