Trying to create Design from upload package
This commit is contained in:
parent
e0811c14db
commit
f6ae58cef4
|
@ -0,0 +1 @@
|
||||||
|
javascripts
|
|
@ -0,0 +1 @@
|
||||||
|
stylesheets
|
Binary file not shown.
|
@ -12,26 +12,28 @@ class Admin::DesignsController < ApplicationController
|
||||||
temp_file = Tempfile.new("temp_file")
|
temp_file = Tempfile.new("temp_file")
|
||||||
temp_file.binmode
|
temp_file.binmode
|
||||||
original_file = params[:design][:package_file]
|
original_file = params[:design][:package_file]
|
||||||
if original_file.content_type == 'application/zip'
|
#if original_file.content_type == 'application/zip'
|
||||||
temp_file.write(original_file.read)
|
temp_file.write(original_file.read)
|
||||||
filename = original_file.original_filename
|
temp_file.rewind
|
||||||
|
filename = File.basename(original_file.original_filename,".zip")
|
||||||
unzip_design(temp_file, filename)
|
unzip_design(temp_file, filename)
|
||||||
else
|
#else
|
||||||
flash[:error] = "Upload file should be in zip format"
|
# flash[:error] = "Upload file should be in zip format"
|
||||||
end
|
#end
|
||||||
temp_file.close
|
temp_file.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def unzip_design(file, zip_name)
|
def unzip_design(file, zip_name)
|
||||||
Zip::ZipFile.open(file) { |zip_file|
|
Zip::ZipFile.open(file) { |zip_file|
|
||||||
design = Design.new.from_json(zip_file.read("#{zip_name}/#{zip_name}.json"))
|
design = Design.new.from_json(zip_file.read("#{zip_name}/info.json"))
|
||||||
|
|
||||||
Dir.mktmpdir('f_path') { |dir|
|
Dir.mktmpdir('f_path') { |dir|
|
||||||
title = design.layout_filename
|
title = 'layout.html' #design.layout_filename Should be layout file name,set to be fetch
|
||||||
temp_file = File.new(dir + '/' + title, 'w+')
|
temp_file = File.new(dir + '/' + title, 'w+') #dir/zip_name
|
||||||
temp_file.write zip_file.read(zip_name + '/' + title)
|
temp_file.write zip_file.read(zip_name + '/' + title)
|
||||||
|
debugger
|
||||||
|
design.build_layout
|
||||||
design.layout = temp_file
|
design.layout = temp_file
|
||||||
['stylesheets', 'javascripts', 'images'].each do |type|
|
['themes', 'javascripts', 'images'].each do |type|
|
||||||
eval("design.#{type}").each do |object|
|
eval("design.#{type}").each do |object|
|
||||||
title = object.file_filename
|
title = object.file_filename
|
||||||
temp_file = File.new(dir + '/' + title, 'w+')
|
temp_file = File.new(dir + '/' + title, 'w+')
|
||||||
|
@ -45,19 +47,6 @@ class Admin::DesignsController < ApplicationController
|
||||||
design.save
|
design.save
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def proc_package
|
|
||||||
#uri = URI.parse("http://localhost:3001/design/fraisier")
|
|
||||||
#http = Net::HTTP.new(uri.host, uri.port)
|
|
||||||
#request = Net::HTTP::Get.new(uri.request_uri)
|
|
||||||
#response = http.request(request)
|
|
||||||
temp_file = Tempfile.new("temp_file")
|
|
||||||
temp_file.binmode
|
|
||||||
temp_file.write response.body
|
|
||||||
zip_name = response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue ''
|
|
||||||
unzip_design(temp_file, zip_name)
|
|
||||||
temp_file.close
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@designs = Design.all.entries
|
@designs = Design.all.entries
|
||||||
|
@ -78,17 +67,6 @@ class Admin::DesignsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply
|
|
||||||
@design = Design.find(params[:id])
|
|
||||||
Layout.create(:name => @design.title,:description=>@design.intro,:content=>@design.layout.file.read)
|
|
||||||
#TODO do somehting to validate
|
|
||||||
# doc = Nokogiri::HTML(@design.layout.file.read)
|
|
||||||
flash[:notice] = "Successfully applied design and created a layout."
|
|
||||||
|
|
||||||
redirect_to admin_designs_url
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit_file
|
def edit_file
|
||||||
@design = Design.find(params[:id])
|
@design = Design.find(params[:id])
|
||||||
filename = params[:filename]
|
filename = params[:filename]
|
||||||
|
|
|
@ -2,6 +2,7 @@ class Design
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
|
||||||
field :title
|
field :title
|
||||||
field :author
|
field :author
|
||||||
field :intro
|
field :intro
|
||||||
|
|
Reference in New Issue