From 6f1e81b038f0029c1ec3408e7a50f78bf9dd4f53 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 28 May 2022 19:12:46 -0700 Subject: [PATCH] Updated join so join() works correctly, #706 --- osxphotos/phototemplate.md | 2 +- osxphotos/phototemplate.py | 8 +++++--- tests/test_template.py | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osxphotos/phototemplate.md b/osxphotos/phototemplate.md index 185118b9..b6f7f1f5 100644 --- a/osxphotos/phototemplate.md +++ b/osxphotos/phototemplate.md @@ -51,7 +51,7 @@ Valid filters are: - `rsort`: Sort list of values in reverse order, e.g. ['a', 'b', 'c'] => ['c', 'b', 'a']. - `reverse`: Reverse order of values, e.g. ['a', 'b', 'c'] => ['c', 'b', 'a']. - `uniq`: Remove duplicate values, e.g. ['a', 'b', 'c', 'b', 'a'] => ['a', 'b', 'c']. -- `join(x)`: Join list of values with delimiter x, e.g. join(:): ['a', 'b', 'c'] => 'a:b:c'; the DELIM option functions similar to join(x) but with DELIM, the join happens before being passed to any filters. +- `join(x)`: Join list of values with delimiter x, e.g. join(:): ['a', 'b', 'c'] => 'a:b:c'; the DELIM option functions similar to join(x) but with DELIM, the join happens before being passed to any filters.May optionally be used without an argument, that is 'join()' which joins values together with no delimiter. e.g. join(): ['a', 'b', 'c'] => 'abc'. - `append(x)`: Append x to list of values, e.g. append(d): ['a', 'b', 'c'] => ['a', 'b', 'c', 'd']. - `prepend(x)`: Prepend x to list of values, e.g. prepend(d): ['a', 'b', 'c'] => ['d', 'a', 'b', 'c']. - `remove(x)`: Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c']. diff --git a/osxphotos/phototemplate.py b/osxphotos/phototemplate.py index d69b09f0..4992c8a9 100644 --- a/osxphotos/phototemplate.py +++ b/osxphotos/phototemplate.py @@ -253,7 +253,10 @@ FILTER_VALUES = { "rsort": "Sort list of values in reverse order, e.g. ['a', 'b', 'c'] => ['c', 'b', 'a'].", "reverse": "Reverse order of values, e.g. ['a', 'b', 'c'] => ['c', 'b', 'a'].", "uniq": "Remove duplicate values, e.g. ['a', 'b', 'c', 'b', 'a'] => ['a', 'b', 'c'].", - "join(x)": "Join list of values with delimiter x, e.g. join(:): ['a', 'b', 'c'] => 'a:b:c'; the DELIM option functions similar to join(x) but with DELIM, the join happens before being passed to any filters.", + "join(x)": "Join list of values with delimiter x, e.g. join(:): ['a', 'b', 'c'] => 'a:b:c'; " + + "the DELIM option functions similar to join(x) but with DELIM, the join happens before being passed to any filters." + + "May optionally be used without an argument, that is 'join()' which joins values together with no delimiter. " + + "e.g. join(): ['a', 'b', 'c'] => 'abc'.", "append(x)": "Append x to list of values, e.g. append(d): ['a', 'b', 'c'] => ['a', 'b', 'c', 'd'].", "prepend(x)": "Prepend x to list of values, e.g. prepend(d): ['a', 'b', 'c'] => ['d', 'a', 'b', 'c'].", "remove(x)": "Remove x from list of values, e.g. remove(b): ['a', 'b', 'c'] => ['a', 'c'].", @@ -1160,7 +1163,6 @@ class PhotoTemplate: "split", "chop", "chomp", - "join", "append", "prepend", "remove", @@ -1234,7 +1236,7 @@ class PhotoTemplate: value = temp_values elif filter_ == "join": # join list of values with delimiter - delim = args + delim = args or "" value = [delim.join(values)] elif filter_ == "append": # append value to list diff --git a/tests/test_template.py b/tests/test_template.py index 25abf29a..8d587b42 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -215,6 +215,7 @@ TEMPLATE_VALUES = { "{descr|brackets}": "[Jack Rose Dining Saloon]", "{descr|split( )|join(|)}": "Jack|Rose|Dining|Saloon", "{descr|autosplit|join(|)}": "Jack|Rose|Dining|Saloon", + "{descr|autosplit|join()}": "JackRoseDiningSaloon", "{descr|autosplit|chop(1)|join(|)}": "Jac|Ros|Dinin|Saloo", "{descr|autosplit|chomp(1)|join(|)}": "ack|ose|ining|aloon", "{descr|chop(2)}": "Jack Rose Dining Salo",