lib/gitdocs/server.rb in gitdocs-0.4.14 vs lib/gitdocs/server.rb in gitdocs-0.4.15

- old
+ new

@@ -89,12 +89,17 @@ elsif mode == 'upload' # Uploading halt 404 unless file = request.params['file'] tempfile, filename = file[:tempfile], file[:filename] FileUtils.mv(tempfile.path, File.expand_path(filename, expanded_path)) redirect! "/" + idx.to_s + file_path + "/" + filename - elsif !File.exist?(expanded_path) # edit for non-existent file - render! "edit", :layout => 'app', :locals => locals.merge(:contents => "") + elsif !File.exist?(expanded_path) && !request.params['dir'] # edit for non-existent file + FileUtils.mkdir_p(File.dirname(expanded_path)) + FileUtils.touch(expanded_path) + redirect! "/" + idx.to_s + file_path + "?mode=edit" + elsif !File.exist?(expanded_path) && request.params['dir'] # create directory + FileUtils.mkdir_p(expanded_path) + redirect! "/" + idx.to_s + file_path elsif File.directory?(expanded_path) # list directory contents = gd.dir_files(expanded_path) rendered_readme = nil if readme = Dir[File.expand_path("README.{md,txt}", expanded_path)].first rendered_readme = '<h3>' + File.basename(readme) + '</h3><div class="tilt">' + render(readme) + '</div>' @@ -110,11 +115,11 @@ end redirect! "/" + idx.to_s + file_path elsif mode == 'delete' # delete file FileUtils.rm(expanded_path) redirect! "/" + idx.to_s + parent - elsif mode == 'edit' && mime.match(%r{text/}) # edit file + elsif mode == 'edit' && (mime.match(%r{text/}) || mime.match(%r{x-empty})) # edit file contents = File.read(expanded_path) render! "edit", :layout => 'app', :locals => locals.merge(:contents => contents) elsif mode != 'raw' # render file revision = request.params['revision'] expanded_path = gd.file_revision_at(file_path, revision) if revision @@ -137,6 +142,6 @@ views_path File.expand_path("../views", __FILE__) } end end end -end \ No newline at end of file +end