From a5ea70229cccfefbe2bd590635b0ac8ecb1b182f Mon Sep 17 00:00:00 2001 From: dinedine Date: Tue, 28 Sep 2010 10:09:49 +0200 Subject: [PATCH] allows to disable import sub tasks + new images tag logic (in progress) + handle errors when importing --- Gemfile.lock | 8 ++--- app/views/admin/shared/_header.html.haml | 2 +- doc/TODO | 8 ++--- lib/locomotive/import/job.rb | 38 ++++++++++++++------- lib/locomotive/liquid/drops/javascripts.rb | 5 +-- lib/locomotive/liquid/drops/stylesheets.rb | 5 +-- lib/locomotive/liquid/drops/theme_images.rb | 6 ++-- lib/locomotive/render.rb | 1 + 8 files changed, 46 insertions(+), 27 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2efbd45f..d3bdcc37 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,12 @@ GIT remote: git://github.com/locomotivecms/custom_fields.git - revision: 89c4d7d21efa4c4715c0e34edcc9ce22c405dcd4 + revision: 89c4d7d specs: custom_fields (0.0.0.2) GIT remote: git://github.com/locomotivecms/liquid.git - revision: b03cdc289ac36c3395459e295c6bf90baa06d256 + revision: b03cdc2 ref: b03cdc289ac36c339545 specs: liquid (2.1.3) @@ -126,7 +126,7 @@ GEM rack (1.2.1) rack-mount (0.6.13) rack (>= 1.0.0) - rack-test (0.5.5) + rack-test (0.5.6) rack (>= 1.0) rails (3.0.0) actionmailer (= 3.0.0) @@ -149,7 +149,7 @@ GEM rubyforge (2.0.4) json_pure (>= 1.1.7) rubyzip (0.9.4) - thor (0.14.1) + thor (0.14.2) treetop (1.4.8) polyglot (>= 0.3.1) tzinfo (0.3.23) diff --git a/app/views/admin/shared/_header.html.haml b/app/views/admin/shared/_header.html.haml index fb63f3cf..f6a9400a 100644 --- a/app/views/admin/shared/_header.html.haml +++ b/app/views/admin/shared/_header.html.haml @@ -1,7 +1,7 @@ %h1 - if current_admin.sites.size > 1 = form_tag new_admin_cross_domain_session_url, :method => 'get' do - = select_tag 'target_id', options_for_select(current_admin.sites.collect { |site| [site.name, site.id] }, current_site.id), :id => 'site-selector' + = select_tag 'target_id', options_for_select(current_admin.sites.collect { |site| [truncate(site.name, :length => 23), site.id] }, current_site.id), :id => 'site-selector' = submit_tag 'Switch', :style => 'display: none' - else = link_to current_site.name, admin_root_url, :class => 'single' diff --git a/doc/TODO b/doc/TODO index 0c3a1af0..b77dab1d 100644 --- a/doc/TODO +++ b/doc/TODO @@ -26,10 +26,10 @@ x create a repo for a tool "a la" vision - snippet dependencies => do not work correctly - images tag to write - import tool: - - disable sub tasks by passing options - - select field (see custom fields and nocoffee theme) ? - - exceptions - - page to import theme + x select field (see custom fields and nocoffee theme) ? + - disable sub tasks by passing options + - exceptions + - page to import theme - refactor slugify method (use parameterize + create a module) - [content types] the "display column" selector should not include file types diff --git a/lib/locomotive/import/job.rb b/lib/locomotive/import/job.rb index 0174e9b6..92f64112 100644 --- a/lib/locomotive/import/job.rb +++ b/lib/locomotive/import/job.rb @@ -4,12 +4,12 @@ module Locomotive module Import class Job - def initialize(theme_file, site = nil, options = {}) + def initialize(theme_file, site = nil, enabled = {}) raise "Theme zipfile not found" unless File.exists?(theme_file) @theme_file = theme_file @site = site - @options = Hash.new(true).merge(options) + @enabled = Hash.new(true).merge(enabled) end def perform @@ -20,18 +20,32 @@ module Locomotive context = { :database => @database, :site => @site, - :theme_path => @theme_path + :theme_path => @theme_path, + :error => nil } - - Locomotive::Import::Site.process(context) - Locomotive::Import::ContentTypes.process(context) + begin + %w(site content_types assets snippets pages).each do |part| + if @enabled[part] + "Locomotive::Import::#{part.camelize}".constantize.process(context) + else + puts "skipping #{part}" + end + end + rescue Exception => e + context[:error] = e.message + end + context + # Locomotive::Import::Site.process(context) + # + # Locomotive::Import::ContentTypes.process(context) + # # Locomotive::Import::Assets.process(context) - - Locomotive::Import::Snippets.process(context) - - Locomotive::Import::Pages.process(context) + # + # Locomotive::Import::Snippets.process(context) + # + # Locomotive::Import::Pages.process(context) end protected @@ -39,8 +53,8 @@ module Locomotive def unzip! Zip::ZipFile.open(@theme_file) do |zipfile| destination_path = File.join(Rails.root, 'tmp', 'themes', @site.id.to_s) - - FileUtils.rm_r destination_path, :force => true + + FileUtils.rm_r destination_path, :force => true zipfile.each do |entry| next if entry.name =~ /__MACOSX/ diff --git a/lib/locomotive/liquid/drops/javascripts.rb b/lib/locomotive/liquid/drops/javascripts.rb index a3ecbfb7..f7b785af 100644 --- a/lib/locomotive/liquid/drops/javascripts.rb +++ b/lib/locomotive/liquid/drops/javascripts.rb @@ -8,8 +8,9 @@ module Locomotive end def before_method(meth) - asset = @site.theme_assets.where(:content_type => 'javascript', :slug => meth.to_s).first - !asset.nil? ? asset.source.url : nil + @context.registers[:theme_uploader].store_path(meth.gsub('__', '.')) + # asset = @site.theme_assets.where(:content_type => 'javascript', :slug => meth.to_s).first + # !asset.nil? ? asset.source.url : nil end end diff --git a/lib/locomotive/liquid/drops/stylesheets.rb b/lib/locomotive/liquid/drops/stylesheets.rb index f18de59c..d609fe2d 100644 --- a/lib/locomotive/liquid/drops/stylesheets.rb +++ b/lib/locomotive/liquid/drops/stylesheets.rb @@ -8,8 +8,9 @@ module Locomotive end def before_method(meth) - asset = @site.theme_assets.where(:content_type => 'stylesheet', :slug => meth.to_s).first - !asset.nil? ? asset.source.url : nil + @context.registers[:theme_uploader].store_path(meth.gsub('__', '.')) + # asset = @site.theme_assets.where(:content_type => 'stylesheet', :slug => meth.to_s).first + # !asset.nil? ? asset.source.url : nil end end diff --git a/lib/locomotive/liquid/drops/theme_images.rb b/lib/locomotive/liquid/drops/theme_images.rb index 738a1be3..9c14f6bb 100644 --- a/lib/locomotive/liquid/drops/theme_images.rb +++ b/lib/locomotive/liquid/drops/theme_images.rb @@ -8,8 +8,10 @@ module Locomotive end def before_method(meth) - asset = @site.theme_assets.where(:content_type => 'image', :slug => meth.to_s).first - !asset.nil? ? asset.source.url : nil + @context.registers[:theme_uploader].store_path(meth.gsub('__', '.')) + # asset = @site.theme_assets.where(:content_type => 'image', :slug => meth.to_s).first + # !asset.nil? ? asset.source.url : nil + # "sites/#{@site.id}/theme/#{meth.gsub('__', '.')}" end end diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index f3b87d0d..6d361e23 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -71,6 +71,7 @@ module Locomotive :site => current_site, :page => @page, :inline_editor => self.editing_page?, + :theme_uploader => ThemeAssetUploader.new(current_site.theme_assets.build), :current_admin => current_admin }