diff options
author | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-01-03 23:05:04 +0000 |
---|---|---|
committer | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-01-03 23:05:04 +0000 |
commit | d3421eb75792b0a77d521c5c5ce14035f6496a5e (patch) | |
tree | f0213fcb144168790c542e67ce7ad8c3d58ffada /src | |
parent | 80d3a9d0e9a172cfd40fb4e043901941d3862b88 (diff) | |
download | bcfg2-d3421eb75792b0a77d521c5c5ce14035f6496a5e.tar.gz bcfg2-d3421eb75792b0a77d521c5c5ce14035f6496a5e.tar.bz2 bcfg2-d3421eb75792b0a77d521c5c5ce14035f6496a5e.zip |
Added syntax coloring for Diffs! Woo. Requires Pygments be installed:
http://pygments.pocoo.org
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2620 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Reports/reports/templates/config_items/index.html | 5 | ||||
-rw-r--r-- | src/lib/Server/Reports/reports/templatetags/syntax_coloring.py | 25 |
2 files changed, 29 insertions, 1 deletions
diff --git a/src/lib/Server/Reports/reports/templates/config_items/index.html b/src/lib/Server/Reports/reports/templates/config_items/index.html index 952172715..b6e4957a4 100644 --- a/src/lib/Server/Reports/reports/templates/config_items/index.html +++ b/src/lib/Server/Reports/reports/templates/config_items/index.html @@ -1,6 +1,9 @@ +{% load syntax_coloring %} + {% extends "base.html" %} {% block extra_header_info %} +<link rel="stylesheet" type="text/css" href="/site_media/syntax-coloring.css" /> <script type="text/javascript" src="/site_media/CalendarPopup.js"></script> <script language="JavaScript">var cal = new CalendarPopup();</script> {% endblock%} @@ -41,7 +44,7 @@ {% endif %}{% if not item.reason.current_exists %} <tr><td align="right"><b>Existance: </b></td><td colspan=2>This item does not currently exist on the host but is specified to exist in the configuration.</td></tr> {% endif %}{% if item.reason.current_diff %} -<tr><td align="right"><b>Unified Diff: </b></td><td colspan=2><pre>{{item.reason.current_diff}}</pre></td></tr> +<tr><td align="right"><b>Unified Diff: </b></td><td colspan=2><pre>{{item.reason.current_diff|syntaxhilight:"diff"}}</pre></td></tr> {% endif %} </table></center> <hr/> diff --git a/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py new file mode 100644 index 000000000..14827b3c6 --- /dev/null +++ b/src/lib/Server/Reports/reports/templatetags/syntax_coloring.py @@ -0,0 +1,25 @@ +from django import template + +try: + from pygments import highlight + from pygments.lexers import get_lexer_by_name + from pygments.formatters import HtmlFormatter + colorize = True +except: + colorize = False + +register = template.Library() + +def syntaxhilight(value, arg="diff"): + '''Returns a syntax-hilighted version of Code; requires code and language arguments''' + lexer = get_lexer_by_name(arg) + if colorize: + try: + return highlight(value, lexer, HtmlFormatter()) + except: + return value + else: + return value + + +register.filter('syntaxhilight', syntaxhilight) |