Class: Alchemy::Ingredients::PictureView
- Defined in:
- app/components/alchemy/ingredients/picture_view.rb
Overview
Renders a picture ingredient view
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 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 24 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: , 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.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def disable_link @disable_link end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def @html_options end |
#ingredient ⇒ Object (readonly)
Returns the value of attribute ingredient.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def ingredient @ingredient end |
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def picture @picture end |
#picture_options ⇒ Object (readonly)
Returns the value of attribute picture_options.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def @picture_options end |
#show_caption ⇒ Object (readonly)
Returns the value of attribute show_caption.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def @show_caption end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def sizes @sizes end |
#srcset ⇒ Object (readonly)
Returns the value of attribute srcset.
7 8 9 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 7 def srcset @srcset end |
Instance Method Details
#call ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/components/alchemy/ingredients/picture_view.rb', line 43 def call return if picture.blank? output = ? img_tag + : img_tag if is_linked? output = link_to(output, url_for(ingredient.link), { title: ingredient.link_title.presence, target: (ingredient.link_target == "blank") ? "_blank" : nil, data: {link_target: ingredient.link_target.presence} }) end if content_tag(:figure, output, {class: ingredient.css_class.presence}.merge()) else output end end |