automate get files with anyname
This commit is contained in:
		
							parent
							
								
									16001fb2c9
								
							
						
					
					
						commit
						8895b9fe20
					
				|  | @ -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 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue