From 2ad2e0675409c9fe359e18962fae9c3b0ff9321f Mon Sep 17 00:00:00 2001 From: kaso17 Date: Mon, 2 Apr 2018 02:22:13 +0200 Subject: [PATCH] Cardigann: add join expression --- .../Indexers/CardigannIndexer.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Jackett.Common/Indexers/CardigannIndexer.cs b/src/Jackett.Common/Indexers/CardigannIndexer.cs index ffcb9fae3..f947cc727 100644 --- a/src/Jackett.Common/Indexers/CardigannIndexer.cs +++ b/src/Jackett.Common/Indexers/CardigannIndexer.cs @@ -251,6 +251,27 @@ namespace Jackett.Common.Indexers ReReplaceRegexMatches = ReReplaceRegexMatches.NextMatch(); } + // handle join expression + // Example: {{ join .Categories "," }} + Regex JoinRegex = new Regex(@"{{\s*join\s+(\..+?)\s+""(.*?)""\s*}}"); + var JoinMatches = JoinRegex.Match(template); + + while (JoinMatches.Success) + { + string all = JoinMatches.Groups[0].Value; + string variable = JoinMatches.Groups[1].Value; + string delimiter = JoinMatches.Groups[2].Value; + + var input = (ICollection)variables[variable]; + var expanded = string.Join(delimiter, input); + + if (modifier != null) + expanded = modifier(expanded); + + template = template.Replace(all, expanded); + JoinMatches = JoinMatches.NextMatch(); + } + // handle if ... else ... expression Regex IfElseRegex = new Regex(@"{{\s*if\s*(.+?)\s*}}(.*?){{\s*else\s*}}(.*?){{\s*end\s*}}"); var IfElseRegexMatches = IfElseRegex.Match(template);