diff --git a/Gemfile.lock b/Gemfile.lock index 45f8a22a..fa1be25e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/models/extensions/page/editable_elements.rb b/app/models/extensions/page/editable_elements.rb index 2a9022f4..3c588d50 100644 --- a/app/models/extensions/page/editable_elements.rb +++ b/app/models/extensions/page/editable_elements.rb @@ -67,10 +67,13 @@ 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 - new_attributes['default_content'] = el.content + if el.respond_to?(:content) # only for text + new_attributes['default_content'] = el.content + end end self.editable_elements.build(new_attributes, el.class) diff --git a/lib/locomotive/import/pages.rb b/lib/locomotive/import/pages.rb index 1d3de006..f24d098d 100644 --- a/lib/locomotive/import/pages.rb +++ b/lib/locomotive/import/pages.rb @@ -82,30 +82,9 @@ module Locomotive page.attributes = attributes 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 diff --git a/spec/fixtures/themes/default.zip b/spec/fixtures/themes/default.zip index b157828b..973d2494 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 10b29bfa..007900c2 100644 --- a/spec/lib/locomotive/import_spec.rb +++ b/spec/lib/locomotive/import_spec.rb @@ -55,18 +55,28 @@ 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 == '
Our office address: 215 Vine Street, Scranton, PA 18503
' + 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 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 - + it 'inserts snippets' do @site.snippets.count.should == 1 end