From 99d391332fa9a6c11e93bd19295425167661b972 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 25 Sep 2012 18:46:19 -0400 Subject: [PATCH] Add a "patch" MIME type, and render it like a normal view in Commit#show --- app/controllers/commit_controller.rb | 25 ++++++++++++++----------- app/controllers/commits_controller.rb | 11 ----------- app/views/commit/show.patch.erb | 1 + config/initializers/mime_types.rb | 2 ++ 4 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 app/views/commit/show.patch.erb diff --git a/app/controllers/commit_controller.rb b/app/controllers/commit_controller.rb index 73a55614..de0d5b2e 100644 --- a/app/controllers/commit_controller.rb +++ b/app/controllers/commit_controller.rb @@ -15,19 +15,22 @@ class CommitController < ApplicationController result = CommitLoad.new(project, current_user, params).execute @commit = result[:commit] + git_not_found! unless @commit - if @commit - @suppress_diff = result[:suppress_diff] - @note = result[:note] - @line_notes = result[:line_notes] - @notes_count = result[:notes_count] - @comments_allowed = true - else - return git_not_found! - end + @suppress_diff = result[:suppress_diff] + @note = result[:note] + @line_notes = result[:line_notes] + @notes_count = result[:notes_count] + @comments_allowed = true - if result[:status] == :huge_commit - render "huge_commit" and return + respond_to do |format| + format.html do + if result[:status] == :huge_commit + render "huge_commit" and return + end + end + + format.patch end end end diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index ba6c6c24..bd67ee88 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -25,15 +25,4 @@ class CommitsController < ApplicationController format.atom { render layout: false } end end - - def patch - @commit = project.commit(params[:id]) - - send_data( - @commit.to_patch, - type: "text/plain", - disposition: 'attachment', - filename: "#{@commit.id}.patch" - ) - end end diff --git a/app/views/commit/show.patch.erb b/app/views/commit/show.patch.erb new file mode 100644 index 00000000..ce1c3d02 --- /dev/null +++ b/app/views/commit/show.patch.erb @@ -0,0 +1 @@ +<%= @commit.to_patch %> diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 72aca7e4..3549b836 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -3,3 +3,5 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone + +Mime::Type.register_alias 'text/plain', :patch