From 8895b9fe2010d130808ec4b402d3ea1bfd70d7a6 Mon Sep 17 00:00:00 2001 From: Kaito Date: Mon, 15 Aug 2011 18:47:02 +0800 Subject: [PATCH] automate get files with anyname --- app/controllers/admin/designs_controller.rb | 49 +++++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index b9e9e4f4..8289ae07 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -27,17 +27,48 @@ class Admin::DesignsController < ApplicationController Zip::ZipFile.open(file) { |zip_file| design = Design.new.from_json(zip_file.read("#{zip_name}/info.json")) Dir.mktmpdir('f_path') { |dir| - title = 'layout.html' #design.layout_filename Should be layout file name,set to be fetch - temp_file = File.new(dir + '/' + title, 'w+') #dir/zip_name - temp_file.write zip_file.read(zip_name + '/' + title) - debugger + #layout_entry ="" + #struct_css_entry ="" design.build_layout - design.layout.file = temp_file + themes_entries = [] + javascripts_entries = [] + images_entries = [] + debugger + temp_file4layout = File.new(dir + '/' + zip_name+'-1', 'w+') + temp_file4layout.binmode + #dir/zip_name + temp_file4structure = File.new(dir + '/' + zip_name+'-2', 'w+') + temp_file4structure.binmode + #dir/zip_name + + zip_file.entries.each do |entry| + case (path = entry.to_s) + when /\A(#{zip_name})\/[^\/]*(\.css)\z/ #for structure css + # struct_css_entry = entry + temp_file4structure.write (zip_file.read entry ) + design.structure_css = temp_file4structure + when /\A(#{zip_name})\/[^\/]*(\.html)\z/ #for layout html + # layout_entry = entry + temp_file4layout.write (zip_file.read entry ) + design.layout.file = temp_file4structure + design.layout.to_save=true + when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css + themes_entries << entry + when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js + javascripts_entries << entry + when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img + images_entries << entry + end + end + debugger + ['themes', 'javascripts', 'images'].each do |type| - eval("design.#{type}").each do |object| - title = object.file_filename - temp_file = File.new(dir + '/' + title, 'w+') - temp_file.write zip_file.read(zip_name + '/' + type + '/' + title) +#incompleted + eval("#{type}.entries").each do |entry| + title = File.basename entry + debugger + temp_file = File.new(dir + '/' + title+'-3', 'w+') + temp_file.write zip_file.read entry object.file = temp_file object.to_save = true end