public static void RenderFileFromTemplate(FileRenderArgs args) { var targetFile = args.TransformFilePath ? new FileInfo(FindReplaceTextTransformer.Transform(args.OutputFile.FullName, args.TemplateVariables)) : args.OutputFile; var text = File.ReadAllText(args.TemplateFile.FullName); var transformedText = FindReplaceTextTransformer.Transform(text, args.TemplateVariables); targetFile.Directory.Create(); File.WriteAllText(targetFile.FullName, transformedText); }
public static void Render(DirectoryRenderArgs args) { var files = Directory.GetFiles(args.TemplateDirectory.FullName, "*", SearchOption.AllDirectories); var ignore = new Ignore.Ignore(); var ignoreFiles = args.Gitignore?.Exists == true; if (ignoreFiles) { var patterns = File .ReadAllLines(args.Gitignore.FullName) .Where(x => !x.Trim().StartsWith("#") && !string.IsNullOrWhiteSpace(x)); ignore.Add(patterns); } foreach (var templateFile in files) { var templateFileInfo = new FileInfo(templateFile); var templateFileRelativePath = templateFileInfo.FullName.Replace(args.TemplateDirectory.FullName, string.Empty).TrimStart('\\'); if (ignoreFiles && ignore.IsIgnored(UseLinuxStyleRelativePath(templateFileRelativePath))) { continue; } var outputFileInfo = new FileInfo( Path.Combine( args.OutputDirectory.FullName, templateFileRelativePath)); var fileRenderArgs = new FileRenderArgs { TemplateFile = templateFileInfo, OutputFile = outputFileInfo, TemplateVariables = args.TemplateVariables, TransformFilePath = args.TransformFilePath }; FileTemplateRenderer.RenderFileFromTemplate(fileRenderArgs); }