refactor the way locomotive was updating a template and its descendants + add custom action_mailer settings for the bushi.do env + fix bug about index and 404 pages positions during the import + fix a little display issue when a subdomain is wrong in the site edit page

This commit is contained in:
did 2011-04-28 17:04:18 +02:00
parent 356715bc77
commit a01e204d29
9 changed files with 57 additions and 31 deletions

View File

@ -80,21 +80,15 @@ module Extensions
# group them by fullpath for better performance
cached = template_descendants.inject({}) { |memo, page| memo[page.fullpath] = page; memo }
self._update_direct_template_descendants(template_descendants, cached)
# finally save them all
template_descendants.map(&:save)
end
def _update_direct_template_descendants(template_descendants, cached)
direct_descendants = template_descendants.select do |page|
((page.template_dependencies || []) - (self.template_dependencies || [])).size == 1
template_descendants.each do |page|
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })
end
direct_descendants.each do |page|
page.send(:_parse_and_serialize_template, { :cached_parent => self, :cached_pages => cached })
page.send(:_update_direct_template_descendants, template_descendants, cached)
# finally save them all
::Page.without_callback(:save, :after, :update_template_descendants) do
template_descendants.each do |page|
page.save(:validate => false)
end
end
end

View File

@ -46,7 +46,7 @@ module Extensions
end
def domains_without_subdomain
(self.domains || []) - [self.full_subdomain]
(self.domains || []) - [self.full_subdomain_was] - [self.full_subdomain]
end
def domains_with_subdomain
@ -57,6 +57,10 @@ module Extensions
"#{self.subdomain}.#{Locomotive.config.domain}"
end
def full_subdomain_was
"#{self.subdomain_was}.#{Locomotive.config.domain}"
end
protected
def domains_must_be_valid_and_unique

View File

@ -37,9 +37,11 @@ class Snippet
pages.each do |page|
self._change_snippet_inside_template(page.template.root)
page.instance_variable_set(:@template_changed, true)
page.send(:_serialize_template)
page.send(:_serialize_template) && page.save
Page.without_callback(:save, :after, :update_template_descendants) do
page.save(:validate => false)
end
end
end

View File

@ -7,7 +7,7 @@ x bugs:
- bushido version
- upgrade warning if new version of locomotive (maybe based on the commit id)
- duostack version
- 2 different sites on the same main domain (one in www, the other one in something else) (Raphael Costa)
x 2 different sites on the same main domain (one in www, the other one in something else) (Raphael Costa)
- seo section for the page form: seo title, seo keywords, seo description
- icon for redirection page in the pages section (back-office)
- write my first tutorial about locomotive

View File

@ -27,6 +27,8 @@ module Locomotive
self.enhance_site_model_with_bushido
self.setup_smtp_settings
self.bushido_domains = ::Bushido::App.domains
self.bushido_subdomain = ::Bushido::App.subdomain
end
@ -36,12 +38,25 @@ module Locomotive
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
end
def setup_smtp_settings
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:authentication => ENV['SMTP_AUTHENTICATION'],
:address => ENV['SMTP_SERVER'],
:port => ENV['SMTP_PORT'],
:domain => ENV['SMTP_DOMAIN'],
:user_name => ENV['SMTP_USER'],
:password => ENV['SMTP_PASSWORD'],
:enable_starttls_auto => ENV['SMTP_TLS'].to_s == 'true'
}
end
# manage domains
def add_bushido_domain(name)
Locomotive.logger "[add bushido domain] #{name}"
::Bushido::App.add_domain(name)
if ::Bushido::Command.last_command_successful?
self.bushido_domains << name
end
@ -50,7 +65,7 @@ module Locomotive
def remove_bushido_domain(name)
Locomotive.logger "[remove bushido domain] #{name}"
::Bushido::App.remove_domain(name)
if ::Bushido::Command.last_command_successful?
self.bushido_domains.delete(name)
end
@ -64,6 +79,7 @@ module Locomotive
self.bushido_subdomain = name
end
end
end
end
end

View File

@ -31,12 +31,9 @@ module Locomotive
def add_subdomain_to_domains_with_bushido
unless self.domains_change.nil?
old_full_subdomain = "#{self.subdomain_was}.#{Locomotive.config.domain}"
full_subdomain = "#{self.subdomain}.#{Locomotive.config.domain}"
@bushido_domains_change = {
:added => self.domains_change.last - self.domains_change.first - [old_full_subdomain] - [full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [old_full_subdomain] - [full_subdomain]
:added => self.domains_change.last - self.domains_change.first - [self.full_subdomain_was] - [self.full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [self.full_subdomain_was] - [self.full_subdomain]
}
end

View File

@ -18,12 +18,9 @@ module Locomotive
def add_subdomain_to_domains_with_heroku
unless self.domains_change.nil?
old_full_subdomain = "#{self.subdomain_was}.#{Locomotive.config.domain}"
full_subdomain = "#{self.subdomain}.#{Locomotive.config.domain}"
@heroku_domains_change = {
:added => self.domains_change.last - self.domains_change.first - [old_full_subdomain] - [full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [old_full_subdomain] - [full_subdomain]
:added => self.domains_change.last - self.domains_change.first - [self.full_subdomain_was] - [self.full_subdomain],
:removed => self.domains_change.first - self.domains_change.last - [self.full_subdomain_was] - [self.full_subdomain]
}
end

View File

@ -5,6 +5,8 @@ module Locomotive
def process
context[:done] = {} # initialize the hash storing pages already processed
self.add_page('404')
self.add_page('index')
Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
@ -16,8 +18,6 @@ module Locomotive
self.add_page(fullpath)
end
self.add_page('404')
# make sure all the pages were processed (redirection pages without template for instance)
self.pages.each { |fullpath, attributes| self.add_page_without_template(fullpath.to_s) }
end

View File

@ -89,4 +89,20 @@ module Mongoid #:nodoc:
end
end
# without callback feature
module Callbacks
module ClassMethods
def without_callback(*args, &block)
skip_callback(*args)
yield
set_callback(*args)
end
end
end
end