diff --git a/progit/__init__.py b/progit/__init__.py index f45e2be..328abe4 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -35,6 +35,9 @@ import progit.doc_utils import progit.login_forms import markdown +from pygments import highlight +from pygments.lexers.text import DiffLexer +from pygments.formatters import HtmlFormatter # Create the application. APP = flask.Flask(__name__) @@ -369,6 +372,30 @@ def markdown_filter(text): return '' +@APP.template_filter('html_diff') +def html_diff(diff): + """Display diff as HTML""" + return highlight( + diff, + DiffLexer(), + HtmlFormatter( + noclasses=True, + style="tango",) + ) + + +@APP.template_filter('patch_to_diff') +def patch_to_diff(patch): + """Render a hunk as a diff""" + content = "" + for hunk in patch.hunks: + content = content + "@@ -%i,%i +%i,%i @@\n" % (hunk.old_start, + hunk.old_lines, hunk.new_start, hunk.new_lines) + for line in hunk.lines: + content = content + ' '.join(line) + return content + + @FAS.postlogin def set_user(return_url): ''' After login method. ''' diff --git a/progit/static/progit.css b/progit/static/progit.css index 1c8568c..0885fe9 100644 --- a/progit/static/progit.css +++ b/progit/static/progit.css @@ -14,6 +14,10 @@ textarea { background: rgba(255, 255, 255, 0.5); } +td, th { + padding: .1em .2em; +} + .message { color: green; } @@ -435,7 +439,8 @@ table.list .open_by { .issue_comment > header, .issue_comment > form > header, -.file_content > header +.file_content > header, +.commit_diff > header { border-radius: 10px 10px 0 0; padding: .5em; @@ -482,17 +487,22 @@ table.list .open_by { padding: .5em; } +.header .buttons, header .buttons { + display: inline-block; + float: right; list-style-type: none; text-align: right; margin: 0; } +.header .buttons li, header .buttons li { display: inline-block; padding-left: .5em; } +.header .button, header .button { display: inline-block; color: white; @@ -509,16 +519,20 @@ header .button { box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2); } +.header .button:hover, header .button:hover { background-image: linear-gradient(to bottom, #34609f, #0066cc); } +.header a.button:visited, +.header a.button:hover, header a.button:visited, header a.button:hover { color: white; } -.file_content { +.file_content, +.commit_diff { border: 1px solid rgba(237, 237, 237, 0.4); border-radius: 10px 10px 0 0; } @@ -593,3 +607,42 @@ a.user_settings { #profile_button { display: inline-block; } + +.header > h3, +.commit_diff > header h3 { + display: inline-block; + margin: .4em 0 0; +} + +.commit_message_body { + display: block; + font-weight: normal; + font-size: .9em; +} + +.commit_diff { + margin-top: 2em; +} + +.addrem_bar { + display: inline-block; + width: 100px; + padding: 0!important; + text-align: left; + background-color: #ffdddd; +} + +.addrem_bar > span { + display: block; + background-color: #dbffdb; +} + +ul.changes { + margin: 0; + list-style-type: none; + padding: 0; +} + +.header { + padding: .5em 0; +} diff --git a/progit/templates/commit.html b/progit/templates/commit.html index 9060f2b..a70fe98 100644 --- a/progit/templates/commit.html +++ b/progit/templates/commit.html @@ -1,34 +1,55 @@ {% extends "repo_master.html" %} {% block title %}Commit - {{ repo.name }} - {{ commitid }}{% endblock %} -{%block tag %}home{% endblock %} +{%block tag %}commit{% endblock %} {% block repo %} +{% set splitted_message = commit.message.split('\n') %} +
| Author | +Author | {{ commit.author.name }} {{ '<' + commit.author.email + '>' }} - {{ commit.commit_time | format_ts}} |
|---|---|---|
| Committer | +Committer | {{ commit.committer.name }} {{ '<' + commit.committer.email + '>' }} - {{ commit.commit_time | format_ts }} |
| Parent | +Parent |
{% for parent in commit.parents %}
+ {% for patch in diff %}
+ |
+
Binary diffs cannot be rendered.
+ {% else %} + {% autoescape false %} + {{ patch|patch_to_diff|html_diff}} + {% endautoescape %} + {% endif %}