218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'app/controllers/designers_controller.rb', line 218
def download(uid, id)
content = open(@url + '/static/uploads/' + uid + '/result.zip')
Zip::File.open_buffer(content) do |zip|
zip.each do |f|
p f.name
f_path = File.join("/tmp/booo", f.name)
if f.name == 'index.html'
f_path = File.join("#{Rails.root}/app/views/pages/", "page-#{id.to_s}.html.erb")
FileUtils.mkdir_p(File.dirname(f_path))
zip.(f, f_path) unless File.exist?(f_path)
text = File.read(f_path)
new_contents = text.gsub('assets/img', 'assets/page-' + id.to_s)
.gsub('link href="assets/css', 'link href="assets/page-' + id.to_s)
.gsub('script src="assets/js', 'script src="assets/page-' + id.to_s)
File.open(f_path, "w") {|file| file.puts new_contents}
elsif f.name == 'assets/css/styles.min.css'
f_path = File.join("#{Rails.root}/app/assets/stylesheets/page-#{id.to_s}", "styles.min.css")
FileUtils.mkdir_p(File.dirname(f_path))
zip.(f, f_path) unless File.exist?(f_path)
text = File.read(f_path)
new_contents = text.gsub(
'../img', '/assets/page-' + id.to_s)
File.open(f_path, "w") {|file| file.puts new_contents}
elsif f.name == 'assets/js/app.min.js'
f_path = File.join("#{Rails.root}/app/assets/javascripts/page-#{id.to_s}", "app.min.js")
FileUtils.mkdir_p(File.dirname(f_path))
zip.(f, f_path) unless File.exist?(f_path)
elsif f.name.include? 'assets/img/'
file_name = f.name.split('assets/img/')[1]
f_path = File.join("#{Rails.root}/app/assets/images/page-#{id.to_s}", file_name)
FileUtils.mkdir_p(File.dirname(f_path))
zip.(f, f_path) unless File.exist?(f_path)
else
next
end
end
end
end
|