From 711110a6e096cc969f3d9935e0b8639aaa207ba4 Mon Sep 17 00:00:00 2001
From: did <didier@nocoffee.fr>
Date: Thu, 7 Jul 2011 16:59:50 +0200
Subject: [PATCH] snippets were missing in the export

---
 doc/TODO                           |   1 -
 lib/locomotive/export.rb           |  14 ++++++++------
 lib/tasks/locomotive.rake          |   9 +++++++++
 spec/fixtures/themes/default.zip   | Bin 401210 -> 403470 bytes
 spec/lib/locomotive/export_spec.rb |  14 +++++++++++++-
 spec/lib/locomotive/import_spec.rb |   4 ++++
 6 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/doc/TODO b/doc/TODO
index ed3b7f5d..50588466 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -78,7 +78,6 @@ x export: problems with templatized pages (source => multi levels pages)
 - [bushido] guiders / welcome page / devise cas authentication (SSO)
 
 
-
 BACKLOG:
 
 - custom_fields:
diff --git a/lib/locomotive/export.rb b/lib/locomotive/export.rb
index 5e7fa007..e82332a8 100644
--- a/lib/locomotive/export.rb
+++ b/lib/locomotive/export.rb
@@ -97,7 +97,7 @@ module Locomotive
 
     def copy_snippets
       @site.snippets.each do |snippet|
-        File.open(File.join(self.snippets_folder, snippet.slug), 'w') do |f|
+        File.open(File.join(self.snippets_folder, "#{snippet.slug}.liquid"), 'w') do |f|
           f.write(snippet.template)
         end
       end
@@ -262,13 +262,15 @@ module Locomotive
           case field.kind
           when 'file'
             uploader = content.send(field._name)
-            filepath = File.join('/samples', content_type.slug, content.send("#{field._name}_filename"))
-
-            self.copy_file_from_an_uploader(uploader, File.join(self.public_folder, filepath))
-
+            unless uploader.blank?
+              filepath = File.join('/samples', content_type.slug, content.send("#{field._name}_filename"))
+              self.copy_file_from_an_uploader(uploader, File.join(self.public_folder, filepath))
+            else
+              filepath = nil
+            end
             hash[field._alias] = filepath
           when 'text'
-            value = self.replace_asset_urls_in(content.send(field._name.to_sym))
+            value = self.replace_asset_urls_in(content.send(field._name.to_sym) || '')
             hash[field._alias] = value
           else
             hash[field._alias] = content.send(field._name.to_sym)
diff --git a/lib/tasks/locomotive.rake b/lib/tasks/locomotive.rake
index 2d0a83c6..bf4224ab 100644
--- a/lib/tasks/locomotive.rake
+++ b/lib/tasks/locomotive.rake
@@ -11,6 +11,15 @@ namespace :locomotive do
     puts '...done'
   end
 
+  desc 'Rebuild the serialized template of all the site pages'
+  task :rebuild_serialized_page_templates do
+    Page.all.each do |page|
+      next unless page.template.nil?
+      page.send :_parse_and_serialize_template
+      page.save
+    end
+  end
+
   desc 'Import a remote template described by its URL -- 2 options: SITE=name or id, RESET=by default false'
   task :import => :environment do
     url, site_name_or_id, reset = ENV['URL'], ENV['SITE'], Boolean.set(ENV['RESET']) || false
