Class: Alchemy::Ingredients::PictureView
- Includes:
- LinkTarget
- Defined in:
- app/components/alchemy/ingredients/picture_view.rb
Overview
Renders a picture ingredient view
Constant Summary
Constants included from LinkTarget
LinkTarget::BLANK_VALUE, LinkTarget::REL_VALUE
Instance Attribute Summary collapse
-
#disable_link ⇒ Object
readonly
Returns the value of attribute disable_link.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#ingredient ⇒ Object
readonly
Returns the value of attribute ingredient.
-
#picture ⇒ Object
readonly
Returns the value of attribute picture.
-
#picture_options ⇒ Object
readonly
Returns the value of attribute picture_options.
-
#show_caption ⇒ Object
readonly
Returns the value of attribute show_caption.
-
#sizes ⇒ Object
readonly
Returns the value of attribute sizes.
-
#srcset ⇒ Object
readonly
Returns the value of attribute srcset.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(ingredient, show_caption: nil, disable_link: nil, srcset: nil, sizes: nil, picture_options: {}, html_options: {}) ⇒ PictureView
constructor
A new instance of PictureView.
Methods included from LinkTarget
#link_rel_value, #link_target_value
Methods inherited from BaseView
Constructor Details
#initialize(ingredient, show_caption: nil, disable_link: nil, srcset: nil, sizes: nil, picture_options: {}, html_options: {}) ⇒ PictureView
Returns a new instance of PictureView.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 26 def initialize( ingredient, show_caption: nil, disable_link: nil, srcset: nil, sizes: nil, picture_options: {}, html_options: {} ) super(ingredient) @show_caption = settings_value(:show_caption, value: show_caption, default: true) @disable_link = settings_value(:disable_link, value: disable_link, default: false) @srcset = settings_value(:srcset, value: srcset, default: []) @sizes = settings_value(:sizes, value: sizes, default: []) @picture_options = || {} @html_options = || {} @picture = ingredient.picture end |
Instance Attribute Details
#disable_link ⇒ Object (readonly)
Returns the value of attribute disable_link.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def disable_link @disable_link end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def @html_options end |
#ingredient ⇒ Object (readonly)
Returns the value of attribute ingredient.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def ingredient @ingredient end |
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def picture @picture end |
#picture_options ⇒ Object (readonly)
Returns the value of attribute picture_options.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def @picture_options end |
#show_caption ⇒ Object (readonly)
Returns the value of attribute show_caption.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def show_caption @show_caption end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def sizes @sizes end |
#srcset ⇒ Object (readonly)
Returns the value of attribute srcset.
9 10 11 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 9 def srcset @srcset end |
Instance Method Details
#call ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 45 def call return if picture.blank? output = caption ? img_tag + caption : img_tag if is_linked? target = ingredient.link_target.presence output = link_to(output, url_for(ingredient.link), { title: ingredient.link_title.presence, rel: link_rel_value(target), target: link_target_value(target) }) end if caption content_tag(:figure, output, {class: ingredient.css_class.presence}.merge()) else output end.html_safe end |