diff --git a/lib/locomotive/import/pages.rb b/lib/locomotive/import/pages.rb index fa68235b..4f55c0ec 100644 --- a/lib/locomotive/import/pages.rb +++ b/lib/locomotive/import/pages.rb @@ -15,10 +15,21 @@ module Locomotive self.add_page(fullpath) end + + # 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 protected + def add_page_without_template(fullpath) + page = context[:done][fullpath] + + return page if page # already added, so skip it + + self._save_page!(fullpath, nil) + end + def add_page(fullpath) page = context[:done][fullpath] @@ -30,6 +41,10 @@ module Locomotive self.build_parent_template(template) + self._save_page!(fullpath, template) + end + + def _save_page!(fullpath, template) parent = self.find_parent(fullpath) attributes = { @@ -42,20 +57,22 @@ module Locomotive # templatized ? if content_type_slug = attributes.delete(:content_type) - fullpath.gsub!(/\/template$/, '/content_type_template') attributes.merge!({ :templatized => true, :content_type => site.content_types.where(:slug => content_type_slug).first }) end - page = site.pages.where(:fullpath => fullpath).first || site.pages.build + # redirection page ? + attributes[:redirect] = true if attributes[:redirect_url].present? + + page = site.pages.where(:fullpath => self.sanitize_fullpath(fullpath)).first || site.pages.build page.attributes = attributes page.save! - self.log "adding #{page.fullpath} / #{page.position}" + self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}" site.reload @@ -162,6 +179,10 @@ module Locomotive pages end + def sanitize_fullpath(fullpath) + fullpath.gsub(/\/template$/, '/content_type_template') + end + end end end \ No newline at end of file diff --git a/public/javascripts/admin/pages.js b/public/javascripts/admin/pages.js index 7df11f1d..0d35011c 100644 --- a/public/javascripts/admin/pages.js +++ b/public/javascripts/admin/pages.js @@ -26,7 +26,8 @@ $(document).ready(function() { params += '&_method=put'; $.post($(this).attr('data_url'), params, function(data) { - $.growl('success', data.notice); + var error = typeof(data.error) != 'undefined'; + $.growl((error ? 'error' : 'success'), (error ? data.error : data.notice)); }, 'json'); } }); diff --git a/spec/fixtures/themes/default.zip b/spec/fixtures/themes/default.zip index 2fb81f55..916d4cac 100644 Binary files a/spec/fixtures/themes/default.zip and b/spec/fixtures/themes/default.zip differ diff --git a/spec/lib/locomotive/import_spec.rb b/spec/lib/locomotive/import_spec.rb index ec0c9483..168a8b48 100644 --- a/spec/lib/locomotive/import_spec.rb +++ b/spec/lib/locomotive/import_spec.rb @@ -53,7 +53,7 @@ describe Locomotive::Import::Job do end it 'inserts all the pages' do - @site.pages.count.should == 8 + @site.pages.count.should == 9 end it 'inserts the index and 404 pages' do @@ -67,6 +67,12 @@ describe Locomotive::Import::Job do page.fullpath.should == 'portfolio/content_type_template' end + it 'inserts redirection page' do + page = @site.pages.where(:redirect => true).first + page.should_not be_nil + page.redirect_url.should == 'http://blog.locomotivecms.com' + end + after(:all) do Site.destroy_all end