public void Render() { foreach (Entity entity in entities) { renderingEngine.Render(entity); } renderingEngine.Render(); }
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()); } }
private static void OnValueProduced(ValueProduced valueProduced, ConcurrentDictionary <Guid, OpenRequest> openRequests, RenderingEngine renderingEngine) { var openRequest = openRequests[valueProduced.ParentId]; var rendering = renderingEngine.Render(valueProduced.Value); // executeResult data var executeResultData = new ExecuteResult( openRequest.ExecutionCount, transient: openRequest.Transient, data: new Dictionary <string, object> { { rendering.Mime, rendering.Content } }); if (!openRequest.ExecuteRequest.Silent) { // send on io var executeResultMessage = Message.Create( executeResultData, openRequest.Context.Request.Header); openRequest.Context.IoPubChannel.Send(executeResultMessage); } }
public void renders_null() { var rendering = _engine.Render(null); rendering.Mime.Should().Be("text/plain"); rendering.Content.Should().Be("<null>"); }
private static void OnValueProduced(ValueProduced valueProduced, ConcurrentDictionary <IKernelCommand, OpenRequest> openRequests, RenderingEngine renderingEngine) { openRequests.TryGetValue(valueProduced.Command, out var openRequest); if (openRequest == null) { return; } try { var rendering = renderingEngine.Render(valueProduced.Value); // executeResult data var executeResultData = new ExecuteResult( openRequest.ExecutionCount, transient: openRequest.Transient, data: new Dictionary <string, object> { { rendering.MimeType, rendering.Content } }); if (!openRequest.Request.Silent) { // send on io var executeResultMessage = Message.Create( executeResultData, openRequest.Context.Request.Header); openRequest.Context.IoPubChannel.Send(executeResultMessage); } } catch (Exception e) { var errorContent = new Error( eName: "Unhandled Exception", eValue: $"{e.Message}" ); if (!openRequest.Request.Silent) { // send on io var error = Message.Create( errorContent, openRequest.Context.Request.Header); openRequest.Context.IoPubChannel.Send(error); // send on stderr var stdErr = new StdErrStream(errorContent.EValue); var stream = Message.Create( stdErr, openRequest.Context.Request.Header); openRequest.Context.IoPubChannel.Send(stream); } } }
public void objects_are_rendered_as_table() { var source = new { Name = "Test object", Counter = 10 }; var rendering = _engine.Render(source); rendering.Mime.Should().Be("text/html"); var html = new HtmlDocument(); html.LoadHtml(rendering.Content.ToString()); var table = html.DocumentNode.SelectSingleNode("table"); table.Should().NotBeNull(); table.SelectNodes("//td") .Select(n => n.InnerText) .Should() .BeEquivalentTo("Name", source.Name, "Counter", "10"); }