gitlab-org--gitlab-foss/app/controllers/concerns/snippets_actions.rb

34 lines
699 B
Ruby
Raw Normal View History

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