Exemple #1
0
        private void GenerateFile(InterpolationArgs args, string templatePath, Interpolator interpolator, bool generateDeferred)
        {
            string template = File.ReadAllText(templatePath);

            if (ShouldGenerateFile(args, ref template, templatePath, generateDeferred))
            {
                while (true)
                {
                    string placeHolder, replacement;
                    if (!interpolator.TryGetNextReplacement(template, args, out placeHolder, out replacement))
                        break;

                    template = template.Replace(placeHolder, replacement);
                }

                BackupExistingFile(args.OutputFilePath);
                File.WriteAllText(args.OutputFilePath, template);
            }
        }
Exemple #2
0
        private static string GetOutputFilePath(InterpolationArgs args, Dictionary<string, string> outputDirectories, Interpolator interpolator)
        {
            string outputDirectory = outputDirectories[interpolator.TemplateExtension];
            string fileName = interpolator.GetOutputFileName(args);
            string outputFilePath = Path.Combine(outputDirectory, fileName);

            if (string.IsNullOrEmpty(Path.GetExtension(fileName)))
                outputFilePath = Path.ChangeExtension(outputFilePath, interpolator.TemplateExtension);

            return outputFilePath;
        }