Esempio n. 1
0
        private static void DoExample(string templateFolder, string dataFile, string outputFolder)
        {
            if (Directory.Exists(outputFolder))
            {
                Directory.Delete(outputFolder, true);
            }

            var context = new RenderingContext();

            foreach (var templateFile in Directory.EnumerateFiles(templateFolder, "*", new EnumerationOptions {
                RecurseSubdirectories = true, MatchType = MatchType.Simple, ReturnSpecialDirectories = false
            }))
            {
                Console.WriteLine($"Template file {templateFile}");
                var templatePath = Path.GetRelativePath(templateFolder, templateFile);
                context.AddTemplate(templatePath, Load(templateFile));
            }

            var data = Load(dataFile);

            var engine = new RenderingEngine();

            engine.Render(context, data);

            foreach (var(relativePath, content) in context.Outputs)
            {
                var outputFile = Path.Combine(outputFolder, relativePath);
                Console.WriteLine($"Output file {outputFile}");
                Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
                File.WriteAllText(outputFile, content.ToString());
            }
        }