2012-02-29 01:30:22 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-02-18 22:47:57 +00:00
|
|
|
class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter
|
2012-02-29 01:30:22 +00:00
|
|
|
include CommitHelper
|
|
|
|
|
2012-02-18 22:47:57 +00:00
|
|
|
attr_accessor :commit, :options
|
|
|
|
attr_reader :header, :image, :date, :caption, :content, :expandable
|
|
|
|
|
|
|
|
def initialize(commit, opts = {})
|
|
|
|
@commit = commit
|
2012-11-28 13:15:15 +00:00
|
|
|
@options = opts
|
2012-02-18 22:47:57 +00:00
|
|
|
prepare_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
2012-11-28 13:15:15 +00:00
|
|
|
@header ||= if options[:project].present?
|
2012-02-29 15:08:21 +00:00
|
|
|
I18n.t("layout.messages.commits.header",
|
2012-02-29 01:30:22 +00:00
|
|
|
:committer => committer_link, :commit => commit_link, :project => options[:project].name)
|
2012-02-18 22:47:57 +00:00
|
|
|
end.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
2012-03-21 21:51:39 +00:00
|
|
|
c = committer
|
|
|
|
@image ||= if c.class == User
|
|
|
|
helpers.avatar_url(c, :medium)
|
|
|
|
else
|
2012-03-21 22:06:33 +00:00
|
|
|
helpers.avatar_url_by_email(c.email, :medium)
|
2012-03-21 21:51:39 +00:00
|
|
|
end
|
2012-02-18 22:47:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def date
|
|
|
|
@date ||= I18n.l(@commit.committed_date || @commit.authored_date, :format => :long)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expandable?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-02-29 15:04:33 +00:00
|
|
|
def buttons?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-02-18 22:47:57 +00:00
|
|
|
def content?
|
|
|
|
!content.blank?
|
|
|
|
end
|
|
|
|
|
2012-03-01 20:33:48 +00:00
|
|
|
def caption?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-03-13 18:47:37 +00:00
|
|
|
def comment_id?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2012-02-18 22:47:57 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def committer
|
|
|
|
@committer ||= User.where(:email => @commit.committer.email).first || @commit.committer
|
|
|
|
end
|
|
|
|
|
|
|
|
def committer_link
|
|
|
|
@committer_link ||= if committer.is_a? User
|
2012-02-29 01:30:22 +00:00
|
|
|
link_to committer.uname, user_path(committer)
|
2012-02-18 22:47:57 +00:00
|
|
|
else
|
2012-03-21 19:55:14 +00:00
|
|
|
mail_to committer.email, committer.name
|
2012-02-18 22:47:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-29 01:30:22 +00:00
|
|
|
def commit_link
|
|
|
|
link_to shortest_hash_id(@commit.id), commit_path(options[:project], @commit.id)
|
|
|
|
end
|
|
|
|
|
2012-02-18 22:47:57 +00:00
|
|
|
def prepare_message
|
2012-03-21 19:55:14 +00:00
|
|
|
(@caption, @content) = @commit.message.split("\n\n", 2)
|
2012-02-27 17:40:46 +00:00
|
|
|
@caption = 'empty message' unless @caption.present?
|
2012-02-18 22:47:57 +00:00
|
|
|
if @caption.length > 72
|
2012-02-27 17:40:46 +00:00
|
|
|
tmp = '...' + @caption[69..-1]
|
|
|
|
@content = (@content.present?) ? tmp + @content : tmp
|
2012-02-18 22:47:57 +00:00
|
|
|
@caption = @caption[0..68] + '...'
|
|
|
|
end
|
2012-03-01 01:07:31 +00:00
|
|
|
# @content = @content.gsub("\n", "<br />").html_safe if @content
|
|
|
|
@content = simple_format(@content, {}, :sanitize => true).html_safe if @content
|
2012-02-18 22:47:57 +00:00
|
|
|
end
|
|
|
|
end
|