Commit 99d391332fa9a6c11e93bd19295425167661b972

Authored by Robert Speicher
1 parent c058e390

Add a "patch" MIME type, and render it like a normal view in Commit#show

app/controllers/commit_controller.rb
@@ -15,19 +15,22 @@ class CommitController < ApplicationController @@ -15,19 +15,22 @@ class CommitController < ApplicationController
15 result = CommitLoad.new(project, current_user, params).execute 15 result = CommitLoad.new(project, current_user, params).execute
16 16
17 @commit = result[:commit] 17 @commit = result[:commit]
  18 + git_not_found! unless @commit
18 19
19 - if @commit  
20 - @suppress_diff = result[:suppress_diff]  
21 - @note = result[:note]  
22 - @line_notes = result[:line_notes]  
23 - @notes_count = result[:notes_count]  
24 - @comments_allowed = true  
25 - else  
26 - return git_not_found!  
27 - end 20 + @suppress_diff = result[:suppress_diff]
  21 + @note = result[:note]
  22 + @line_notes = result[:line_notes]
  23 + @notes_count = result[:notes_count]
  24 + @comments_allowed = true
  25 +
  26 + respond_to do |format|
  27 + format.html do
  28 + if result[:status] == :huge_commit
  29 + render "huge_commit" and return
  30 + end
  31 + end
28 32
29 - if result[:status] == :huge_commit  
30 - render "huge_commit" and return 33 + format.patch
31 end 34 end
32 end 35 end
33 end 36 end
app/controllers/commits_controller.rb
@@ -25,15 +25,4 @@ class CommitsController < ApplicationController @@ -25,15 +25,4 @@ class CommitsController < ApplicationController
25 format.atom { render layout: false } 25 format.atom { render layout: false }
26 end 26 end
27 end 27 end
28 -  
29 - def patch  
30 - @commit = project.commit(params[:id])  
31 -  
32 - send_data(  
33 - @commit.to_patch,  
34 - type: "text/plain",  
35 - disposition: 'attachment',  
36 - filename: "#{@commit.id}.patch"  
37 - )  
38 - end  
39 end 28 end
app/views/commit/show.patch.erb 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +<%= @commit.to_patch %>
config/initializers/mime_types.rb
@@ -3,3 +3,5 @@ @@ -3,3 +3,5 @@
3 # Add new mime types for use in respond_to blocks: 3 # Add new mime types for use in respond_to blocks:
4 # Mime::Type.register "text/richtext", :rtf 4 # Mime::Type.register "text/richtext", :rtf
5 # Mime::Type.register_alias "text/html", :iphone 5 # Mime::Type.register_alias "text/html", :iphone
  6 +
  7 +Mime::Type.register_alias 'text/plain', :patch