Skip to content

Commit

Permalink
even/odd and tag-based class names for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Jul 8, 2013
1 parent 4845d9d commit ec56b70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mailpile/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class Search(Command):
class CommandResult(Command.CommandResult):
def as_text(self):
return self.result.as_text()
def as_html(self):
for msg in self.result['messages']:
msg['tag_classes'] = ' '.join(['tid_%s' % t for t in msg['tag_ids']] +
['t_%s' % t.lower() for t in msg['tags']])
return Command.CommandResult.as_html(self)

SYNOPSIS = '<terms ...>'
def command(self, search=None):
Expand Down
5 changes: 4 additions & 1 deletion mailpile/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, log_parent=None):
'title': 'Mailpile',
'name': 'Bradley Manning',
'csrf': '',
'even_odd': 'odd'
}

# Logging
Expand Down Expand Up @@ -185,8 +186,10 @@ def render_html(self, cfg, tpl_name, data):
elif (isinstance(data, list)
or isinstance(data, tuple)
or isinstance(data, set)):
html = []
eo, html = 0, []
for item in data:
eo += 1
self.html_variables['even_odd'] = ((eo%2)==0) and 'even' or 'odd'
html.append(self.render_html(cfg, tpl_name, item))
return ' '.join(html)
else:
Expand Down
2 changes: 1 addition & 1 deletion static/default/html/search-result-messages.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="result odd t_inbox t_sent" data-state="normal">
<tr class="result %(even_odd)s %(tag_classes)s" data-state="normal">
<td class="from"><a href="%(url)s">%(from)s</a></td>
<td class="subject"><a href="%(url)s">%(subject)s</a></td>
<td class="date"><a href="/_/search/dates:%(date)s">%(date)s</a></td>
Expand Down

0 comments on commit ec56b70

Please sign in to comment.