installation procedure allows to install the default site template if provided

This commit is contained in:
did 2011-05-28 19:45:29 -07:00
parent c6b272f9f9
commit 61886ec1b1
11 changed files with 91 additions and 29 deletions

View File

@ -42,13 +42,7 @@ module Admin
@site = Site.create_first_one(params[:site])
if @site.valid?
begin
unless params[:zipfile].blank?
Locomotive::Import::Job.run!(params[:zipfile], @site, { :samples => true })
end
rescue Exception => e
logger.error "Import failed because of #{e.message}"
end
Site.install_template(@site, params)
redirect_to last_url
else
@ -61,8 +55,8 @@ module Admin
def is_step_already_done?
case params[:step].to_i
when 1 # already an account in db
if Account.count > 0
@step_done = t('admin.installation.step_1.done', Account.first.attributes)
if account = Account.first
@step_done = I18n.t('admin.installation.step_1.done', :name => account.name, :email => account.email)
render 'step_1' and return false
end
else

View File

@ -13,6 +13,24 @@ module Extensions
site
end
def install_template(site, options = {})
default_template = Boolean.set(options.delete(:default_site_template)) || false
zipfile = options.delete(:zipfile)
# do not try to process anything if said so
return unless default_template || zipfile.present?
# default template options has a higher priority than the zipfile
source = default_template ? Locomotive.default_site_template_path : zipfile
begin
Locomotive::Import::Job.run!(source, site, { :samples => true })
rescue Exception => e
logger.error "The import of the site template failed because of #{e.message}"
end
end
end
end
end

View File

@ -5,6 +5,7 @@
- content_for :head do
= include_stylesheets :installation
= include_javascripts :installation
= semantic_form_for(@site, :url => admin_installation_step_url(2), :html => { :multipart => true }) do |f|
.inner
@ -18,9 +19,16 @@
- if multi_sites?
= f.input :subdomain, :required => true
%li{ :class => 'string optional', :id => 'zipfile_input' }
- if Locomotive.default_site_template_present?
%li{ :class => 'question', :id => 'default_site_template_input' }
= check_box_tag 'default_site_template', '1', params[:default_site_template].blank? || params[:default_site_template] == '1'
%label{ :for => 'default_site_template' }!= t('formtastic.labels.import.new.default_site_template')
%li{ :class => 'string optional', :id => 'zipfile_input', :style => "#{'display: none' if Locomotive.default_site_template_present?}" }
%label{ :for => 'zipfile' }= t('formtastic.labels.import.new.source')
= file_field_tag 'zipfile'
- if Locomotive.default_site_template_present?
%p.inline-hints!= t('.back_to_default_template')
.footer
= box_button_tag t('.next')

View File

@ -7,6 +7,9 @@ s3_secret_access_key: <%= ENV['S3_SECRET_KEY'] %>
javascripts:
box:
- public/javascripts/admin/jquery.js
installation:
- public/javascripts/admin/jquery.js
- public/javascripts/admin/installation.js
common:
- public/javascripts/admin/jquery.js
- public/javascripts/admin/jquery.ui.js

View File

@ -4,7 +4,7 @@ Locomotive::Application.configure do
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = true #false
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
@ -30,11 +30,11 @@ Locomotive::Application.configure do
# set up the bushido stub (uncomment it)
# config.bushido_stub_env = false
config.bushido_stub_env = {
'APP_TLD' => 'bushi.do',
'BUSHIDO_APP' => 'san_francisco',
'BUSHIDO_HOST' => 'bushi.do',
'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST',
'BUSHIDO_CLAIMED' => 'true'
}
# config.bushido_stub_env = {
# 'APP_TLD' => 'bushi.do',
# 'BUSHIDO_APP' => 'san_francisco',
# 'BUSHIDO_HOST' => 'bushi.do',
# 'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST',
# 'BUSHIDO_CLAIMED' => 'true'
# }
end

View File

@ -289,5 +289,6 @@ en:
next: Create account
step_2:
title: "Step 2/2 &mdash; Create your first site"
explanations: "This is the last step of the installation. You can upload a theme as a zip file. We have free available themes <a href=\"http://www.locomotivecms.com/support/themes\">here</a>."
explanations: "If you already uploaded the default site template (see instructions), you can use it right away. Or you can upload a site template as a zip file (free available templates <a href=\"http://www.locomotivecms.com/support/themes\">here</a>)."
back_to_default_template: "Click <a href='#'>here</a> to select the default site template instead"
next: Create site

View File

@ -36,6 +36,7 @@ en:
source: File
samples: Copy samples
reset: Reset site
default_site_template: "Use the default site template. Click <a href='#'>here</a> to upload a site template as a zip file instead."
content_type:
api_accounts: Notified Accounts
account:

View File

@ -39,6 +39,14 @@ module Locomotive
self.const_defined?('Engine')
end
def self.default_site_template_present?
File.exists?(self.default_site_template_path)
end
def self.default_site_template_path
File.join(Rails.root, 'tmp/default_site_template.zip')
end
def self.configure
self.config ||= Configuration.new
@ -96,7 +104,7 @@ module Locomotive
if self.config.multi_sites?
self.config.manage_subdomain = self.config.manage_domains = true
else
# Note: (Did) modify the code below if Locomotive handles a new hosting solution
# Note: (Did) modify the code below if Locomotive handles a new hosting solution (not a perfect solution though)
self.config.manage_domains = self.heroku? || self.bushido?
self.config.manage_subdomain = self.bushido?
end

View File

@ -15,7 +15,7 @@ module Locomotive
if ::Locomotive.bushido_app_claimed?
require_admin_without_bushido
else
# open back-office for everybody as long as the application has not been claimed
# open back-office for everybody as long as the application is not claimed
sign_in(Account.order_by(:created_at).first)
end
end

View File

@ -0,0 +1,17 @@
$(document).ready(function() {
$('#default_site_template_input label a').click(function(e) {
$('#default_site_template_input input[type=checkbox]').attr('checked', '');
$('#default_site_template_input').hide();
$('#zipfile_input').show();
e.preventDefault();
});
$('#zipfile_input p.inline-hints a').click(function(e) {
$('#default_site_template_input input[type=checkbox]').attr('checked', 'checked');
$('#zipfile_input').hide();
$('#default_site_template_input').show();
e.preventDefault();
});
});

View File

@ -4,20 +4,20 @@
color: #222;
}
#panel .inner p.explanations {
margin-top: 10px;
font-size: 1.2em;
}
#panel .inner p.explanations a {
#panel .inner a {
color: #1F82BC;
text-decoration: none;
}
#panel .inner p.explanations a:hover {
#panel .inner a:hover {
text-decoration: underline;
}
#panel .inner p.explanations {
margin-top: 10px;
font-size: 1.2em;
}
#panel .inner p.done {
margin: 20px 0px 15px;
font-size: 1.2em;
@ -45,6 +45,18 @@
}
#panel .inner dd p {
}
/* ___ custom ___ */
#panel fieldset ol li.question input[type=checkbox] {
display: inline;
width: auto;
margin-right: 10px;
}
#panel fieldset ol li.question label {
display: inline;
font-weight: normal;
}