|
6 | 6 |
|
7 | 7 | namespace Moryx.Cli.Templates |
8 | 8 | { |
| 9 | + /// <summary> |
| 10 | + /// <see cref="Template"/> is used to bring copy files from a template |
| 11 | + /// repository to the target solution as defined in a `.moryxtpl`. |
| 12 | + /// |
| 13 | + /// Central functions are |
| 14 | + /// |
| 15 | + /// * `WriteFilesToDisk()` |
| 16 | + /// * `ReplacePlaceHoldersInsideFiles()` |
| 17 | + /// * Everything that returns a dictionary as for example |
| 18 | + /// * `StateBaseFile()` |
| 19 | + /// * `Product()` |
| 20 | + /// * `Resource()` |
| 21 | + /// |
| 22 | + /// </summary> |
| 23 | + /// <example> |
| 24 | + /// var dictionary = template.Product(product); |
| 25 | + /// |
| 26 | + /// var files = template.WriteFilesToDisk(dictionary); |
| 27 | + /// Template.ReplacePlaceHoldersInsideFiles( |
| 28 | + /// files, |
| 29 | + /// template.ReplaceVariables(template.Configuration.Add.Product, product) |
| 30 | + /// ); |
| 31 | + /// </example> |
9 | 32 | public class Template |
10 | 33 | { |
11 | 34 | private const string IdentifierKey = "{id}"; |
@@ -177,7 +200,11 @@ public Dictionary<string, string> Module(string name) |
177 | 200 | public Dictionary<string, string> Resource(string identifier) |
178 | 201 | => FilteredFileStructure(_configuration.Add.Resource, identifier); |
179 | 202 |
|
180 | | - |
| 203 | + /// <summary> |
| 204 | + /// Replaces placeholders in the files provided to <paramref name="filenames"/>. |
| 205 | + /// </summary> |
| 206 | + /// <param name="filenames">List of files to be updated</param> |
| 207 | + /// <param name="dict">Dictionary of placeholders to be replaced</param> |
181 | 208 | public static void ReplacePlaceHoldersInsideFiles(IEnumerable<string> filenames, Dictionary<string, string> dict) |
182 | 209 | { |
183 | 210 | var tasks = new List<Task>(); |
@@ -225,6 +252,13 @@ public Dictionary<string, string> PrepareFileStructure(List<string> fileNames, D |
225 | 252 | f => ReplacePlaceholders(f, patterns) |
226 | 253 | ); |
227 | 254 |
|
| 255 | + /// <summary> |
| 256 | + /// Creates a dictionary of placeholders and their replacements |
| 257 | + /// by updating variables (e.g. `{id}`, `{solutionname}`) |
| 258 | + /// </summary> |
| 259 | + /// <param name="pattern">a <see cref="ConfigurationPattern"/></param> |
| 260 | + /// <param name="identifier">Will replace `{id}` in </param> |
| 261 | + /// <param name="variables">Custom list of variables to be replaced. E.g. `<"{lang}", "Spanish">`</param> |
228 | 262 | public Dictionary<string, string> ReplaceVariables(ConfigurationPattern pattern, string identifier = "", Dictionary<string, string>? variables = null) |
229 | 263 | { |
230 | 264 | var replacements = pattern.Replacements; |
@@ -265,6 +299,12 @@ private static string ReplacePlaceholders(string f, Dictionary<string, string> p |
265 | 299 | return result; |
266 | 300 | } |
267 | 301 |
|
| 302 | + /// <summary> |
| 303 | + /// Writes provided files to the file system |
| 304 | + /// </summary> |
| 305 | + /// <param name="dictionary">A dictionary of files to be copied `from` a source `to` a target</param> |
| 306 | + /// <param name="force">Overwrite existing files if true</param> |
| 307 | + /// <returns>List of written files</returns> |
268 | 308 | public IEnumerable<string> WriteFilesToDisk(Dictionary<string, string> dictionary, bool force = false) |
269 | 309 | { |
270 | 310 | var result = new List<string>(); |
|
0 commit comments