From 890d5d7e18145a0ed6dd6e3e459cef1f34b78dc9 Mon Sep 17 00:00:00 2001 From: dinedine Date: Mon, 10 Jan 2011 14:57:44 +0100 Subject: [PATCH] the import module takes care of redirection pages (+ tests) --- lib/locomotive/import/pages.rb | 27 ++++++++++++++++++++++++--- public/javascripts/admin/pages.js | 3 ++- spec/fixtures/themes/default.zip | Bin 408995 -> 409020 bytes spec/lib/locomotive/import_spec.rb | 8 +++++++- 4 files changed, 33 insertions(+), 5 deletions(-) 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 2fb81f555c2564e5a533a17bd6c6c3505aa50298..916d4cac79ad0ed76d7cfd176824b81b7a6d3e09 100644 GIT binary patch delta 5974 zcmaJ_2V7HE7tb@vB?L$SL1-WlkUc^`W*8F00SFF65se7q9(8X->Z}_hT&x>V3kuqz zqT&D%C!gXdjykJVi!%JIR#EGB@4I>Ah58kKPm_1g`Jey!-*fIgTKLiW#7ApU|2QsB z$iY9+Gdv=4L{5?q0?+tX^t`3sQh3#ZBS60!XQS1=imX_%XM9)m;MJzVasBQoOi#5O zuwE8R<+@ZJ44=7dLrKKV*r^`j4#^=GU!8k&JFm(A>BBi&&ri7y1{IAc`R>q#*I^M? zpTDk4Zk`&z-LSvPl9yU0_j&N$;B%8VJ@Sx!-`~BnQ;!&XzVgVa^T!9elo#!&j57YS z`uF6WK?9a$P5)#Nm2!J$#pU`v%O{@Cb-HmfXRxKDPFB3@wN>4PsB-U=EI*FC+rn}1 zP^!y!zuJ~t1}CPMS8ny$VcxPUeZ{gab!qi4Lz@>)9dbY7M-xSTuls3@%G^OQE3TKS zOJmA4clNfP;K!*aUH0!eF^gYW6uxTRZ%0Jsdu^SgCeLYz&N2()os_RlR^^B89Ww1z zQbG9RvvZ%VtRTFrorwL!tjwmmF*zPNs+ z=aq_MJMGOXru^A3`B_%mm(DBuz6prU6I^|{-0)?t+f~1N2L~Q~GW$T{luvgeQWgg_ z?Yo^>@&0zWGN=>gNH_Pf(p)LOmv2tRJal()kYwu;ueR+TzFidKBF zk+tp5pZ?+g%Iv($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#Mqfj9mAd|Lx$UHmeZ3r5J2I6* U{CR+(9*cgj+H*Md&dk661&ctg*Z=?k 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