| |   |
| 8 | 8 | project_repository_log_path(@project, @repository, args) |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | | def tree_path(sha1=nil) |
| 12 | | project_repository_tree_path(@project, @repository, sha1) |
| 11 | def tree_path(sha1=nil, path=[]) |
| 12 | project_repository_tree_path(@project, @repository, sha1, path) |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | 15 | def commit_path(sha1) |
| 16 | 16 | project_repository_commit_path(@project, @repository, sha1) |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | | def blob_path(sha1, filename) |
| 20 | | project_repository_blob_path(@project, @repository, sha1, filename) |
| 19 | def blob_path(sha1, path) |
| 20 | project_repository_blob_path(@project, @repository, sha1, path) |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | | def raw_blob_path(sha1, filename) |
| 24 | | project_repository_raw_blob_path(@project, @repository, sha1, filename) |
| 23 | def raw_blob_path(sha1, path) |
| 24 | project_repository_raw_blob_path(@project, @repository, sha1, path) |
| 25 | 25 | end |
| 26 | 26 | |
| 27 | 27 | def diff_path(sha1, other_sha1) |
| 28 | 28 | project_repository_diff_path(@project, @repository, sha1, other_sha1) |
| 29 | 29 | end |
| 30 | |
| 31 | def current_path |
| 32 | params[:path].dup |
| 33 | end |
| 34 | |
| 35 | def build_tree_path(path) |
| 36 | current_path << path |
| 37 | end |
| 38 | |
| 39 | # def breadcrumb_path |
| 40 | # out = %Q{<ul class="path_breadcrumbs">\n} |
| 41 | # visited_path = [] |
| 42 | # out << %Q{ <li>/ #{link_to("root", tree_path(params[:sha], []))}</li>\n} |
| 43 | # current_path.each_with_index do |path, index| |
| 44 | # visited_path << path |
| 45 | # out << %Q{ <li>/ #{link_to(path, tree_path(params[:sha], path))}</li>\n} |
| 46 | # end |
| 47 | # out << "</ul>" |
| 48 | # out |
| 49 | # end |
| 30 | 50 | |
| 31 | 51 | def render_tag_box_if_match(sha, tags_per_sha) |
| 32 | 52 | tags = tags_per_sha[sha] |
| toggle raw diff |
--- a/app/helpers/browse_helper.rb
+++ b/app/helpers/browse_helper.rb
@@ -8,25 +8,45 @@ module BrowseHelper
project_repository_log_path(@project, @repository, args)
end
- def tree_path(sha1=nil)
- project_repository_tree_path(@project, @repository, sha1)
+ def tree_path(sha1=nil, path=[])
+ project_repository_tree_path(@project, @repository, sha1, path)
end
def commit_path(sha1)
project_repository_commit_path(@project, @repository, sha1)
end
- def blob_path(sha1, filename)
- project_repository_blob_path(@project, @repository, sha1, filename)
+ def blob_path(sha1, path)
+ project_repository_blob_path(@project, @repository, sha1, path)
end
- def raw_blob_path(sha1, filename)
- project_repository_raw_blob_path(@project, @repository, sha1, filename)
+ def raw_blob_path(sha1, path)
+ project_repository_raw_blob_path(@project, @repository, sha1, path)
end
def diff_path(sha1, other_sha1)
project_repository_diff_path(@project, @repository, sha1, other_sha1)
end
+
+ def current_path
+ params[:path].dup
+ end
+
+ def build_tree_path(path)
+ current_path << path
+ end
+
+ # def breadcrumb_path
+ # out = %Q{<ul class="path_breadcrumbs">\n}
+ # visited_path = []
+ # out << %Q{ <li>/ #{link_to("root", tree_path(params[:sha], []))}</li>\n}
+ # current_path.each_with_index do |path, index|
+ # visited_path << path
+ # out << %Q{ <li>/ #{link_to(path, tree_path(params[:sha], path))}</li>\n}
+ # end
+ # out << "</ul>"
+ # out
+ # end
def render_tag_box_if_match(sha, tags_per_sha)
tags = tags_per_sha[sha] |
| |   |
| 8 | 8 | <tr class="<%= cycle("odd", "even") -%>"> |
| 9 | 9 | <!-- <td><%#= h(node.mode) -%></td> --> |
| 10 | 10 | <% if node.type == "tree" -%> |
| 11 | | <td class="node tree"><%= link_to h(file + "/"), tree_path(node.sha) -%></td> |
| 12 | | <td class="link"><%= link_to node.type, tree_path(node.sha) -%></td> |
| 11 | <td class="node tree"><%= link_to h(file + "/"), tree_path(node.sha, build_tree_path(file)) -%></td> |
| 12 | <td class="link"><%= link_to node.type, tree_path(node.sha, build_tree_path(file)) -%></td> |
| 13 | 13 | <!-- TODO: archive --> |
| 14 | 14 | <% else -%> |
| 15 | | <td class="node file"><%= link_to h(file), blob_path(node.sha, file) -%></td> |
| 16 | | <td class="link"><%= link_to node.type, blob_path(node.sha, file) -%></td> |
| 15 | <td class="node file"><%= link_to h(file), blob_path(node.sha, build_tree_path(file)) -%></td> |
| 16 | <td class="link"><%= link_to node.type, blob_path(node.sha, build_tree_path(file)) -%></td> |
| 17 | 17 | <% end -%> |
| 18 | 18 | <td class="sha1"><%= h(node.sha[0..16]) -%></td> |
| 19 | 19 | </tr> |
| toggle raw diff |
--- a/app/views/browse/tree.html.erb
+++ b/app/views/browse/tree.html.erb
@@ -8,12 +8,12 @@
<tr class="<%= cycle("odd", "even") -%>">
<!-- <td><%#= h(node.mode) -%></td> -->
<% if node.type == "tree" -%>
- <td class="node tree"><%= link_to h(file + "/"), tree_path(node.sha) -%></td>
- <td class="link"><%= link_to node.type, tree_path(node.sha) -%></td>
+ <td class="node tree"><%= link_to h(file + "/"), tree_path(node.sha, build_tree_path(file)) -%></td>
+ <td class="link"><%= link_to node.type, tree_path(node.sha, build_tree_path(file)) -%></td>
<!-- TODO: archive -->
<% else -%>
- <td class="node file"><%= link_to h(file), blob_path(node.sha, file) -%></td>
- <td class="link"><%= link_to node.type, blob_path(node.sha, file) -%></td>
+ <td class="node file"><%= link_to h(file), blob_path(node.sha, build_tree_path(file)) -%></td>
+ <td class="link"><%= link_to node.type, blob_path(node.sha, build_tree_path(file)) -%></td>
<% end -%>
<td class="sha1"><%= h(node.sha[0..16]) -%></td>
</tr> |
| |   |
| 2 | 2 | |
| 3 | 3 | describe BrowseHelper do |
| 4 | 4 | |
| 5 | | #Delete this example and add some real ones or delete this file |
| 6 | | it "should include the BrowseHelper" do |
| 7 | | included_modules = self.metaclass.send :included_modules |
| 8 | | included_modules.should include(BrowseHelper) |
| 5 | before(:each) do |
| 6 | @project = projects(:johans) |
| 7 | @repository = @project.repositories.first |
| 8 | end |
| 9 | |
| 10 | it "has a browse_path shortcut" do |
| 11 | browse_path.should == project_repository_browse_path(@project, @repository) |
| 12 | end |
| 13 | |
| 14 | it "has a log_path shortcut" do |
| 15 | log_path.should == project_repository_log_path(@project, @repository) |
| 16 | end |
| 17 | |
| 18 | it "has a log_path shortcut that takes args" do |
| 19 | log_path(:page => 2).should == project_repository_log_path(@project, |
| 20 | @repository, {:page => 2}) |
| 21 | end |
| 22 | |
| 23 | it "has a tree_path shortcut" do |
| 24 | tree_path.should == project_repository_tree_path(@project, @repository) |
| 25 | end |
| 26 | |
| 27 | it "has a tree_path shortcut that takes an sha1" do |
| 28 | tree_path("abc123").should == project_repository_tree_path(@project, |
| 29 | @repository, "abc123") |
| 30 | end |
| 31 | |
| 32 | it "has a tree_path shortcut that takes an sha1 and a path glob" do |
| 33 | tree_path("abc123", ["a", "b"]).should == project_repository_tree_path(@project, |
| 34 | @repository, "abc123", ["a", "b"]) |
| 35 | end |
| 36 | |
| 37 | it "has a commit_path shortcut" do |
| 38 | commit_path("abc123").should == project_repository_commit_path(@project, |
| 39 | @repository, "abc123") |
| 40 | end |
| 41 | |
| 42 | it "has a blob_path shortcut" do |
| 43 | blob_path("sha", ["a","b"]).should == project_repository_blob_path(@project, |
| 44 | @repository, "sha", ["a","b"]) |
| 45 | end |
| 46 | |
| 47 | it "has a raw_blob_path shortcut" do |
| 48 | raw_blob_path("sha", ["a","b"]).should == project_repository_raw_blob_path( |
| 49 | @project, @repository, "sha", ["a","b"]) |
| 50 | end |
| 51 | |
| 52 | it "has a diff_path shortcut" do |
| 53 | diff_path("old", "new").should == project_repository_diff_path(@project, |
| 54 | @repository, "old", "new") |
| 55 | end |
| 56 | |
| 57 | it "has a current_path based on the *path glob" do |
| 58 | params[:path] = ["one", "two"] |
| 59 | current_path.should == ["one", "two"] |
| 60 | end |
| 61 | |
| 62 | it "builds a tree from current_path" do |
| 63 | params[:path] = ["one", "two"] |
| 64 | build_tree_path("three").should == ["one", "two", "three"] |
| 65 | end |
| 66 | |
| 67 | it "builds breadcrumbs of the current_path" do |
| 68 | stub!(:current_path).and_return(["one", "two", "tree"]) |
| 69 | breadcrumb_path.should include(%Q{<ul class="path_breadcrumbs">}) |
| 70 | breadcrumb_path.should include("<li> / ") |
| 9 | 71 | end |
| 10 | 72 | |
| 11 | 73 | end |
| toggle raw diff |
--- a/spec/helpers/browse_helper_spec.rb
+++ b/spec/helpers/browse_helper_spec.rb
@@ -2,10 +2,72 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe BrowseHelper do
- #Delete this example and add some real ones or delete this file
- it "should include the BrowseHelper" do
- included_modules = self.metaclass.send :included_modules
- included_modules.should include(BrowseHelper)
+ before(:each) do
+ @project = projects(:johans)
+ @repository = @project.repositories.first
+ end
+
+ it "has a browse_path shortcut" do
+ browse_path.should == project_repository_browse_path(@project, @repository)
+ end
+
+ it "has a log_path shortcut" do
+ log_path.should == project_repository_log_path(@project, @repository)
+ end
+
+ it "has a log_path shortcut that takes args" do
+ log_path(:page => 2).should == project_repository_log_path(@project,
+ @repository, {:page => 2})
+ end
+
+ it "has a tree_path shortcut" do
+ tree_path.should == project_repository_tree_path(@project, @repository)
+ end
+
+ it "has a tree_path shortcut that takes an sha1" do
+ tree_path("abc123").should == project_repository_tree_path(@project,
+ @repository, "abc123")
+ end
+
+ it "has a tree_path shortcut that takes an sha1 and a path glob" do
+ tree_path("abc123", ["a", "b"]).should == project_repository_tree_path(@project,
+ @repository, "abc123", ["a", "b"])
+ end
+
+ it "has a commit_path shortcut" do
+ commit_path("abc123").should == project_repository_commit_path(@project,
+ @repository, "abc123")
+ end
+
+ it "has a blob_path shortcut" do
+ blob_path("sha", ["a","b"]).should == project_repository_blob_path(@project,
+ @repository, "sha", ["a","b"])
+ end
+
+ it "has a raw_blob_path shortcut" do
+ raw_blob_path("sha", ["a","b"]).should == project_repository_raw_blob_path(
+ @project, @repository, "sha", ["a","b"])
+ end
+
+ it "has a diff_path shortcut" do
+ diff_path("old", "new").should == project_repository_diff_path(@project,
+ @repository, "old", "new")
+ end
+
+ it "has a current_path based on the *path glob" do
+ params[:path] = ["one", "two"]
+ current_path.should == ["one", "two"]
+ end
+
+ it "builds a tree from current_path" do
+ params[:path] = ["one", "two"]
+ build_tree_path("three").should == ["one", "two", "three"]
+ end
+
+ it "builds breadcrumbs of the current_path" do
+ stub!(:current_path).and_return(["one", "two", "tree"])
+ breadcrumb_path.should include(%Q{<ul class="path_breadcrumbs">})
+ breadcrumb_path.should include("<li> / ")
end
end |