Class: Alchemy::Ingredients::Picture
- Inherits:
-
Alchemy::Ingredient
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Ingredient
- Alchemy::Ingredients::Picture
- Includes:
- PictureThumbnails
- Defined in:
- app/models/alchemy/ingredients/picture.rb
Overview
A picture assignment
Assign Alchemy::Picture to this ingredient
Optionally you can add a link As well as set the alt tag, a caption and title
Constant Summary
Constants included from SearchableResource
SearchableResource::SEARCHABLE_COLUMN_TYPES
Instance Method Summary collapse
- #alt_text(language: Alchemy::Current.language) ⇒ Object
-
#as_view_component(options: {}, html_options: {}) ⇒ Object
The picture view component with mapped options.
-
#preview_text(max_length = 30) ⇒ Object
The first 30 characters of the pictures name.
Methods included from PictureThumbnails
#allow_image_cropping?, #image_cropper_settings, #picture_url, #picture_url_options, #thumbnail_url, #thumbnail_url_options
Methods inherited from Alchemy::Ingredient
allow_settings, allowed_settings, #definition, #deprecated?, #has_hint?, #has_tinymce?, #has_validations?, normalize_type, #partial_name, #preview_ingredient?, related_object_alias, #settings, #to_partial_path, translated_label_for, #value
Methods included from Hints
Methods included from SearchableResource
#ransackable_associations, #ransackable_attributes, #ransortable_attributes
Instance Method Details
#alt_text(language: Alchemy::Current.language) ⇒ Object
41 42 43 44 45 |
# File 'app/models/alchemy/ingredients/picture.rb', line 41 def alt_text(language: Alchemy::Current.language) alt_tag.presence || picture&.description_for(language) || picture&.name&.humanize end |
#as_view_component(options: {}, html_options: {}) ⇒ Object
The picture view component with mapped options.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/alchemy/ingredients/picture.rb', line 63 def as_view_component(options: {}, html_options: {}) PictureView.new( self, show_caption: .delete(:show_caption), disable_link: .delete(:disable_link), srcset: .delete(:srcset), sizes: .delete(:sizes), picture_options: , html_options: ) end |
#preview_text(max_length = 30) ⇒ Object
The first 30 characters of the pictures name
Used by the Element#preview_text method.
53 54 55 |
# File 'app/models/alchemy/ingredients/picture.rb', line 53 def preview_text(max_length = 30) picture&.name.to_s[0..max_length - 1] end |