Only use monospace fonts in diff table if so specified

This commit is contained in:
Lance Edgar 2017-08-07 23:22:47 -05:00
parent 2714d3c03c
commit 3fcc105b78
3 changed files with 5 additions and 4 deletions

View file

@ -35,12 +35,13 @@ class Diff(object):
Core diff class. In sore need of documentation. Core diff class. In sore need of documentation.
""" """
def __init__(self, old_data, new_data, columns=None, fields=None, render_value=None): def __init__(self, old_data, new_data, columns=None, fields=None, render_value=None, monospace=False):
self.old_data = old_data self.old_data = old_data
self.new_data = new_data self.new_data = new_data
self.columns = columns or ["field name", "old value", "new value"] self.columns = columns or ["field name", "old value", "new value"]
self.fields = fields or self.make_fields() self.fields = fields or self.make_fields()
self.render_value = render_value or self.render_value_default self.render_value = render_value or self.render_value_default
self.monospace = monospace
def make_fields(self): def make_fields(self):
return sorted(set(self.old_data) | set(self.new_data), key=lambda x: x.lower()) return sorted(set(self.old_data) | set(self.new_data), key=lambda x: x.lower())

View file

@ -16,8 +16,8 @@ table.diff td {
padding: 2px 5px; padding: 2px 5px;
} }
table.diff td.old-value, table.diff.monospace td.old-value,
table.diff td.new-value{ table.diff.monospace td.new-value{
font-family: monospace; font-family: monospace;
white-space: pre; white-space: pre;
} }

View file

@ -1,5 +1,5 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<table class="diff"> <table class="diff${' monospace' if diff.monospace else ''}">
<thead> <thead>
<tr> <tr>
% for column in diff.columns: % for column in diff.columns: