This commit is contained in:
parent
2c2c565aad
commit
8da0db2454
@ -52,7 +52,7 @@ GEM
|
||||
bson (1.3.1)
|
||||
bson_ext (1.3.1)
|
||||
builder (2.1.2)
|
||||
bushido (0.0.31)
|
||||
bushido (0.0.34)
|
||||
highline (>= 1.6.1)
|
||||
json (>= 1.4.6)
|
||||
orm_adapter (~> 0.0.3)
|
||||
@ -289,7 +289,7 @@ DEPENDENCIES
|
||||
actionmailer-with-request
|
||||
autotest
|
||||
bson_ext (~> 1.3.0)
|
||||
bushido (= 0.0.31)
|
||||
bushido (= 0.0.34)
|
||||
bushido_stub (= 0.0.3)
|
||||
cancan
|
||||
capybara
|
||||
|
@ -67,11 +67,14 @@ module Extensions
|
||||
|
||||
if existing_el.nil? # new one from parents
|
||||
new_attributes = el.attributes.merge(:from_parent => true)
|
||||
|
||||
if new_attributes['default_attribute'].present?
|
||||
new_attributes['default_content'] = self.send(new_attributes['default_attribute']) || el.content
|
||||
else
|
||||
if el.respond_to?(:content) # only for text
|
||||
new_attributes['default_content'] = el.content
|
||||
end
|
||||
end
|
||||
|
||||
self.editable_elements.build(new_attributes, el.class)
|
||||
elsif existing_el.default_attribute.nil?
|
||||
|
@ -84,28 +84,7 @@ module Locomotive
|
||||
page.save!
|
||||
|
||||
unless editable_elements_attributes.nil?
|
||||
page.editable_elements.each do |editable_element|
|
||||
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
|
||||
self.assign_editable_elements(page, editable_elements_attributes)
|
||||
end
|
||||
|
||||
self.log "adding #{page.fullpath} (#{template.blank? ? 'without' : 'with'} template) / #{page.position}"
|
||||
@ -117,6 +96,28 @@ module Locomotive
|
||||
page
|
||||
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)
|
||||
# just check if the template contains the extends keyword
|
||||
fullpath = template.scan(/\{% extends \'?([\w|\/]+)\'? %\}/).flatten.first
|
||||
@ -148,7 +149,7 @@ module Locomotive
|
||||
return if template.blank?
|
||||
|
||||
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
|
||||
asset.source.url
|
||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
@ -55,6 +55,16 @@ describe Locomotive::Import::Job do
|
||||
@site.pages.not_found.first.should_not be_nil
|
||||
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
|
||||
page = @site.pages.where(:templatized => true).first
|
||||
page.should_not be_nil
|
||||
|
Loading…
Reference in New Issue
Block a user