From e03d7b5dcc4135873e4f2aa30ea5cab9f6b900be Mon Sep 17 00:00:00 2001 From: did Date: Thu, 7 Apr 2011 01:34:36 +0200 Subject: [PATCH] smoother integration with bushi.do --- Gemfile | 3 ++- Gemfile.lock | 16 +++++++------- app/uploaders/asset_uploader.rb | 6 +++--- app/uploaders/editable_file_uploader.rb | 6 +++--- app/uploaders/theme_uploader.rb | 6 +++--- config/initializers/carrierwave.rb | 21 +++++++++++++------ config/mongoid.yml | 5 ++--- .../locomotive/install/install_generator.rb | 4 ++-- .../install/templates/carrierwave.rb | 19 +++++++++++++++++ .../hosting/bushido/custom_domain.rb | 4 +++- spec/lib/locomotive/bushido_spec.rb | 4 ++-- 11 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 lib/generators/locomotive/install/templates/carrierwave.rb diff --git a/Gemfile b/Gemfile index 7c8c2397..89e23e62 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,8 @@ gem 'locomotive_carrierwave', '0.5.0.1.beta3', :require => 'carrierwave' gem 'custom_fields', '1.0.0.beta.9' gem 'fog', '0.3.7' gem 'mimetype-fu' -gem 'actionmailer_with_request', :git => 'git://github.com/eric1234/actionmailer_with_request.git' +gem 'actionmailer-with-request', :git => 'git://github.com/weppos/actionmailer_with_request.git' +#:git => 'git://github.com/eric1234/actionmailer_with_request.git' gem 'heroku', '1.19.1' # '1.18.2' gem 'bushido' gem 'httparty', '>= 0.6.1' diff --git a/Gemfile.lock b/Gemfile.lock index d5140c6e..befde08f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,16 @@ -GIT - remote: git://github.com/eric1234/actionmailer_with_request.git - revision: 6dd5658d44cc3624596a4fc57e6cde08b7e3bf43 - specs: - actionmailer_with_request (0.0.3) - rails (>= 3) - GIT remote: git://github.com/floehopper/mocha.git revision: 2b4e868d1907859cd03f407078bd8b630f7d0dd6 specs: mocha (0.9.12.20110213002255) +GIT + remote: git://github.com/weppos/actionmailer_with_request.git + revision: c1f18f4541554367fe5910fc1bc8caecd7d09682 + specs: + actionmailer-with-request (0.3.0) + rails (>= 3) + GIT remote: https://github.com/wunderbread/xpath.git revision: d04da707886287e7dfe82705fda5b3d4f65e94c3 @@ -274,7 +274,7 @@ DEPENDENCIES RedCloth (= 4.2.7) SystemTimer ZenTest - actionmailer_with_request! + actionmailer-with-request! autotest bson_ext (~> 1.3.0) bushido diff --git a/app/uploaders/asset_uploader.rb b/app/uploaders/asset_uploader.rb index 5fa4b766..58df579e 100644 --- a/app/uploaders/asset_uploader.rb +++ b/app/uploaders/asset_uploader.rb @@ -8,9 +8,9 @@ class AssetUploader < CarrierWave::Uploader::Base "sites/#{model.collection.site_id}/assets/#{model.id}" end - def cache_dir - "#{Rails.root}/tmp/uploads" - end + # def cache_dir + # "#{Rails.root}/tmp/uploads" + # end version :thumb, :if => :image? do process :resize_to_fill => [50, 50] diff --git a/app/uploaders/editable_file_uploader.rb b/app/uploaders/editable_file_uploader.rb index db805737..3182cf89 100644 --- a/app/uploaders/editable_file_uploader.rb +++ b/app/uploaders/editable_file_uploader.rb @@ -4,8 +4,8 @@ class EditableFileUploader < ::CarrierWave::Uploader::Base "sites/#{model.page.site_id}/pages/#{model.page.id}/files" end - def cache_dir - "#{Rails.root}/tmp/uploads" - end + # def cache_dir + # "#{Rails.root}/tmp/uploads" + # end end \ No newline at end of file diff --git a/app/uploaders/theme_uploader.rb b/app/uploaders/theme_uploader.rb index 3f17dff8..1be924aa 100644 --- a/app/uploaders/theme_uploader.rb +++ b/app/uploaders/theme_uploader.rb @@ -8,9 +8,9 @@ class ThemeUploader < ::CarrierWave::Uploader::Base end end - def cache_dir - "#{Rails.root}/tmp/uploads" - end + # def cache_dir + # "#{Rails.root}/tmp/uploads" + # end def extension_white_list %w(zip) diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 613e557f..e2111767 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,3 +1,5 @@ +require 'locomotive' + # TODO: Make this store to RAILS_ROOT/permanent # On bushido, the app directory is destroyed on every update, so everything is lost. @@ -7,6 +9,8 @@ CarrierWave.configure do |config| + config.cache_dir = File.join(Rails.root, 'tmp', 'uploads') + case Rails.env.to_sym when :development @@ -14,11 +18,16 @@ CarrierWave.configure do |config| config.root = File.join(Rails.root, 'public') when :production - config.storage = :s3 - config.s3_access_key_id = ENV['S3_KEY_ID'] - config.s3_secret_access_key = ENV['S3_SECRET_KEY'] - config.s3_bucket = ENV['S3_BUCKET'] - # config.s3_cname = 'ENV['S3_CNAME'] + if Locomotive.bushido? + config.storage = :file + config.root = File.join(Rails.root, 'public', 'store') + else + config.storage = :s3 + config.s3_access_key_id = ENV['S3_KEY_ID'] + config.s3_secret_access_key = ENV['S3_SECRET_KEY'] + config.s3_bucket = ENV['S3_BUCKET'] + # config.s3_cname = 'ENV['S3_CNAME'] + end end -end +end unless Locomotive.engine? diff --git a/config/mongoid.yml b/config/mongoid.yml index 1ff4cd9b..8b08b667 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -17,11 +17,10 @@ test: # set these environment variables on your prod server production: - <<: *defaults - database: locomotive_prod + # <<: *defaults + # database: locomotive_prod # other settings for production - # host: <%= ENV['MONGOID_HOST'] %> # port: <%= ENV['MONGOID_PORT'] %> # username: <%= ENV['MONGOID_USERNAME'] %> diff --git a/lib/generators/locomotive/install/install_generator.rb b/lib/generators/locomotive/install/install_generator.rb index 1512736e..e4a0644e 100644 --- a/lib/generators/locomotive/install/install_generator.rb +++ b/lib/generators/locomotive/install/install_generator.rb @@ -13,13 +13,13 @@ module Locomotive end def copy_initializers - copy_file 'config/initializers/carrierwave.rb', 'config/initializers/carrierwave.rb' - @source_paths = nil # reset it for the find_in_source_paths method Locomotive::InstallGenerator.source_root(File.expand_path('../templates', __FILE__)) template 'locomotive.rb', 'config/initializers/locomotive.rb' + + template 'carrierwave.rb', 'config/initializers/carrierwave.rb' end def remove_index_html diff --git a/lib/generators/locomotive/install/templates/carrierwave.rb b/lib/generators/locomotive/install/templates/carrierwave.rb new file mode 100644 index 00000000..1f6fdcb5 --- /dev/null +++ b/lib/generators/locomotive/install/templates/carrierwave.rb @@ -0,0 +1,19 @@ +CarrierWave.configure do |config| + + config.cache_dir = File.join(Rails.root, 'tmp', 'uploads') + + case Rails.env.to_sym + + when :development + config.storage = :file + config.root = File.join(Rails.root, 'public') + + when :production + config.storage = :s3 + config.s3_access_key_id = ENV['S3_KEY_ID'] + config.s3_secret_access_key = ENV['S3_SECRET_KEY'] + config.s3_bucket = ENV['S3_BUCKET'] + # config.s3_cname = 'ENV['S3_CNAME'] + end + +end \ No newline at end of file diff --git a/lib/locomotive/hosting/bushido/custom_domain.rb b/lib/locomotive/hosting/bushido/custom_domain.rb index b171b95f..c55edfd2 100644 --- a/lib/locomotive/hosting/bushido/custom_domain.rb +++ b/lib/locomotive/hosting/bushido/custom_domain.rb @@ -8,7 +8,7 @@ module Locomotive included do validate :subdomain_availability - before_save :check_subdomain_change + before_update :check_subdomain_change after_save :add_bushido_domains after_update :record_new_subdomain @@ -22,6 +22,8 @@ module Locomotive protected def subdomain_availability + return true if self.new_record? + unless ::Bushido::App.subdomain_available?(self.subdomain) self.errors.add(:subdomain, :exclusion) end diff --git a/spec/lib/locomotive/bushido_spec.rb b/spec/lib/locomotive/bushido_spec.rb index faf60e88..79193f92 100644 --- a/spec/lib/locomotive/bushido_spec.rb +++ b/spec/lib/locomotive/bushido_spec.rb @@ -46,7 +46,7 @@ describe 'Bushido support' do context '#enabled' do it 'tells bushido is enabled from ENV' do - ENV['HOSTING_PLATFORM'] = 'bushido' + ENV['APP_TLD'] = 'bushi.do' Locomotive.config.hosting = :auto Locomotive.bushido?.should be_true end @@ -165,7 +165,7 @@ describe 'Bushido support' do end after(:all) do - ENV['HOSTING_PLATFORM'] = ENV['APP_TLD'] = nil + ENV['APP_TLD'] = nil Locomotive.configure_for_test(true) end