the import module takes care of redirection pages (+ tests)
This commit is contained in:
parent
2adb950ac3
commit
890d5d7e18
@ -15,10 +15,21 @@ module Locomotive
|
|||||||
|
|
||||||
self.add_page(fullpath)
|
self.add_page(fullpath)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
protected
|
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)
|
def add_page(fullpath)
|
||||||
page = context[:done][fullpath]
|
page = context[:done][fullpath]
|
||||||
|
|
||||||
@ -30,6 +41,10 @@ module Locomotive
|
|||||||
|
|
||||||
self.build_parent_template(template)
|
self.build_parent_template(template)
|
||||||
|
|
||||||
|
self._save_page!(fullpath, template)
|
||||||
|
end
|
||||||
|
|
||||||
|
def _save_page!(fullpath, template)
|
||||||
parent = self.find_parent(fullpath)
|
parent = self.find_parent(fullpath)
|
||||||
|
|
||||||
attributes = {
|
attributes = {
|
||||||
@ -42,20 +57,22 @@ module Locomotive
|
|||||||
|
|
||||||
# templatized ?
|
# templatized ?
|
||||||
if content_type_slug = attributes.delete(:content_type)
|
if content_type_slug = attributes.delete(:content_type)
|
||||||
fullpath.gsub!(/\/template$/, '/content_type_template')
|
|
||||||
attributes.merge!({
|
attributes.merge!({
|
||||||
:templatized => true,
|
:templatized => true,
|
||||||
:content_type => site.content_types.where(:slug => content_type_slug).first
|
:content_type => site.content_types.where(:slug => content_type_slug).first
|
||||||
})
|
})
|
||||||
end
|
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.attributes = attributes
|
||||||
|
|
||||||
page.save!
|
page.save!
|
||||||
|
|
||||||
self.log "adding #{page.fullpath} / #{page.position}"
|
self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}"
|
||||||
|
|
||||||
site.reload
|
site.reload
|
||||||
|
|
||||||
@ -162,6 +179,10 @@ module Locomotive
|
|||||||
pages
|
pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize_fullpath(fullpath)
|
||||||
|
fullpath.gsub(/\/template$/, '/content_type_template')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -26,7 +26,8 @@ $(document).ready(function() {
|
|||||||
params += '&_method=put';
|
params += '&_method=put';
|
||||||
|
|
||||||
$.post($(this).attr('data_url'), params, function(data) {
|
$.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');
|
}, 'json');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
@ -53,7 +53,7 @@ describe Locomotive::Import::Job do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'inserts all the pages' do
|
it 'inserts all the pages' do
|
||||||
@site.pages.count.should == 8
|
@site.pages.count.should == 9
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'inserts the index and 404 pages' do
|
it 'inserts the index and 404 pages' do
|
||||||
@ -67,6 +67,12 @@ describe Locomotive::Import::Job do
|
|||||||
page.fullpath.should == 'portfolio/content_type_template'
|
page.fullpath.should == 'portfolio/content_type_template'
|
||||||
end
|
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
|
after(:all) do
|
||||||
Site.destroy_all
|
Site.destroy_all
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user