Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a2ddff3

Browse files
authored
Merge pull request #485 from loiccoyle/master
fix template issue
2 parents ed9339c + cecc28c commit a2ddff3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pywal/export.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def template(colors, input_file, output_file=None):
1313
"""Read template file, substitute markers and
1414
save the file elsewhere."""
15+
# pylint: disable-msg=too-many-locals
1516
template_data = util.read_file_raw(input_file)
1617
for i, l in enumerate(template_data):
1718
for match in re.finditer(r"(?<=(?<!\{))(\{([^{}]+)\})(?=(?!\}))", l):
@@ -25,7 +26,7 @@ def template(colors, input_file, output_file=None):
2526
# Color to be modified copied into new one
2627
new_color = util.Color(colors[cname].hex_color)
2728
# Execute each function to be done
28-
for func in filter(None, funcs.split(")")):
29+
for func in filter(None, re.split(r"\)|\.", funcs)):
2930
# Get function name and arguments
3031
func = func.split("(")
3132
fname = func[0]
@@ -47,11 +48,19 @@ def template(colors, input_file, output_file=None):
4748
if func[0] != '.':
4849
replace_str += "."
4950
replace_str += "(".join(func) + ")"
51+
else:
52+
# if it is an attribute i.e. rgb
53+
replace_str += '.' + fname
54+
new_color = function
55+
56+
if isinstance(new_color, util.Color):
57+
new_color = new_color.strip
5058
# If the color was changed, replace with a unique identifier.
5159
if new_color is not colors[cname]:
52-
template_data[i] = l.replace(
53-
replace_str, "color" + new_color.strip)
54-
colors["color" + new_color.strip] = new_color
60+
new_color_clean = new_color.replace('[', '_').replace(']', '_')
61+
template_data[i] = l.replace(replace_str,
62+
"color" + new_color_clean)
63+
colors["color" + new_color_clean] = new_color
5564
try:
5665
template_data = "".join(template_data).format(**colors)
5766
except ValueError:

0 commit comments

Comments
 (0)