the theme import module can work without delayedjob + fix bugs

This commit is contained in:
dinedine 2010-12-17 00:42:38 +01:00
parent 727a824745
commit 62564021b6
18 changed files with 82 additions and 47 deletions

View File

@ -54,7 +54,7 @@ GEM
ZenTest (>= 4.4.1)
bcrypt-ruby (2.1.2)
bson (1.1.5)
bson_ext (1.1.4)
bson_ext (1.1.5)
builder (2.1.2)
capybara (0.4.0)
celerity (>= 0.7.9)
@ -261,7 +261,7 @@ DEPENDENCIES
RedCloth
actionmailer-with-request
autotest
bson_ext (= 1.1.4)
bson_ext (= 1.1.5)
capybara
cucumber (= 0.8.5)
cucumber-rails

View File

@ -21,7 +21,7 @@ module Admin
format.json { render :json => { :content => @content, :errors => @content.errors } }
format.html do
flash[@content_type.slug.singularize] = @content.aliased_attributes
flash[:errors] = content.errors
flash['errors'] = @content.errors_to_hash
redirect_to params[:error_callback]
end
end

View File

@ -23,16 +23,14 @@ module Admin
def create
begin
job = Locomotive::Import::Job.new(params[:zipfile], current_site, {
Locomotive::Import::Job.run!(params[:zipfile], current_site, {
:samples => Boolean.set(params[:samples]),
:reset => Boolean.set(params[:reset])
})
Delayed::Job.enqueue job, { :site => current_site, :job_type => 'import' }
flash[:notice] = t('flash.admin.imports.create.notice')
redirect_to admin_import_url
redirect_to Locomotive.config.delayed_job ? admin_import_url : new_admin_import_url
rescue
@error = t('errors.messages.invalid_theme_file')
flash[:alert] = t('flash.admin.imports.create.alert')

View File

@ -44,12 +44,11 @@ module Admin
@site.save
if @site.valid?
begin
job = Locomotive::Import::Job.new(params[:zipfile], @site, { :samples => true })
Delayed::Job.enqueue job, { :site => @site, :job_type => 'import' }
rescue Exception => e
logger.error "Import failed because of #{e.message}"
end
# begin
Locomotive::Import::Job.run!(params[:zipfile], @site, { :samples => true })
# rescue Exception => e
# logger.error "Import failed because of #{e.message}"
# end
redirect_to admin_session_url(:host => Site.first.domains.first, :port => request.port)
else

View File

@ -52,6 +52,10 @@ class ContentInstance
hash
end
def errors_to_hash
Hash.new.replace(self.errors)
end
def to_liquid
Locomotive::Liquid::Drops::Content.new(self)
end

View File

@ -27,9 +27,4 @@ Locomotive::Application.configure do
:port => 1025,
:domain => "example.com"
}
end
CarrierWave.configure do |config|
config.storage = :file
config.root = File.join(Rails.root, 'public')
end

View File

@ -45,14 +45,4 @@ Locomotive::Application.configure do
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
# TODO: Put your carrierwave config down here
CarrierWave.configure do |config|
config.storage = :s3
config.s3_access_key_id = 'AKIAIPXDQKLBLIOF34VA'
config.s3_secret_access_key = 'BjyBbrd4L2Q3cydeaqlKq6Il18IkHbvXV/NpqQJH'
config.s3_bucket = 'locomotivehosting'
config.s3_cname = 'cdn.locomotivehosting.com'
end

View File

@ -32,8 +32,4 @@ Locomotive::Application.configure do
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end
CarrierWave.configure do |config|
config.storage = :file
end
end

View File

@ -0,0 +1,17 @@
CarrierWave.configure do |config|
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

View File

@ -26,6 +26,11 @@ Locomotive.configure do |config|
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
config.heroku = false
# Locomotive uses the DelayedJob gem for the theme import module.
# In case you want to deploy to Heroku, you will have to pay for an extra dyno.
# If you do not mind about importing theme without DelayedJob, disable it.
config.delayed_job = true
# default locale (for now, only en and fr are supported)
config.default_locale = :en
end

View File

@ -1,8 +1,8 @@
BOARD:
x jammit-s3: assets
- copy assets.yml config file when using it as gem (http://asciicasts.com/episodes/218-making-generators-in-rails-3)
- import theme without delayed_job
x copy assets.yml config file when using it as gem (http://asciicasts.com/episodes/218-making-generators-in-rails-3)
x import theme without delayed_job
BACKLOG:

View File

@ -8,11 +8,13 @@ module Locomotive
end
def copy_assets
directory 'public', 'public', :recursive => true
copy_file 'config/assets.yml', 'config/assets.yml'
end
directory 'public', 'public', :recursive => true
copy_file 'config/assets.yml', 'config/assets.yml'
end
def copy_initializers
copy_file 'config/initializers/carrierwave.rb', 'config/initializers/carrierwave.rb'
def copy_initializer
@source_paths = nil # reset it for the find_in_source_paths method
Locomotive::InstallGenerator.source_root(File.expand_path('../templates', __FILE__))

View File

@ -1,8 +1,12 @@
===============================================================================
The Locomotive initializer has been added to your application.
The Locomotive Engine has been correctly installed in your Rails application.
1. Edit the config/initializers/locomotive.rb file (+ the config/mongoid.yml one)
1. Edit the main config files:
- config/initializers/locomotive.rb
- config/initializers/carrierwave.rb
- config/mongoid.yml
2. Launch the server
@ -16,4 +20,8 @@ The Locomotive initializer has been added to your application.
5. Enjoy !
Note: If you want to use DelayedJob, be sure to launch it:
> rake jobs:work
===============================================================================

View File

@ -23,4 +23,9 @@ Locomotive.configure do |config|
# Ex:
# config.heroku = { :name => '<my heroku app name>', :login => 'john@doe.net', :password => 'easy' }
config.heroku = false
# Locomotive uses the DelayedJob gem for the theme import module.
# In case you want to deploy to Heroku, you will have to pay for an extra dyno.
# If you do not mind about importing theme without DelayedJob, disable it.
config.delayed_job = true
end

View File

@ -11,6 +11,7 @@ module Locomotive
:cookie_key => '_locomotive_session',
:enable_logs => false,
:heroku => false,
:delayed_job => true,
:default_locale => :en
}

View File

@ -53,7 +53,7 @@ module Locomotive
def success(worker)
self.log 'deleting original zip file'
uploader = ThemeUploader.new(@site)
uploader = self.get_uploader(@site)
uploader.retrieve_from_store!(@identifier)
@ -64,6 +64,16 @@ module Locomotive
FileUtils.rm_rf(themes_folder) rescue nil
end
def self.run!(zipfile, site, options = {})
job = self.new(zipfile, site, options)
if Locomotive.config.delayed_job
Delayed::Job.enqueue job, { :site => site, :job_type => 'import' }
else
job.perform
end
end
protected
def themes_folder
@ -81,7 +91,7 @@ module Locomotive
file = CarrierWave::SanitizedFile.new(zipfile)
uploader = ThemeUploader.new(@site)
uploader = self.get_uploader(@site)
begin
uploader.store!(file)
@ -93,7 +103,7 @@ module Locomotive
end
def retrieve_zipfile
uploader = ThemeUploader.new(@site)
uploader = self.get_uploader(@site)
uploader.retrieve_from_store!(@identifier)
@ -136,7 +146,6 @@ module Locomotive
zipfile.extract(entry, File.join(destination_path, entry.name))
end
end
end
def reset!
@ -146,6 +155,13 @@ module Locomotive
@site.asset_collections.destroy_all
end
def get_uploader(site)
unless Locomotive.config.delayed_job
ThemeUploader.storage = :file
end
@uploader ||= ThemeUploader.new(site)
end
end
end
end

View File

@ -26,7 +26,6 @@ module Locomotive
end
def require_site
Locomotive.logger "[require_site] #{Account.count} account(s) / #{Site.count} site(s)"
redirect_to admin_installation_url and return false if Account.count == 0 || Site.count == 0
render_no_site_error and return false if current_site.nil?

View File

@ -26,7 +26,7 @@
#page-toolbar ul li.link a {
display: block;
background: transparent url('/images/admin/inline_editor/action-left.png') no-repeat 0 0;
height: 20px;
height: 18px;
line-height: 20px;
padding-left: 24px;
text-decoration: none;