summaryrefslogtreecommitdiff
path: root/pywal/export.py
diff options
context:
space:
mode:
authordylan <dylan.araps@gmail.com>2020-05-04 21:40:17 +0300
committerGitHub <noreply@github.com>2020-05-04 21:40:17 +0300
commita2ddff38fdd16f6e16e7be82a433ed022a3c8a8b (patch)
tree9dccf6f887f6e2c6ccb089fc620a92c52abf8024 /pywal/export.py
parented9339c310e14f7886ecfb3fe41f2ca1d6762aec (diff)
parentcecc28cc5288fb80a178e456cf2e93d77f5dbd71 (diff)
Merge pull request #485 from loiccoyle/master
fix template issue
Diffstat (limited to 'pywal/export.py')
-rw-r--r--pywal/export.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/pywal/export.py b/pywal/export.py
index 0c71a76..928fbc3 100644
--- a/pywal/export.py
+++ b/pywal/export.py
@@ -12,6 +12,7 @@ from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR
def template(colors, input_file, output_file=None):
"""Read template file, substitute markers and
save the file elsewhere."""
+ # pylint: disable-msg=too-many-locals
template_data = util.read_file_raw(input_file)
for i, l in enumerate(template_data):
for match in re.finditer(r"(?<=(?<!\{))(\{([^{}]+)\})(?=(?!\}))", l):
@@ -25,7 +26,7 @@ def template(colors, input_file, output_file=None):
# Color to be modified copied into new one
new_color = util.Color(colors[cname].hex_color)
# Execute each function to be done
- for func in filter(None, funcs.split(")")):
+ for func in filter(None, re.split(r"\)|\.", funcs)):
# Get function name and arguments
func = func.split("(")
fname = func[0]
@@ -47,11 +48,19 @@ def template(colors, input_file, output_file=None):
if func[0] != '.':
replace_str += "."
replace_str += "(".join(func) + ")"
+ else:
+ # if it is an attribute i.e. rgb
+ replace_str += '.' + fname
+ new_color = function
+
+ if isinstance(new_color, util.Color):
+ new_color = new_color.strip
# If the color was changed, replace with a unique identifier.
if new_color is not colors[cname]:
- template_data[i] = l.replace(
- replace_str, "color" + new_color.strip)
- colors["color" + new_color.strip] = new_color
+ new_color_clean = new_color.replace('[', '_').replace(']', '_')
+ template_data[i] = l.replace(replace_str,
+ "color" + new_color_clean)
+ colors["color" + new_color_clean] = new_color
try:
template_data = "".join(template_data).format(**colors)
except ValueError: