From 5d4ca333dae067f455688663f23e6f2f17a90358 Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Thu, 10 Mar 2011 16:33:50 +0300 Subject: [PATCH] commit and diff helpers --- app/helpers/commit_helper.rb | 25 +++++++++++++++++++++++++ app/helpers/diff_helper.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 app/helpers/commit_helper.rb create mode 100644 app/helpers/diff_helper.rb diff --git a/app/helpers/commit_helper.rb b/app/helpers/commit_helper.rb new file mode 100644 index 000000000..10bb80a09 --- /dev/null +++ b/app/helpers/commit_helper.rb @@ -0,0 +1,25 @@ +module CommitHelper + + def render_commit_stats(stats) + res = ["" + + res.join("\n") + end + + def format_commit_message(message) + h(message).gsub("\n", "
") + end + + def commit_date(date) + I18n.localize(date, { :format => "%d %B %Y" }) + end + +end \ No newline at end of file diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb new file mode 100644 index 000000000..f6b9a9c8f --- /dev/null +++ b/app/helpers/diff_helper.rb @@ -0,0 +1,36 @@ +module DiffHelper + def render_inline_diff(commit, diff) + [render_inline_diff_header(commit, diff), render_inline_diff_body(diff.diff), render_inline_diff_footer].join("\n") + end + + def render_inline_diff_header(commit, diff) + res = "" + if diff.b_path.present? + res += link_to("view file @ #{commit.id}", blob_commit_path(@platform.name, @project.name, commit.id, diff.b_path)) + res += "
" + end + + res += " + + + + + + + + " + + res + end + + def render_inline_diff_body(diff) + diff_display ||= Diff::Display::Unified.new(diff) + " + #{diff_display.render(Git::Diff::InlineCallback.new)} + " + end + + def render_inline_diff_footer + "
  
" + end +end \ No newline at end of file