diff options
author | Marius Mathiesen <marius.mathiesen@gmail.com> | 2009-01-28 12:56:02 +0100 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-04-22 12:55:01 +0200 |
commit | 0cf56856198180a5b36f15ca081efaafab49f704 (patch) | |
tree | dabaee53a8ed502a7663fddd6e704460cc594417 | |
parent | aa6dfee81e8cb3f45bfe319a6e0388b4cac8e92b (diff) | |
download | gitorious-mainline-outdated-0cf56856198180a5b36f15ca081efaafab49f704.zip gitorious-mainline-outdated-0cf56856198180a5b36f15ca081efaafab49f704.tar.gz gitorious-mainline-outdated-0cf56856198180a5b36f15ca081efaafab49f704.tar.bz2 |
Adding breadcrumb support:
- Adding a Breadcrumb module w/specs
- Setting a root in LogsController
- Setting a root in TreesController
- Adding a Breadcrumb helper, include in Logs-, Repositories- and Projects helpers
- Replacing navigation in Logs#show, Projects#show, Repositories#show and Trees#show
(Temporarily?) removing the site menu.
-rw-r--r-- | app/controllers/logs_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/trees_controller.rb | 1 | ||||
-rw-r--r-- | app/helpers/breadcrumbs_helper.rb | 32 | ||||
-rw-r--r-- | app/helpers/logs_helper.rb | 1 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 1 | ||||
-rw-r--r-- | app/helpers/repositories_helper.rb | 1 | ||||
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/repository.rb | 8 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 2 | ||||
-rw-r--r-- | app/views/logs/show.html.erb | 2 | ||||
-rw-r--r-- | app/views/projects/show.html.erb | 2 | ||||
-rw-r--r-- | app/views/repositories/show.html.erb | 2 | ||||
-rw-r--r-- | app/views/site/_breadcrumbs.html.erb | 2 | ||||
-rw-r--r-- | app/views/trees/show.html.erb | 2 | ||||
-rw-r--r-- | lib/breadcrumb.rb | 33 | ||||
-rw-r--r-- | spec/lib/breadcrumb_spec.rb | 63 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 8 |
18 files changed, 164 insertions, 7 deletions
diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index a5d9ea6..097ffc5 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #++ - class LogsController < ApplicationController before_filter :find_project_and_repository before_filter :check_repository_for_commits @@ -25,6 +24,7 @@ class LogsController < ApplicationController def show @git = @repository.git + @root = Breadcrumb::Branch.new(@git.head, @repository) @commits = @repository.paginated_commits(params[:id], params[:page]) @atom_auto_discovery_url = project_repository_formatted_log_feed_path(@project, @repository, params[:id], :atom) respond_to do |format| diff --git a/app/controllers/trees_controller.rb b/app/controllers/trees_controller.rb index d452b0a..2ab4afb 100644 --- a/app/controllers/trees_controller.rb +++ b/app/controllers/trees_controller.rb @@ -27,6 +27,7 @@ class TreesController < ApplicationController def show @git = @repository.git @commit = @git.commit(params[:id]) + @root = Breadcrumb::Folder.new(:paths => params[:path], :head => @git.head, :repository => @repository) unless @commit redirect_to project_repository_tree_path(@project, @repository, "HEAD", params[:path]) return diff --git a/app/helpers/breadcrumbs_helper.rb b/app/helpers/breadcrumbs_helper.rb new file mode 100644 index 0000000..f36a3c8 --- /dev/null +++ b/app/helpers/breadcrumbs_helper.rb @@ -0,0 +1,32 @@ +module BreadcrumbsHelper + def render_breadcrumb_starting_from(root) + result = [] + html = '' + if current_breadcrumb = root + until current_breadcrumb.nil? + result << current_breadcrumb + current_breadcrumb = current_breadcrumb.breadcrumb_parent + end + end + result.reverse.each do |crumb| + html << content_tag(:li, breadcrumb_link_to(crumb), :class => crumb.class.to_s.demodulize.downcase) + end + return html + end + + def breadcrumb_link_to(an_object) + url = case an_object + when Repository + project_repository_path(@project, @repository) + when Project + project_path(an_object) + when Breadcrumb::Branch + project_repository_log_path(@project, @repository, an_object.title) + when Breadcrumb::Folder + tree_path(params[:id], an_object.paths) + else + "/" + end + link_to(an_object.title, url) + end +end
\ No newline at end of file diff --git a/app/helpers/logs_helper.rb b/app/helpers/logs_helper.rb index 9465a60..4020c85 100644 --- a/app/helpers/logs_helper.rb +++ b/app/helpers/logs_helper.rb @@ -17,4 +17,5 @@ module LogsHelper include RepositoriesHelper + include BreadcrumbsHelper end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 38a2d06..0d1730c 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -16,4 +16,5 @@ #++ module ProjectsHelper + include BreadcrumbsHelper end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 300767a..093f719 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -17,6 +17,7 @@ #++ module RepositoriesHelper + include BreadcrumbsHelper def log_path(objectish = "master", options = {}) if options.blank? # just to avoid the ? being tacked onto the url project_repository_log_path(@project, @repository, objectish) diff --git a/app/models/project.rb b/app/models/project.rb index 8a7e54e..09a8d13 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -162,6 +162,10 @@ class Project < ActiveRecord::Base events.create(:action => action_id, :target => target, :user => user, :body => body, :data => data, :created_at => date) end + + def breadcrumb_parent + nil + end protected def create_core_group diff --git a/app/models/repository.rb b/app/models/repository.rb index d09e23c..cf09e00 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -276,6 +276,14 @@ class Repository < ActiveRecord::Base owner === Group end + def breadcrumb_parent + project + end + + def title + name + end + protected def set_as_mainline_if_first unless project.repositories.size >= 1 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ce56d04..0805658 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -81,7 +81,7 @@ </div> <% end -%> - <% if @project -%> + <% if @project && false -%> <h2 id="project_title"><%= link_to h(@project.title), @project -%></h2> <ul id="submenu" class="<%= @content_for_submenu.blank? ? "white" : "" -%>"> <li class="<%= submenu_selected_class_if_current?(:overview) -%>"> diff --git a/app/views/logs/show.html.erb b/app/views/logs/show.html.erb index e601b1e..eff66bf 100644 --- a/app/views/logs/show.html.erb +++ b/app/views/logs/show.html.erb @@ -30,7 +30,7 @@ <%= render :partial => "log" -%> <% content_for :submenu do -%> - <%= render :partial => "repositories/context_menu" -%> + <%= render :partial => "site/breadcrumbs", :locals => {:root => @root} -%> <% end -%> <% content_for :sidebar do -%> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 4d0553a..8f54c87 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -33,7 +33,7 @@ <%= render :partial => "events/events", :locals => { :events => @events } -%> <% content_for :submenu do -%> - <%= render :partial => "site/breadcrumbs" -%> + <%= render :partial => "site/breadcrumbs", :locals => {:root => @project} -%> <% end -%> <% content_for :sidebar do -%> diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 7b4e963..eb76472 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -32,7 +32,7 @@ <% end -%> <% content_for :submenu do -%> - <%= render :partial => "context_menu" -%> + <%= render :partial => "site/breadcrumbs", :locals => {:root => @repository} -%> <% end -%> <% content_for :sidebar do -%> diff --git a/app/views/site/_breadcrumbs.html.erb b/app/views/site/_breadcrumbs.html.erb index dba5d67..1a39d9f 100644 --- a/app/views/site/_breadcrumbs.html.erb +++ b/app/views/site/_breadcrumbs.html.erb @@ -1 +1 @@ -Breadcrumbs coming up
\ No newline at end of file +<%= render_breadcrumb_starting_from(root) %> diff --git a/app/views/trees/show.html.erb b/app/views/trees/show.html.erb index a06d458..fe9052e 100644 --- a/app/views/trees/show.html.erb +++ b/app/views/trees/show.html.erb @@ -24,7 +24,7 @@ </h1> <% content_for :submenu do -%> - <%= render :partial => "repositories/context_menu" -%> + <%= render :partial => "site/breadcrumbs", :locals => {:root => @root} -%> <% end -%> <%= breadcrumb_path(@repository.name) -%> diff --git a/lib/breadcrumb.rb b/lib/breadcrumb.rb new file mode 100644 index 0000000..c44dba8 --- /dev/null +++ b/lib/breadcrumb.rb @@ -0,0 +1,33 @@ +module Breadcrumb + class Branch + def initialize(obj, parent) + @object = obj + @parent = parent + end + def breadcrumb_parent + @parent + end + def title + @object.name + end + end + + class Folder + attr_reader :paths + def initialize(options) + @paths = options[:paths] + @head = options[:head] + @repository = options[:repository] + end + def breadcrumb_parent + if @paths.blank? + Branch.new(@head, @repository) + else + Folder.new(:paths => @paths[0..-2], :head => @head, :repository => @repository) + end + end + def title + @paths.last || "/" + end + end +end diff --git a/spec/lib/breadcrumb_spec.rb b/spec/lib/breadcrumb_spec.rb new file mode 100644 index 0000000..0934707 --- /dev/null +++ b/spec/lib/breadcrumb_spec.rb @@ -0,0 +1,63 @@ +#-- +# Copyright (C) 2007, 2008 Johan Sørensen <johan@johansorensen.com> +# Copyright (C) 2008 Tim Dysinger <tim@dysinger.net> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +#++ + +require File.dirname(__FILE__) + '/../spec_helper' + +describe Breadcrumb::Folder do + before(:each) do + @head = Object.new + def @head.name + return "head" + end + @folder = Breadcrumb::Folder.new(:paths => %w(foo bar baz), :head => @head, :repository => nil) + end + + it 'should return a relevant title' do + @folder.title.should == 'baz' + end + + it 'should return parents all the way up to a Branch' do + branch = @folder.breadcrumb_parent.breadcrumb_parent.breadcrumb_parent.breadcrumb_parent + branch.should be_a(Breadcrumb::Branch) + end + + describe "a top level folder" do + folder = Breadcrumb::Folder.new(:paths => [], :head => @head, :repository => nil) + folder.title.should == '/' + end +end + + + +describe Breadcrumb::Branch do + before(:each) do + @o = Object.new + def @o.name + return "Yikes" + end + @branch = Breadcrumb::Branch.new(@o, 'I am a parent') + end + + it 'should return its title' do + @branch.title.should == 'Yikes' + end + + it 'should return its parent' do + @branch.breadcrumb_parent.should == "I am a parent" + end +end
\ No newline at end of file diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 98c68e7..cd9393c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -127,6 +127,11 @@ describe Project do project = create_project(:description => "<h1>Project A</h1>\n<b>Project A</b> is a....") project.stripped_description.should == "Project A\nProject A is a...." end + + it 'should have a breadcrumb_parent method which returns nil' do + project = create_project + project.breadcrumb_parent.should be_nil + end # it "should strip html tags, except highlights" do # project = create_project(:description => %Q{<h1>Project A</h1>\n<strong class="highlight">Project A</strong> is a....}) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 36b1f87..54007c4 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -359,6 +359,14 @@ describe Repository do @repository.wiki?.should == true end + it 'has a parent, which is the Project' do + @repository.breadcrumb_parent.should == @repository.project + end + + it 'should return its name as title' do + @repository.name.should == @repository.title + end + it "returns a list of committers depending on owner type" do repo = repositories(:johans) repo.owner.add_member(users(:mike), Role.admin) |