Class: Alchemy::GenerateThumbnails
- Inherits:
-
Object
- Object
- Alchemy::GenerateThumbnails
- Defined in:
- lib/alchemy/tasks/generate_thumbnails.rb
Overview
Pre-generates picture thumbnails so they do not have to be rendered on the first request.
Used by the alchemy:generate:thumbnails rake tasks. Works with both
the active_storage and the dragonfly storage adapter.
Both methods yield each processed record, so callers (like the rake task) can report progress without this service having to know about the shell.
With async: true the active_storage variants are enqueued as
+ActiveStorage::TransformJob+s instead of being processed inline. The
dragonfly adapter has no background processor and always runs inline.
Class Method Summary collapse
-
.ingredients(element_names: nil, async: false) {|Alchemy::Ingredients::Picture| ... } ⇒ Object
Pre-generates the thumbnails rendered for published picture ingredients.
-
.pictures(async: false) {|Alchemy::Picture| ... } ⇒ Object
Pre-generates the archive thumbnails (+Alchemy::Picture::THUMBNAIL_SIZES+) for every picture.
Class Method Details
.ingredients(element_names: nil, async: false) {|Alchemy::Ingredients::Picture| ... } ⇒ Object
Pre-generates the thumbnails rendered for published picture ingredients.
Takes the ingredients crop and srcset settings into account, so all variants that the frontend requests are generated upfront.
38 39 40 41 42 43 |
# File 'lib/alchemy/tasks/generate_thumbnails.rb', line 38 def ingredients(element_names: nil, async: false) ingredient_scope(element_names).find_each do |ingredient| generate_for_ingredient(ingredient, async: async) yield ingredient if block_given? end end |
.pictures(async: false) {|Alchemy::Picture| ... } ⇒ Object
Pre-generates the archive thumbnails (+Alchemy::Picture::THUMBNAIL_SIZES+) for every picture. These are the thumbnails used by the picture archive.
23 24 25 26 27 28 |
# File 'lib/alchemy/tasks/generate_thumbnails.rb', line 23 def pictures(async: false) Alchemy::Picture.find_each do |picture| generate_for_picture(picture, async: async) yield picture if block_given? end end |