diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
| commit | 8eab68f2c5a3c126e2fec2ecdfa7ace87ce0937b (patch) | |
| tree | f446ebc26a7707c7b64a937aa51a155df146c80a /lib/tasks/assets.rake | |
| parent | 42714c697273a7117c6b355fab26c8c35e336ad1 (diff) | |
| parent | cdf5d9941ca866d437612d2f863eac6eb0b3db12 (diff) | |
Merge branch 'erdgeist-revive-events'
Diffstat (limited to 'lib/tasks/assets.rake')
| -rw-r--r-- | lib/tasks/assets.rake | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake new file mode 100644 index 0000000..563dfad --- /dev/null +++ b/lib/tasks/assets.rake | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | namespace :assets do | ||
| 2 | desc "Regenerate ImageMagick variants for every image asset from its stored original -- rerun whenever a new style is added to FileAttachment::STYLES after assets already exist. Scope to one asset first with ASSET_ID=123." | ||
| 3 | task :regenerate_variants => :environment do | ||
| 4 | scope = Asset.images | ||
| 5 | scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present? | ||
| 6 | |||
| 7 | scope.find_each do |asset| | ||
| 8 | original_path = asset.send(:file_path, :original) | ||
| 9 | |||
| 10 | unless File.exist?(original_path) | ||
| 11 | puts "Skipping Asset##{asset.id} (#{asset.name}) -- no original file at #{original_path}" | ||
| 12 | next | ||
| 13 | end | ||
| 14 | |||
| 15 | asset.send(:generate_variants, original_path) | ||
| 16 | puts "Regenerated variants for Asset##{asset.id} (#{asset.name})" | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | ||
