Exemplo n.º 1
0
        public FileOutput GenerateFile(
            string inputRoot,
            FileLocation inputFileLocation,
            string inputContent,
            string[] templates,
            ImmutableDictionary <string, IBuffer <ImmutableDictionary <string, object> > > projectVariables)
        {
            // all files are transformed by the templater
            string fileOutput = templater.Convert(inputRoot, inputContent, projectVariables.AsTemplateValues(), out var fileVariables);

            var environment = Settings.Default;

            environment = environment.SetItems(projectVariables.AsTemplateValues());

            // markdown files get some additional processing
            if (inputFileLocation.Extension == ".md")
            {
                environment = environment.SetItems(TransformMarkdownVariables(fileVariables, environment));
                var processOutput = TransformMarkdownFile(inputRoot, fileOutput, templates, environment);
                fileOutput  = processOutput.Output;
                environment = processOutput.Variables;
            }
            else
            {
                environment = environment.SetItems(fileVariables);
            }

            var outputLocation = CreateOutputFileName(inputRoot, inputFileLocation, environment);

            environment = environment.TrySetItem(Settings.ItemUrl, outputLocation.FullyQualifiedName);

            return(new FileOutput(outputLocation, fileOutput, environment));
        }