This commit is contained in:
parent
2c2c565aad
commit
8da0db2454
@ -52,7 +52,7 @@ GEM
|
|||||||
bson (1.3.1)
|
bson (1.3.1)
|
||||||
bson_ext (1.3.1)
|
bson_ext (1.3.1)
|
||||||
builder (2.1.2)
|
builder (2.1.2)
|
||||||
bushido (0.0.31)
|
bushido (0.0.34)
|
||||||
highline (>= 1.6.1)
|
highline (>= 1.6.1)
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
orm_adapter (~> 0.0.3)
|
orm_adapter (~> 0.0.3)
|
||||||
@ -289,7 +289,7 @@ DEPENDENCIES
|
|||||||
actionmailer-with-request
|
actionmailer-with-request
|
||||||
autotest
|
autotest
|
||||||
bson_ext (~> 1.3.0)
|
bson_ext (~> 1.3.0)
|
||||||
bushido (= 0.0.31)
|
bushido (= 0.0.34)
|
||||||
bushido_stub (= 0.0.3)
|
bushido_stub (= 0.0.3)
|
||||||
cancan
|
cancan
|
||||||
capybara
|
capybara
|
||||||
|
@ -67,10 +67,13 @@ module Extensions
|
|||||||
|
|
||||||
if existing_el.nil? # new one from parents
|
if existing_el.nil? # new one from parents
|
||||||
new_attributes = el.attributes.merge(:from_parent => true)
|
new_attributes = el.attributes.merge(:from_parent => true)
|
||||||
|
|
||||||
if new_attributes['default_attribute'].present?
|
if new_attributes['default_attribute'].present?
|
||||||
new_attributes['default_content'] = self.send(new_attributes['default_attribute']) || el.content
|
new_attributes['default_content'] = self.send(new_attributes['default_attribute']) || el.content
|
||||||
else
|
else
|
||||||
new_attributes['default_content'] = el.content
|
if el.respond_to?(:content) # only for text
|
||||||
|
new_attributes['default_content'] = el.content
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.editable_elements.build(new_attributes, el.class)
|
self.editable_elements.build(new_attributes, el.class)
|
||||||
|
@ -82,30 +82,9 @@ module Locomotive
|
|||||||
page.attributes = attributes
|
page.attributes = attributes
|
||||||
|
|
||||||
page.save!
|
page.save!
|
||||||
|
|
||||||
unless editable_elements_attributes.nil?
|
unless editable_elements_attributes.nil?
|
||||||
page.editable_elements.each do |editable_element|
|
self.assign_editable_elements(page, editable_elements_attributes)
|
||||||
editable_elements_attributes.each do |attributes|
|
|
||||||
if editable_element.block == attributes['block'] && editable_element.slug == attributes['slug']
|
|
||||||
if editable_element.respond_to?(:source)
|
|
||||||
# editable_file, update file
|
|
||||||
unless attributes['content'].blank?
|
|
||||||
full_path = File.join(File.join(theme_path,'public',attributes['content']))
|
|
||||||
if File.exists?(full_path)
|
|
||||||
file = File.open(full_path)
|
|
||||||
editable_element.source = file
|
|
||||||
editable_element.save!
|
|
||||||
file.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# update content value
|
|
||||||
editable_element.update_attribute(:content, attributes['content'])
|
|
||||||
end
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}"
|
self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}"
|
||||||
@ -117,6 +96,28 @@ module Locomotive
|
|||||||
page
|
page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assign_editable_elements(page, elements)
|
||||||
|
page.reload # editable elements are not synchronized otherwise
|
||||||
|
|
||||||
|
elements.each do |attributes|
|
||||||
|
element = page.find_editable_element(attributes['block'], attributes['slug'])
|
||||||
|
|
||||||
|
next if element.nil?
|
||||||
|
|
||||||
|
if element.respond_to?(:source)
|
||||||
|
asset_path = File.join(theme_path, 'public', attributes['content'])
|
||||||
|
|
||||||
|
if File.exists?(asset_path)
|
||||||
|
element.source = File.open(asset_path)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
element.content = attributes['content']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
page.save!
|
||||||
|
end
|
||||||
|
|
||||||
def build_parent_template(template)
|
def build_parent_template(template)
|
||||||
# just check if the template contains the extends keyword
|
# just check if the template contains the extends keyword
|
||||||
fullpath = template.scan(/\{% extends \'?([\w|\/]+)\'? %\}/).flatten.first
|
fullpath = template.scan(/\{% extends \'?([\w|\/]+)\'? %\}/).flatten.first
|
||||||
@ -148,7 +149,7 @@ module Locomotive
|
|||||||
return if template.blank?
|
return if template.blank?
|
||||||
|
|
||||||
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
|
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
|
||||||
name = $1
|
name = File.basename($1)
|
||||||
|
|
||||||
if asset = site.assets.where(:source_filename => name).first
|
if asset = site.assets.where(:source_filename => name).first
|
||||||
asset.source.url
|
asset.source.url
|
||||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
@ -55,18 +55,28 @@ describe Locomotive::Import::Job do
|
|||||||
@site.pages.not_found.first.should_not be_nil
|
@site.pages.not_found.first.should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'sets the editable text for a page from the site config file' do
|
||||||
|
page = @site.pages.where(:title => 'Contact').first
|
||||||
|
page.find_editable_element('content', 'address').content.should == '<p>Our office address: 215 Vine Street, Scranton, PA 18503</p>'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sets the editable file for a page from the site config file' do
|
||||||
|
page = @site.pages.where(:title => 'Contact').first
|
||||||
|
page.find_editable_element('content', 'office').source_filename.should == 'office.jpg'
|
||||||
|
end
|
||||||
|
|
||||||
it 'inserts templatized page' do
|
it 'inserts templatized page' do
|
||||||
page = @site.pages.where(:templatized => true).first
|
page = @site.pages.where(:templatized => true).first
|
||||||
page.should_not be_nil
|
page.should_not be_nil
|
||||||
page.fullpath.should == 'portfolio/content_type_template'
|
page.fullpath.should == 'portfolio/content_type_template'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'inserts redirection page' do
|
it 'inserts redirection page' do
|
||||||
page = @site.pages.where(:redirect => true).first
|
page = @site.pages.where(:redirect => true).first
|
||||||
page.should_not be_nil
|
page.should_not be_nil
|
||||||
page.redirect_url.should == 'http://blog.locomotivecms.com'
|
page.redirect_url.should == 'http://blog.locomotivecms.com'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'inserts snippets' do
|
it 'inserts snippets' do
|
||||||
@site.snippets.count.should == 1
|
@site.snippets.count.should == 1
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user