2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 13:33:50 +00:00
|
|
|
module CommitHelper
|
|
|
|
|
|
|
|
def render_commit_stats(stats)
|
2011-04-01 04:44:21 +01:00
|
|
|
res = ["<table class='commit_stats'>"]
|
2012-06-07 20:20:06 +01:00
|
|
|
ind=0
|
2011-03-10 13:33:50 +00:00
|
|
|
stats.files.each do |filename, adds, deletes, total|
|
2011-04-01 04:44:21 +01:00
|
|
|
res << "<tr>"
|
2012-06-08 08:38:24 +01:00
|
|
|
res << "<td><a href='#diff-#{ind}'>#{h(filename.rtruncate 120)}</a></td>"
|
2012-02-29 01:30:22 +00:00
|
|
|
res << "<td class='diffstat'>"
|
|
|
|
res << I18n.t("layout.projects.inline_changes_count", :count => total).strip +
|
|
|
|
" (" +
|
|
|
|
I18n.t("layout.projects.inline_additions_count", :count => adds).strip +
|
|
|
|
", " +
|
|
|
|
I18n.t("layout.projects.inline_deletions_count", :count => deletes).strip +
|
|
|
|
")"
|
|
|
|
res << "</td>"
|
2012-06-07 20:20:06 +01:00
|
|
|
ind +=1
|
2011-03-10 13:33:50 +00:00
|
|
|
end
|
2011-04-01 04:44:21 +01:00
|
|
|
res << "</table>"
|
2011-03-10 13:33:50 +00:00
|
|
|
|
2012-03-21 19:55:14 +00:00
|
|
|
res.join("\n").html_safe.default_encoding!
|
2011-03-10 13:33:50 +00:00
|
|
|
end
|
|
|
|
|
2011-04-01 04:44:21 +01:00
|
|
|
# def format_commit_message(message)
|
|
|
|
# h(message).gsub("\n", "<br />").html_safe
|
|
|
|
# end
|
2011-03-10 13:33:50 +00:00
|
|
|
|
|
|
|
def commit_date(date)
|
|
|
|
I18n.localize(date, { :format => "%d %B %Y" })
|
|
|
|
end
|
|
|
|
|
2011-04-01 01:36:34 +01:00
|
|
|
def short_hash_id(id)
|
|
|
|
id[0..19]
|
|
|
|
end
|
|
|
|
|
2012-12-03 18:04:03 +00:00
|
|
|
def shortest_hash_id(id, size=10)
|
|
|
|
id[0..size-1]
|
2011-04-04 12:28:33 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def short_commit_message(message)
|
|
|
|
# Why 42? Because it is the Answer!
|
2012-03-21 19:55:14 +00:00
|
|
|
truncate(message, :length => 42, :omission => "...")
|
2011-04-04 12:28:33 +01:00
|
|
|
end
|
|
|
|
|
2012-03-05 15:29:05 +00:00
|
|
|
def commit_author_link(author)
|
2012-03-21 19:55:14 +00:00
|
|
|
name = author.name
|
2012-03-05 15:29:05 +00:00
|
|
|
email = author.email
|
|
|
|
u = User.where(:email => email).first
|
|
|
|
u.present? ? link_to(name, user_path(u)) : mail_to(email, name)
|
|
|
|
end
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|