Пример #1
0
        public async Task <IEnumerable <RenderingResult> > RenderAsync(string templateFilePath, string template, ICodeModel codeModel, IEnumerable <Type> typesThatContainCustomFunctions, EditorConfig editorConfig)
        {
            errorList.Clear();
            output.Info("Rendering template");

            var configuration = new NTypewriter.Configuration();

            configuration.AddCustomFunctions(typesThatContainCustomFunctions.ToArray());

            var configAdapter = new EditorConfigAdapterForScriban(editorConfig);

            var dataModels = new Dictionary <string, object>();

            dataModels[DataScriptObject.DataVariableName] = codeModel;
            dataModels["codeModel"] = codeModel;
            dataModels[DataScriptObject.ConfigVariableName] = configAdapter;

            var result = await NTypeWriter.Render(template, dataModels, configuration, new ExternalOutputAdapter(output));

            output.Info("Used configuration : " + editorConfig.ToString());

            foreach (var message in result.Messages)
            {
                output.Write(message.ToString(), message.Type == MessageType.Error);
                errorList.AddError(templateFilePath, message);
            }
            errorList.Publish();
            if (result.HasErrors)
            {
                throw new RuntimeException("Rendering template failed");
            }

            output.Info("Template rendered successfully");

            var rootDirectory = Path.GetDirectoryName(templateFilePath);

            output.Info($"Root directory : {rootDirectory})");
            var renderedItems = result.Items.Select(x => new RenderingResult(x, rootDirectory)).ToList();

            return(renderedItems);
        }
Пример #2
0
 public void BeforeCompilation()
 {
     _errorList.Clear();
     _reportedRuntimeErrors.Clear();
 }