15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/controllers/statixite/templates_controller.rb', line 15
def update
if template_params[:path] == ""
@json = { message: "Something went wrong", status: "error" }
@response_status = 422
elsif !sanitized?
@json = { message: "Invalid name. try #{new_name}", status: "error" }
@response_status = 422
elsif (rename_folder? || rename_file?) && rename_not_changed?
@json = { message: "#{new_name} not changed.", status: 'info' }
@response_status = 200
elsif (new_file? || rename_file?) && new_file_or_folder_exists?
@json = { message: "File already exists. try another name!", status: "error" }
@response_status = 422
elsif (new_folder? || rename_folder?) && new_file_or_folder_exists?
@json = { message: "Folder already exists. try another name!", status: "warn" }
@response_status = 422
elsif new_file? && !new_file_or_folder_exists?
GitService.new(@site.site_clone_path, @site.site_remote).make_changes do
File.open(new_file, 'w+') { |f| f.write(template_params[:content]) }
end
@json = { message: "#{new_name} created!", status: "success", template: recurse_site(site_path) }
@response_status = 201
elsif new_folder? && !new_file_or_folder_exists?
GitService.new(@site.site_clone_path, @site.site_remote).make_changes do
Dir.mkdir(new_file)
end
@json = { message: "#{new_name} created!", status: "success", template: recurse_site(site_path) }
@response_status = 201
elsif (rename_folder? || rename_file?) && !new_file_or_folder_exists?
GitService.new(@site.site_clone_path, @site.site_remote).make_changes do
File.rename(old_file, new_file)
end
@json = { message: "Renamed to #{new_name}", status: 'success', template: recurse_site(site_path) }
@response_status = 201
elsif edit_file_content?
GitService.new(@site.site_clone_path, @site.site_remote).make_changes do
write_file_content
end
else
@json = { message: 'Something went wrong', status: 'error' }
@response_status = 422
end
apply_post_changes if @response_status.to_s[0] == "2"
render :json => @json, :status => @response_status
end
|