require "digest/md5" module Ginatra # Actually useful stuff module Helpers def gravatar_url(email) "https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=40" end def nicetime(date) date.strftime("%b %d, %Y – %H:%M") end def actor_box(actor, role, date) partial(:actor_box, :locals => { :actor => actor, :role => role, :date => date }) end def actor_boxes(commit) o = actor_box(commit.committer, :committer, commit.committed_date) if commit.author.name != commit.committer.name o = actor_box(commit.author, :author, commit.authored_date) + o end end def commit_ref(ref, repo_param) ref_class = ref.class.to_s.split("::")[1].to_s "#{ref.name}" end def commit_refs(commit, repo_param) commit.refs.map{ |r| commit_ref(r, repo_param) }.join("\n") end def archive_link(tree, repo_param) "Download Archive" end def patch_link(commit, repo_param) "Download Patch" end # The only reason this doesn't work 100% of the time is because grit doesn't :/ # if i find a fix, it'll go upstream :D def file_listing(commit) count = 0 out = commit.diffs.map do |diff| count = count + 1 if diff.deleted_file %(
tags without any options
# modified since
def simple_format(text)
text.gsub!(/ +/, " ")
text.gsub!(/\r\n?/, "\n")
text.gsub!(/\n/, "
\n")
text
end
# stolen from rails: ERB::Util
def html_escape(s)
s.to_s.gsub(/[&"<>]/) do |special|
{ '&' => '&',
'>' => '>',
'<' => '<',
'"' => '"' }[special]
end
end
alias :h :html_escape
# Stolen and bastardised from rails
def truncate(text, options={})
options[:length] ||= 30
options[:omission] ||= "..."
if text
l = options[:length] - options[:omission].length
chars = text
stop = options[:separator] ? (chars.rindex(options[:separator], l) || l) : l
(chars.length > options[:length] ? chars[0...stop] + options[:omission] : text).to_s
end
end
# stolen from Marley
def rfc_date(datetime)
datetime.strftime("%Y-%m-%dT%H:%M:%SZ") # 2003-12-13T18:30:02Z
end
# stolen from Marley
def hostname
(request.env['HTTP_X_FORWARDED_SERVER'] =~ /[a-z]*/) ? request.env['HTTP_X_FORWARDED_SERVER'] : request.env['HTTP_HOST']
end
def atom_feed_link(repo_param, ref=nil)
"Feed"
end
end
end