debian-mirror-gitlab/app/controllers/concerns/snippets_actions.rb

34 lines
699 B
Ruby
Raw Normal View History

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'
2018-12-23 12:14:25 +05:30
workhorse_set_content_type!
2017-08-17 22:00:37 +05:30
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