2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module SnippetsActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-08-17 22:00:37 +05:30
|
|
|
def raw
|
|
|
|
disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
|
|
|
|
|
|
|
|
send_data(
|
|
|
|
convert_line_endings(@snippet.content),
|
|
|
|
type: 'text/plain; charset=utf-8',
|
|
|
|
disposition: disposition,
|
|
|
|
filename: @snippet.sanitized_file_name
|
|
|
|
)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def js_request?
|
|
|
|
request.format.js?
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def convert_line_endings(content)
|
|
|
|
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
|
|
|
|
end
|
|
|
|
end
|