summaryrefslogtreecommitdiff
path: root/app/controllers/concerns/snippets_actions.rb
blob: 9095cc7f78304925dd6e32714d9f707cfec083c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module SnippetsActions
  extend ActiveSupport::Concern

  def edit
  end

  # rubocop:disable Gitlab/ModuleWithInstanceVariables
  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
  # rubocop:enable Gitlab/ModuleWithInstanceVariables

  private

  def convert_line_endings(content)
    params[:line_ending] == 'raw' ? content : content.gsub(/\r\n/, "\n")
  end
end