summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-02-20 13:26:22 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-02-20 13:26:22 +0000
commitbc0b438d13f6bffd8e837f551a5415173f43f9f3 (patch)
tree0218cbd37c409551e0c1fdde938adc2319e382f7 /app
parente03a7c53aedfb8f5c9afcf71e1e2e071084b3f56 (diff)
parentc9d687d6fed8ee9d0b9dfd1ebb55ddbb30b39fe2 (diff)
downloadgitlab-ce-bc0b438d13f6bffd8e837f551a5415173f43f9f3.tar.gz
Merge branch '21240_snippets_line_ending' into 'master'
Download snippets with LF line-endings by default Closes #21240 See merge request !8999
Diffstat (limited to 'app')
-rw-r--r--app/controllers/concerns/snippets_actions.rb21
-rw-r--r--app/controllers/projects/snippets_controller.rb13
-rw-r--r--app/controllers/snippets_controller.rb15
3 files changed, 24 insertions, 25 deletions
diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb
new file mode 100644
index 00000000000..ca6dffe1cc5
--- /dev/null
+++ b/app/controllers/concerns/snippets_actions.rb
@@ -0,0 +1,21 @@
+module SnippetsActions
+ extend ActiveSupport::Concern
+
+ def edit
+ end
+
+ def raw
+ send_data(
+ convert_line_endings(@snippet.content),
+ type: 'text/plain; charset=utf-8',
+ disposition: 'inline',
+ filename: @snippet.sanitized_file_name
+ )
+ end
+
+ private
+
+ def convert_line_endings(content)
+ params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
+ end
+end
diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb
index 5d193f26a8e..ef5d3d242eb 100644
--- a/app/controllers/projects/snippets_controller.rb
+++ b/app/controllers/projects/snippets_controller.rb
@@ -1,6 +1,7 @@
class Projects::SnippetsController < Projects::ApplicationController
include ToggleAwardEmoji
include SpammableActions
+ include SnippetsActions
before_action :module_enabled
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw, :toggle_award_emoji, :mark_as_spam]
@@ -49,9 +50,6 @@ class Projects::SnippetsController < Projects::ApplicationController
end
end
- def edit
- end
-
def update
UpdateSnippetService.new(project, current_user, @snippet,
snippet_params).execute
@@ -74,15 +72,6 @@ class Projects::SnippetsController < Projects::ApplicationController
redirect_to namespace_project_snippets_path(@project.namespace, @project)
end
- def raw
- send_data(
- @snippet.content,
- type: 'text/plain; charset=utf-8',
- disposition: 'inline',
- filename: @snippet.sanitized_file_name
- )
- end
-
protected
def snippet
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb
index b169d993688..366804ab17e 100644
--- a/app/controllers/snippets_controller.rb
+++ b/app/controllers/snippets_controller.rb
@@ -1,6 +1,7 @@
class SnippetsController < ApplicationController
include ToggleAwardEmoji
include SpammableActions
+ include SnippetsActions
before_action :snippet, only: [:show, :edit, :destroy, :update, :raw, :download]
@@ -47,9 +48,6 @@ class SnippetsController < ApplicationController
respond_with @snippet.becomes(Snippet)
end
- def edit
- end
-
def update
UpdateSnippetService.new(nil, current_user, @snippet,
snippet_params).execute
@@ -67,18 +65,9 @@ class SnippetsController < ApplicationController
redirect_to snippets_path
end
- def raw
- send_data(
- @snippet.content,
- type: 'text/plain; charset=utf-8',
- disposition: 'inline',
- filename: @snippet.sanitized_file_name
- )
- end
-
def download
send_data(
- @snippet.content,
+ convert_line_endings(@snippet.content),
type: 'text/plain; charset=utf-8',
filename: @snippet.sanitized_file_name
)