diff --git a/spec/fixtures/themes/default.zip b/spec/fixtures/themes/default.zip
index 22fa15647e1d35383e454cd137a7be4d841535ae..b157828b6836b61ff907452b662f30af82f120af 100644
GIT binary patch
delta 4546
zcma)930PBC7Je_wOW49oAd)>qRx5<T9hb_YsHnIL`i*4(0TDD|Q)?}Oied#teb(nT
zD8eUps#a7KMRDJ?fMeY%Gt+TFXGEopRT;2z?@eCv613kW--F9N=bm%!|DWY?yg|0M
zN#-_rJeTK;!H;`(>v}h}yu4Bx3!m5cYa9waF(LSR0%4TDX-Ks+w%Q_W+k9sA**|!W
zewk6?nMyql>Tr1<L3V%j4quQmD)5N+i~5eE3vP_=H$5@+@y<7=A9{Ya;mEcVC$Iw-
z(uWCD1(N0=5A}Y@k<qPDck7~CrZ4!(wQO@s!u**0HEu(5e@Y&DD!PQ*P;==;+OBg>
z(yh8F)lRx16B*g%yy?a-50CB86}>Gk{qOQ>Zp#>DhkTB2j;ifh_?za7S@Jneer@w6
z367UN*`1R4X{lk*qQEEfCKZqDK1dp(G><QKo;rK(eS)z4Y<x}EY`rl<=wDiU+r1_>
zV8jsK-1dX7`pa9PrJ+J$dyszec!AL1RQB~F01!{+j$t;uI&)enBd(D{OyI)+W=0cA
zt8xDxQY)O)6FgL4!IRQ(#&7||)I5$35x`(<M*uZ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uQpz9lRibETCJlUs
zqqj+2%o4@K!u*o5{FP35g%nGT$f?0saO(0`2n4t?Wyni?#wlT}352@(L>@6r6<LeJ
zV<NC^HX*h<WOWkkFo6J1u_G8NQDKr8m>39rJy3Qaf<)s8KX22jyqoC6*q#84S)pH$
z5JrT1U`4_`Qsc_i=zZWT2uGk+Gf)^4HJ-iA`LHNAf3<6S;qPV;!&Yi2-e$7K3j<R6
z`mEW6F%f>fH~od9AJS%&^;EFWlvhVp7{g07gEsez0Wm~*X?bQ_h!GYC10(+;SmT^e
zlpfFL_`qSusL@k*aand@evYed(p#nlwLRGci!Er#-NGNSAeqX@st(#XpyHQvc$D13
z;L9NgW*rVA4rVMrA^eC#gllfX{TvAN5MIRo-`s?EI1uL9sh|*GWWyPnFX_|4F$pdA
zq|m~O5MW>{tO9sE1js#c-8gPwfdI8E@s88L304FS)eB&z6{tLMJ27;-Lx5VXz~5ap
z+5P)nwV{B+MdMCXIxmrj9n-pL*ew?8y(X4}__VQ`1%z`U!t4%)qK>b2*M<S|2O%sb
zhoJ%##Vlsx;Lb4b<JX9>t0zPli-eEDfZ9`dNI1g$DKW+pJR+epi-9@01mIv)q1fxh
zLEIGk7yx))4gz1UE+qn0XP3Z&2tfX0h4Q{etLzgA35c)=qi8?-bY5Dr7~r{`guXfz
JMadQT@qa^?`40d9

diff --git a/spec/lib/locomotive/export_spec.rb b/spec/lib/locomotive/export_spec.rb
index 2b05b6c6..ed0432ef 100644
--- a/spec/lib/locomotive/export_spec.rb
+++ b/spec/lib/locomotive/export_spec.rb
@@ -24,6 +24,17 @@ describe Locomotive::Export do
       Dir[File.join(self.zip_folder, 'app', 'views', 'pages', '**/*.liquid')].size.should == 10
     end
 
+    it 'includes snippets' do
+      self.unzip
+      Dir[File.join(self.zip_folder, 'app', 'views', 'snippets', '*.liquid')].size.should == 1
+    end
+
+    it 'has yaml files describing the content types as well as their data' do
+      self.unzip
+      Dir[File.join(self.zip_folder, 'app', 'content_types', '*.yml')].size.should == 4
+      Dir[File.join(self.zip_folder, 'data', '*.yml')].size.should == 4
+    end
+
     def import_it
       job = Locomotive::Import::Job.new(FixturedTheme.duplicate_and_open('default.zip'), @site, { :samples => true, :reset => true })
       job.perform
@@ -35,7 +46,7 @@ describe Locomotive::Export do
     end
 
     def zip_folder
-      File.join(File.dirname(@zip_file), 'acme-website')
+      File.join(File.dirname(@zip_file), 'locomotive-test-website-2')
     end
 
     def unzip
@@ -51,6 +62,7 @@ describe Locomotive::Export do
     end
 
     after(:all) do
+      FileUtils.rm_rf(self.zip_folder) if File.exists?(self.zip_folder)
       Site.destroy_all
     end
 
diff --git a/spec/lib/locomotive/import_spec.rb b/spec/lib/locomotive/import_spec.rb
index 5dbcc5b3..10b29bfa 100644
--- a/spec/lib/locomotive/import_spec.rb
+++ b/spec/lib/locomotive/import_spec.rb
@@ -67,6 +67,10 @@ describe Locomotive::Import::Job do
       page.redirect_url.should == 'http://blog.locomotivecms.com'
     end
 
+    it 'inserts snippets' do
+      @site.snippets.count.should == 1
+    end
+
     after(:all) do
       Site.destroy_all
     end