From e33cbb9b4252e2617bcb4c3f850c47aae43e4d83 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 17 Sep 2012 12:38:59 -0400 Subject: Add TreeController and spec --- app/controllers/tree_controller.rb | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/controllers/tree_controller.rb (limited to 'app/controllers/tree_controller.rb') diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb new file mode 100644 index 00000000000..15bbb1a3c77 --- /dev/null +++ b/app/controllers/tree_controller.rb @@ -0,0 +1,49 @@ +# Controller for viewing a repository's file structure +class TreeController < ApplicationController + # Thrown when given an invalid path + class InvalidPathError < StandardError; end + + include RefExtractor + + layout "project" + + before_filter :project + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_project! + before_filter :authorize_code_access! + before_filter :require_non_empty_project + + before_filter :define_tree_vars + + def show + respond_to do |format| + format.html + # Disable cache so browser history works + format.js { no_cache_headers } + end + end + + private + + def define_tree_vars + @ref, @path = extract_ref(params[:id]) + + @id = File.join(@ref, @path) + @repo = @project.repo + @commit = CommitDecorator.decorate(@project.commit(@ref)) + + @tree = Tree.new(@commit.tree, @project, @ref, @path.gsub(/^\//, '')) + @tree = TreeDecorator.new(@tree) + + raise InvalidPathError if @tree.invalid? + + @hex_path = Digest::SHA1.hexdigest(@path) + + @history_path = project_tree_path(@project, @id) + @logs_path = logs_file_project_ref_path(@project, @ref, @path) + rescue NoMethodError, InvalidPathError + not_found! + end +end -- cgit v1.2.1 From 398ba6f1bb60f176444dedc7b26188e08b920f54 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 17 Sep 2012 14:24:31 -0400 Subject: DRY up Blame, Blob and Tree controllers --- app/controllers/tree_controller.rb | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'app/controllers/tree_controller.rb') diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index 15bbb1a3c77..e0dd8f8beaf 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -15,35 +15,18 @@ class TreeController < ApplicationController before_filter :authorize_code_access! before_filter :require_non_empty_project - before_filter :define_tree_vars + before_filter :assign_ref_vars def show + @hex_path = Digest::SHA1.hexdigest(@path) + + @history_path = project_tree_path(@project, @id) + @logs_path = logs_file_project_ref_path(@project, @ref, @path) + respond_to do |format| format.html # Disable cache so browser history works format.js { no_cache_headers } end end - - private - - def define_tree_vars - @ref, @path = extract_ref(params[:id]) - - @id = File.join(@ref, @path) - @repo = @project.repo - @commit = CommitDecorator.decorate(@project.commit(@ref)) - - @tree = Tree.new(@commit.tree, @project, @ref, @path.gsub(/^\//, '')) - @tree = TreeDecorator.new(@tree) - - raise InvalidPathError if @tree.invalid? - - @hex_path = Digest::SHA1.hexdigest(@path) - - @history_path = project_tree_path(@project, @id) - @logs_path = logs_file_project_ref_path(@project, @ref, @path) - rescue NoMethodError, InvalidPathError - not_found! - end end -- cgit v1.2.1 From a8ea8d98a4f88a292289ddfedef4358033b68ec0 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 20 Sep 2012 13:25:28 -0400 Subject: Update RefExtractor to handle atom feeds --- app/controllers/tree_controller.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'app/controllers/tree_controller.rb') diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index e0dd8f8beaf..430876647d4 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -1,8 +1,5 @@ # Controller for viewing a repository's file structure class TreeController < ApplicationController - # Thrown when given an invalid path - class InvalidPathError < StandardError; end - include RefExtractor layout "project" -- cgit v1.2.1 From a1e68a91205186287f21fb5fd1669acebcd7e79e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 20 Sep 2012 13:55:14 -0400 Subject: Rename RefExtractor to ExtractsPath Update docs a bit --- app/controllers/tree_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/tree_controller.rb') diff --git a/app/controllers/tree_controller.rb b/app/controllers/tree_controller.rb index 430876647d4..e6313783d6e 100644 --- a/app/controllers/tree_controller.rb +++ b/app/controllers/tree_controller.rb @@ -1,6 +1,6 @@ # Controller for viewing a repository's file structure class TreeController < ApplicationController - include RefExtractor + include ExtractsPath layout "project" -- cgit v1.2.1