Class: Alchemy::Ingredients::FileView
- Inherits:
-
BaseView
- Object
- ViewComponent::Base
- BaseView
- Alchemy::Ingredients::FileView
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.
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
#call ⇒ Object
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)
)
end
|
29
30
31
|
# File 'app/components/alchemy/ingredients/file_view.rb', line 29
def render?
!attachment.nil?
end
|