rosa-build/app/helpers/commit_helper.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2011-03-10 13:33:50 +00:00
module CommitHelper
def render_commit_stats(stats)
res = ["<table class='commit_stats'>"]
ind=0
2011-03-10 13:33:50 +00:00
stats.files.each do |filename, adds, deletes, total|
res << "<tr>"
res << "<td><a href='#diff-#{ind}'>#{h(filename.rtruncate 120)}</a></td>"
res << "<td class='diffstat'>"
2014-01-21 04:51:49 +00:00
res << I18n.t("layout.projects.inline_changes_count", count: total).strip +
" (" +
2014-01-21 04:51:49 +00:00
I18n.t("layout.projects.inline_additions_count", count: adds).strip +
", " +
2014-01-21 04:51:49 +00:00
I18n.t("layout.projects.inline_deletions_count", count: deletes).strip +
")"
res << "</td>"
ind +=1
2011-03-10 13:33:50 +00:00
end
res << "</table>"
2011-03-10 13:33:50 +00:00
2014-01-15 19:34:54 +00:00
res.join("\n").html_safe
2011-03-10 13:33:50 +00:00
end
# 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)
2014-01-21 04:51:49 +00:00
I18n.localize(date, { format: "%d %B %Y" })
2011-03-10 13:33:50 +00:00
end
2011-04-01 01:36:34 +01:00
def short_hash_id(id)
id[0..19]
end
def shortest_hash_id(id, size=10)
id[0..size-1]
2011-04-04 12:28:33 +01:00
end
2012-03-05 15:29:05 +00:00
def commit_author_link(author)
name = author.name
2012-03-05 15:29:05 +00:00
email = author.email
2014-01-21 04:51:49 +00:00
u = User.where(email: email).first
2012-03-05 15:29:05 +00:00
u.present? ? link_to(name, user_path(u)) : mail_to(email, name)
end
2013-09-08 12:56:43 +01:00
def commits_pluralize(commits_count)
Russian.p(commits_count, *commits_pluralization_arr)
end
protected
def commits_pluralization_arr
pluralize ||= t('layout.commits.pluralize').map {|base, title| title.to_s}
end
2012-01-30 20:39:34 +00:00
end