-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
CB-448: Implemented new footer design
- Loading branch information
Showing
6 changed files
with
232 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
import html | ||
import re | ||
|
||
|
||
def encode_entities(string, quote=True): | ||
return html.escape(string, quote).encode('ascii', 'xmlcharrefreplace').decode('utf8') | ||
|
||
|
||
def expand(string, args, tag='a', default_attribute='href'): | ||
|
||
def make_link(match): | ||
var = match.group(1) | ||
text = match.group(2) | ||
if text in args.keys(): | ||
final_text = args[text] | ||
else: | ||
final_text = text | ||
|
||
if isinstance(args[var], dict): | ||
d = args[var] | ||
else: | ||
if default_attribute: | ||
d = {default_attribute: args[var]} | ||
else: | ||
d = {} | ||
attribs = ' '.join(["%s=\"%s\"" % (k, encode_entities(d[k])) for k | ||
in sorted(d.keys())]) | ||
if attribs: | ||
attribs = ' ' + attribs | ||
return '<%s%s>%s</%s>' % (tag, attribs, final_text, tag) | ||
|
||
def simple_expr(match): | ||
var = match.group(1) | ||
if var in args.keys(): | ||
return args[var] | ||
return '{' + var + '}' | ||
|
||
r = '|'.join([re.escape(k) for k in args.keys()]) | ||
|
||
r1 = re.compile('\{(' + r + ')\|(.*?)\}', re.UNICODE) | ||
r2 = re.compile('\{(' + r + ')\}', re.UNICODE) | ||
|
||
string = r1.sub(make_link, string) | ||
string = r2.sub(simple_expr, string) | ||
|
||
return string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.