Merge pull request #1127 from riyad/use-decorators

Use CommitDecorator more
This commit is contained in:
Dmitriy Zaporozhets 2012-07-25 11:25:55 -07:00
commit 5133541f25
13 changed files with 37 additions and 24 deletions

View file

@ -17,6 +17,7 @@ class CommitsController < ApplicationController
@limit, @offset = (params[:limit] || 40), (params[:offset] || 0) @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
@commits = @project.commits(@ref, params[:path], @limit, @offset) @commits = @project.commits(@ref, params[:path], @limit, @offset)
@commits = CommitDecorator.decorate(@commits)
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb

View file

@ -143,5 +143,6 @@ class MergeRequestsController < ApplicationController
# Get commits from repository # Get commits from repository
# or from cache if already merged # or from cache if already merged
@commits = @merge_request.commits @commits = @merge_request.commits
@commits = CommitDecorator.decorate(@commits)
end end
end end

View file

@ -51,6 +51,7 @@ class RefsController < ApplicationController
@logs = contents.map do |content| @logs = contents.map do |content|
file = params[:path] ? File.join(params[:path], content.name) : content.name file = params[:path] ? File.join(params[:path], content.name) : content.name
last_commit = @project.commits(@commit.id, file, 1).last last_commit = @project.commits(@commit.id, file, 1).last
last_commit = CommitDecorator.decorate(last_commit)
{ {
:file_name => content.name, :file_name => content.name,
:commit => last_commit :commit => last_commit

View file

@ -1,6 +1,10 @@
class CommitDecorator < ApplicationDecorator class CommitDecorator < ApplicationDecorator
decorates :commit decorates :commit
def short_id(length = 10)
id.to_s[0..length]
end
# Returns the commits title. # Returns the commits title.
# #
# Usually, the commit title is the first line of the commit message. # Usually, the commit title is the first line of the commit message.

View file

@ -4,11 +4,11 @@
%strong= link_to "Browse Code »", tree_project_ref_path(@project, commit.id), :class => "right" %strong= link_to "Browse Code »", tree_project_ref_path(@project, commit.id), :class => "right"
= link_to project_commit_path(@project, :id => commit.id) do = link_to project_commit_path(@project, :id => commit.id) do
%p %p
%code.left= commit.id.to_s[0..10] %code.left= commit.short_id
%strong.cgray= commit.author_name %strong.cgray= commit.author_name
&ndash; &ndash;
= image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16
%span.row_title= truncate(commit.safe_message, :length => 50) %span.row_title= truncate(commit.title, :length => 50)
%span.committed_ago %span.committed_ago
= time_ago_in_words(commit.committed_date) = time_ago_in_words(commit.committed_date)

View file

@ -10,14 +10,14 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear
xml.entry do xml.entry do
xml.id project_commit_url(@project, :id => commit.id) xml.id project_commit_url(@project, :id => commit.id)
xml.link :href => project_commit_url(@project, :id => commit.id) xml.link :href => project_commit_url(@project, :id => commit.id)
xml.title truncate(commit.safe_message, :length => 80) xml.title truncate(commit.title, :length => 80)
xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ") xml.updated commit.committed_date.strftime("%Y-%m-%dT%H:%M:%SZ")
xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email) xml.media :thumbnail, :width => "40", :height => "40", :url => gravatar_icon(commit.author_email)
xml.author do |author| xml.author do |author|
xml.name commit.author_name xml.name commit.author_name
xml.email commit.author_email xml.email commit.author_email
end end
xml.summary commit.safe_message xml.summary commit.description
end end
end end
end end

View file

@ -1,9 +1,10 @@
- commit = CommitDecorator.decorate(commit)
%li.wll.commit %li.wll.commit
= link_to project_commit_path(project, :id => commit.id) do = link_to project_commit_path(project, :id => commit.id) do
%p %p
%code.left= commit.id.to_s[0..10] %code.left= commit.short_id
%strong.cgray= commit.author_name %strong.cgray= commit.author_name
&ndash; &ndash;
= image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16 = image_tag gravatar_icon(commit.author_email), :class => "avatar", :width => 16
%span.row_title= truncate(commit.safe_message, :length => 50) rescue "--broken encoding" %span.row_title= truncate(commit.title, :length => 50) rescue "--broken encoding"

View file

@ -1,3 +1,3 @@
- if tm - if tm
%strong= link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) %strong= link_to "[#{tm.user_name}]", project_team_member_path(@project, tm)
= link_to truncate(content_commit.safe_message, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link" = link_to truncate(content_commit.title, :length => tm ? 30 : 50), project_commit_path(@project, content_commit.id), :class => "tree-commit-link"

View file

@ -25,6 +25,7 @@
%table %table
- @blame.each do |commit, lines| - @blame.each do |commit, lines|
- commit = Commit.new(commit) - commit = Commit.new(commit)
- commit = CommitDecorator.decorate(commit)
%tr %tr
%td.author %td.author
= image_tag gravatar_icon(commit.author_email, 16) = image_tag gravatar_icon(commit.author_email, 16)
@ -32,8 +33,8 @@
%td.blame_commit %td.blame_commit
&nbsp; &nbsp;
= link_to project_commit_path(@project, :id => commit.id) do = link_to project_commit_path(@project, :id => commit.id) do
%code= commit.id.to_s[0..10] %code= commit.short_id
%span.row_title= truncate(commit.safe_message, :length => 30) rescue "--broken encoding" %span.row_title= truncate(commit.title, :length => 30) rescue "--broken encoding"
%td.lines %td.lines
= preserve do = preserve do
%pre %pre

View file

@ -1,3 +1,5 @@
- commit = Commit.new(branch.commit)
- commit = CommitDecorator.decorate(commit)
%tr %tr
%td %td
= link_to project_commits_path(@project, :ref => branch.name) do = link_to project_commits_path(@project, :ref => branch.name) do
@ -5,14 +7,14 @@
- if branch.name == @project.root_ref - if branch.name == @project.root_ref
%span.label default %span.label default
%td %td
= link_to project_commit_path(@project, :id => branch.commit.id) do = link_to project_commit_path(@project, :id => commit.id) do
%code= branch.commit.id.to_s[0..10] %code= commit.short_id
= image_tag gravatar_icon(Commit.new(branch.commit).author_email), :class => "", :width => 16 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
= truncate(Commit.new(branch.commit).safe_message, :length => 40) = truncate(commit.title, :length => 40)
%td %td
%span.update-author.right %span.update-author.right
= time_ago_in_words(branch.commit.committed_date) = time_ago_in_words(commit.committed_date)
ago ago
%td %td
- if can? current_user, :download_code, @project - if can? current_user, :download_code, @project

View file

@ -1,4 +1,5 @@
- commit = update - commit = update
- commit = CommitDecorator.new(commit)
%tr %tr
%td %td
= link_to project_commits_path(@project, :ref => commit.head.name) do = link_to project_commits_path(@project, :ref => commit.head.name) do
@ -10,9 +11,9 @@
%td %td
%div %div
= link_to project_commits_path(@project, commit.id) do = link_to project_commits_path(@project, commit.id) do
%code= commit.id.to_s[0..10] %code= commit.short_id
= image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
= truncate(commit.safe_message, :length => 40) = truncate(commit.title, :length => 40)
%td %td
%span.right.cgray %span.right.cgray
= time_ago_in_words(commit.committed_date) = time_ago_in_words(commit.committed_date)

View file

@ -9,14 +9,15 @@
%th %th
- @tags.each do |tag| - @tags.each do |tag|
- commit = Commit.new(tag.commit) - commit = Commit.new(tag.commit)
- commit = CommitDecorator.decorate(commit)
%tr %tr
%td %td
%strong= link_to tag.name, project_commits_path(@project, :ref => tag.name), :class => "" %strong= link_to tag.name, project_commits_path(@project, :ref => tag.name), :class => ""
%td %td
= link_to project_commit_path(@project, commit.id) do = link_to project_commit_path(@project, commit.id) do
%code= commit.id.to_s[0..10] %code= commit.short_id
= image_tag gravatar_icon(commit.author_email), :class => "", :width => 16 = image_tag gravatar_icon(commit.author_email), :class => "", :width => 16
= truncate(commit.safe_message, :length => 40) = truncate(commit.title, :length => 40)
%td %td
%span.update-author.right %span.update-author.right
= time_ago_in_words(commit.committed_date) = time_ago_in_words(commit.committed_date)

View file

@ -2,7 +2,7 @@ require 'spec_helper'
describe "Commits" do describe "Commits" do
let(:project) { Factory :project } let(:project) { Factory :project }
let!(:commit) { project.commit } let!(:commit) { CommitDecorator.decorate(project.commit) }
before do before do
login_as :user login_as :user
project.add_access(@user, :read) project.add_access(@user, :read)
@ -22,8 +22,8 @@ describe "Commits" do
end end
it "should list commits" do it "should list commits" do
page.should have_content(commit.message) page.should have_content(commit.description)
page.should have_content(commit.id.to_s[0..5]) page.should have_content(commit.short_id)
end end
it "should render atom feed" do it "should render atom feed" do
@ -32,7 +32,7 @@ describe "Commits" do
page.response_headers['Content-Type'].should have_content("application/atom+xml") page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", :text => "Recent commits to #{project.name}") page.body.should have_selector("title", :text => "Recent commits to #{project.name}")
page.body.should have_selector("author email", :text => commit.author_email) page.body.should have_selector("author email", :text => commit.author_email)
page.body.should have_selector("entry summary", :text => commit.message) page.body.should have_selector("entry summary", :text => commit.description)
end end
it "should render atom feed via private token" do it "should render atom feed via private token" do
@ -42,7 +42,7 @@ describe "Commits" do
page.response_headers['Content-Type'].should have_content("application/atom+xml") page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", :text => "Recent commits to #{project.name}") page.body.should have_selector("title", :text => "Recent commits to #{project.name}")
page.body.should have_selector("author email", :text => commit.author_email) page.body.should have_selector("author email", :text => commit.author_email)
page.body.should have_selector("entry summary", :text => commit.message) page.body.should have_selector("entry summary", :text => commit.description)
end end
end end