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 | 1 | class RefsController < ApplicationController |
2 | 2 | before_filter :project |
3 | 3 | before_filter :ref |
4 | + before_filter :define_tree_vars, :only => [:tree, :blob] | |
4 | 5 | layout "project" |
5 | 6 | |
6 | 7 | # Authorize |
... | ... | @@ -22,12 +23,6 @@ class RefsController < ApplicationController |
22 | 23 | # Repository preview |
23 | 24 | # |
24 | 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 | 26 | respond_to do |format| |
32 | 27 | format.html |
33 | 28 | format.js do |
... | ... | @@ -40,11 +35,7 @@ class RefsController < ApplicationController |
40 | 35 | end |
41 | 36 | |
42 | 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 | 39 | send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) |
49 | 40 | else |
50 | 41 | head(404) |
... | ... | @@ -55,6 +46,13 @@ class RefsController < ApplicationController |
55 | 46 | |
56 | 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 | 56 | def ref |
59 | 57 | @ref = params[:id] |
60 | 58 | end | ... | ... |