summaryrefslogtreecommitdiff
path: root/lib/tasks/assets.rake
blob: 563dfadb1c836a7dad0403b8130924f93b4af691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
namespace :assets do
  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."
  task :regenerate_variants => :environment do
    scope = Asset.images
    scope = scope.where(id: ENV["ASSET_ID"]) if ENV["ASSET_ID"].present?

    scope.find_each do |asset|
      original_path = asset.send(:file_path, :original)

      unless File.exist?(original_path)
        puts "Skipping Asset##{asset.id} (#{asset.name}) -- no original file at #{original_path}"
        next
      end

      asset.send(:generate_variants, original_path)
      puts "Regenerated variants for Asset##{asset.id} (#{asset.name})"
    end
  end
end