ref controller refactored

This commit is contained in:
gitlabhq 2011-11-21 01:16:10 -05:00
parent 4bf4efe712
commit 3f35cccfbd
2 changed files with 10 additions and 11 deletions

View file

@ -1,6 +1,7 @@
class RefsController < ApplicationController class RefsController < ApplicationController
before_filter :project before_filter :project
before_filter :ref before_filter :ref
before_filter :define_tree_vars, :only => [:tree, :blob]
layout "project" layout "project"
# Authorize # Authorize
@ -22,12 +23,6 @@ class RefsController < ApplicationController
# Repository preview # Repository preview
# #
def tree def tree
@repo = project.repo
@commit = @repo.commits(@ref).first
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
respond_to do |format| respond_to do |format|
format.html format.html
format.js do format.js do
@ -40,11 +35,7 @@ class RefsController < ApplicationController
end end
def blob def blob
@repo = project.repo if @tree.is_blob?
@commit = project.commit(@ref)
@tree = project.tree(@commit, params[:path])
if @tree.is_a?(Grit::Blob)
send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name)
else else
head(404) head(404)
@ -55,6 +46,13 @@ class RefsController < ApplicationController
protected protected
def define_tree_vars
@repo = project.repo
@commit = project.commit(@ref)
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
end
def ref def ref
@ref = params[:id] @ref = params[:id]
end end

View file

@ -5,6 +5,7 @@ class Tree
:basename, :basename,
:name, :name,
:data, :data,
:mime_type,
:text?, :text?,
:colorize, :colorize,
:to => :tree :to => :tree