Commit 3f35cccfbd9a97bd1291c3b2dd7bdf78e8acc047
1 parent
4bf4efe7
Exists in
master
and in
4 other branches
ref controller refactored
Showing
2 changed files
with
10 additions
and
11 deletions
Show diff stats
app/controllers/refs_controller.rb
| 1 | class RefsController < ApplicationController | 1 | class RefsController < ApplicationController |
| 2 | before_filter :project | 2 | before_filter :project |
| 3 | before_filter :ref | 3 | before_filter :ref |
| 4 | + before_filter :define_tree_vars, :only => [:tree, :blob] | ||
| 4 | layout "project" | 5 | layout "project" |
| 5 | 6 | ||
| 6 | # Authorize | 7 | # Authorize |
| @@ -22,12 +23,6 @@ class RefsController < ApplicationController | @@ -22,12 +23,6 @@ class RefsController < ApplicationController | ||
| 22 | # Repository preview | 23 | # Repository preview |
| 23 | # | 24 | # |
| 24 | def tree | 25 | def tree |
| 25 | - @repo = project.repo | ||
| 26 | - | ||
| 27 | - @commit = @repo.commits(@ref).first | ||
| 28 | - @tree = Tree.new(@commit.tree, project, @ref, params[:path]) | ||
| 29 | - @tree = TreeDecorator.new(@tree) | ||
| 30 | - | ||
| 31 | respond_to do |format| | 26 | respond_to do |format| |
| 32 | format.html | 27 | format.html |
| 33 | format.js do | 28 | format.js do |
| @@ -40,11 +35,7 @@ class RefsController < ApplicationController | @@ -40,11 +35,7 @@ class RefsController < ApplicationController | ||
| 40 | end | 35 | end |
| 41 | 36 | ||
| 42 | def blob | 37 | def blob |
| 43 | - @repo = project.repo | ||
| 44 | - @commit = project.commit(@ref) | ||
| 45 | - @tree = project.tree(@commit, params[:path]) | ||
| 46 | - | ||
| 47 | - if @tree.is_a?(Grit::Blob) | 38 | + if @tree.is_blob? |
| 48 | send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) | 39 | send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) |
| 49 | else | 40 | else |
| 50 | head(404) | 41 | head(404) |
| @@ -55,6 +46,13 @@ class RefsController < ApplicationController | @@ -55,6 +46,13 @@ class RefsController < ApplicationController | ||
| 55 | 46 | ||
| 56 | protected | 47 | protected |
| 57 | 48 | ||
| 49 | + def define_tree_vars | ||
| 50 | + @repo = project.repo | ||
| 51 | + @commit = project.commit(@ref) | ||
| 52 | + @tree = Tree.new(@commit.tree, project, @ref, params[:path]) | ||
| 53 | + @tree = TreeDecorator.new(@tree) | ||
| 54 | + end | ||
| 55 | + | ||
| 58 | def ref | 56 | def ref |
| 59 | @ref = params[:id] | 57 | @ref = params[:id] |
| 60 | end | 58 | end |