Skip to content

Commit 91df5ea

Browse files
committed
feat: preliminary AssetFieldType dynamic path generation
1 parent aa2dd70 commit 91df5ea

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

app/uploaders/asset_uploader.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class AssetUploader < Shrine
77
plugin :store_dimensions
88
plugin :validation_helpers
99
plugin :cortex_validation_helpers
10-
plugin :pretty_location
1110
plugin :processing
1211
plugin :versions
1312
plugin :keep_files, destroyed: true, replaced: true
@@ -38,6 +37,16 @@ class AssetUploader < Shrine
3837
end
3938
end
4039

40+
def _generate_location(io, context)
41+
# TODO: This is broken
42+
attachment = :asset
43+
media_title = ''
44+
style = context[:version] || :original
45+
name = super
46+
47+
ERB.new(context[:metadata][:path]).result # TODO: Shrine is overwriting metadata..
48+
end
49+
4150
def image?(io)
4251
MimeMagic.new(io.data['metadata']['mime_type']).mediatype == 'image'
4352
end

config/initializers/shrine.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
}
88

99
Shrine.plugin :logging, logger: Rails.logger
10-
Shrine.plugin :cached_attachment_data

lib/tasks/cortex/core/media.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace :cortex do
4040
micro: { process: { method: 'resize_to_limit', config: { width: '50', height: '50' } }, format: :jpg },
4141
},
4242
keep_files: [:destroyed, :replaced],
43-
path: ':class/:attachment/:media_title-:style.:extension',
43+
path: '<%= attachment %>/<%= media_title %>-<%= style %>',
4444
storage: {
4545
type: 's3',
4646
host_alias: ENV['HOST_ALIAS'],

0 commit comments

Comments
 (0)