2017-02-06 10:04:00 -05:00
|
|
|
module SnippetsActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-02-06 10:04:00 -05:00
|
|
|
def raw
|
2017-04-30 13:15:20 -04:00
|
|
|
disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
|
|
|
|
|
2017-02-06 10:04:00 -05:00
|
|
|
send_data(
|
|
|
|
convert_line_endings(@snippet.content),
|
|
|
|
type: 'text/plain; charset=utf-8',
|
2017-04-30 13:15:20 -04:00
|
|
|
disposition: disposition,
|
2017-02-06 10:04:00 -05:00
|
|
|
filename: @snippet.sanitized_file_name
|
|
|
|
)
|
|
|
|
end
|
2017-11-22 02:50:36 -05:00
|
|
|
# rubocop:enable Gitlab/ModuleWithInstanceVariables
|
2017-02-06 10:04:00 -05:00
|
|
|
|
2018-02-06 08:33:18 -05:00
|
|
|
def js_request?
|
|
|
|
request.format.js?
|
|
|
|
end
|
|
|
|
|
2017-02-06 10:04:00 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def convert_line_endings(content)
|
|
|
|
params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
|
|
|
|
end
|
|
|
|
end
|