From 09bd73c7ac0fef1186c0458c903edb9d567d25b7 Mon Sep 17 00:00:00 2001 From: did Date: Thu, 7 Apr 2011 11:53:07 +0200 Subject: [PATCH] enhance carrierwave settings to support bushi.do --- app/uploaders/asset_uploader.rb | 2 +- app/uploaders/editable_file_uploader.rb | 2 +- app/uploaders/theme_asset_uploader.rb | 2 +- app/uploaders/theme_uploader.rb | 2 +- app/views/admin/current_sites/_form.html.haml | 2 +- config/initializers/carrierwave.rb | 1 + lib/locomotive/carrierwave/patches.rb | 20 +++++++++++++++++++ 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb index 58df579e..075829cb 100644 --- a/app/uploaders/asset_uploader.rb +++ b/app/uploaders/asset_uploader.rb @@ -5,7 +5,7 @@ class AssetUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick def store_dir - "sites/#{model.collection.site_id}/assets/#{model.id}" + self.build_store_dir('sites', model.collection.site_id, 'assets', model.id) end # def cache_dir diff --git a/app/uploaders/editable_file_uploader.rb b/app/uploaders/editable_file_uploader.rb index 3182cf89..de672854 100644 --- a/app/uploaders/editable_file_uploader.rb +++ b/app/uploaders/editable_file_uploader.rb @@ -1,7 +1,7 @@ class EditableFileUploader < ::CarrierWave::Uploader::Base def store_dir - "sites/#{model.page.site_id}/pages/#{model.page.id}/files" + self.build_store_dir('sites', model.page.site_id, 'pages', model.page.id, 'files') end # def cache_dir diff --git a/app/uploaders/theme_asset_uploader.rb b/app/uploaders/theme_asset_uploader.rb index 78cdd75c..1283dca6 100644 --- a/app/uploaders/theme_asset_uploader.rb +++ b/app/uploaders/theme_asset_uploader.rb @@ -7,7 +7,7 @@ class ThemeAssetUploader < AssetUploader process :set_width_and_height def store_dir - File.join('sites', (model.site_id_was || model.site_id).to_s, 'theme', model.folder_was || model.folder) + self.build_store_dir('sites', (model.site_id_was || model.site_id).to_s, 'theme', model.folder_was || model.folder) end def stale_model? diff --git a/app/uploaders/theme_uploader.rb b/app/uploaders/theme_uploader.rb index 1be924aa..7ad75909 100644 --- a/app/uploaders/theme_uploader.rb +++ b/app/uploaders/theme_uploader.rb @@ -2,7 +2,7 @@ class ThemeUploader < ::CarrierWave::Uploader::Base def store_dir if Locomotive.config.delayed_job - "sites/#{model.id}/tmp/themes" + self.build_store_dir('sites', model.id, 'tmp', 'themes') else "#{Rails.root}/tmp/themes" end diff --git a/app/views/admin/current_sites/_form.html.haml b/app/views/admin/current_sites/_form.html.haml index 58d4e5e9..17c082f7 100644 --- a/app/views/admin/current_sites/_form.html.haml +++ b/app/views/admin/current_sites/_form.html.haml @@ -15,7 +15,7 @@ = f.custom_input :subdomain, :css => 'path' do %em http:// - = f.text_field :subdomain, :disabled => (manage_subdomain? ? '' : 'disabled') + = f.text_field :subdomain, :readonly => !manage_subdomain? \. %em = application_domain diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index e2111767..ddfd4e26 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -21,6 +21,7 @@ CarrierWave.configure do |config| if Locomotive.bushido? config.storage = :file config.root = File.join(Rails.root, 'public', 'store') + config.store_dir = 'store' else config.storage = :s3 config.s3_access_key_id = ENV['S3_KEY_ID'] diff --git a/lib/locomotive/carrierwave/patches.rb b/lib/locomotive/carrierwave/patches.rb index 1df1cb2e..19f09230 100644 --- a/lib/locomotive/carrierwave/patches.rb +++ b/lib/locomotive/carrierwave/patches.rb @@ -33,6 +33,26 @@ module CarrierWave end + module Uploader + + class Base + + # alias :super_store_dir :store_dir + + def build_store_dir(*args) + default_dir = self.class.store_dir + + if default_dir.blank? || default_dir == 'uploads' + File.join(args) + else + File.join([default_dir] + args) + end + end + + end + + end + end module CarrierWave