summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/tasks/assets.rake19
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 @@
1namespace :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
19end