public void ExportTo(string directory, Topic root, Func <Topic, string> pathing)
        {
            var fileSystem = new FileSystem();

            string sourceContent = _settings.Root.AppendPath("content");

            if (fileSystem.DirectoryExists(sourceContent))
            {
                fileSystem.CopyToDirectory(sourceContent, directory.AppendPath("content"));
            }

            root.AllTopicsInOrder().Each(topic =>
            {
                var path            = pathing(topic);
                var parentDirectory = path.ParentUrl();

                if (parentDirectory.IsNotEmpty())
                {
                    fileSystem.CreateDirectory(directory.AppendPath(parentDirectory));
                }


                var text = _generator.Generate(topic);

                // Hoakum
                topic.Substitutions.Each((key, value) =>
                {
                    text = text.Replace(key, value);
                });

                fileSystem.WriteStringToFile(directory.AppendPath(path), text);
            });
        }
        public HtmlToPdfDocument Generate()
        {
            var doc = new HtmlToPdfDocument
            {
                GlobalSettings =
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Landscape,
                    PaperSize   = PaperKind.A4,
                },
                ObjectSettings =
                {
                    new PdfObjectSettings
                    {
                        PagesCount  = true,
                        WebSettings =
                        {
                            DefaultEncoding = "utf-8",
                        },
                        HeaderSettings =
                        {
                            FontSize = 9, Right = "Page [page] of [toPage]", Line = true,
                        },
                        FooterSettings =
                        {
                            FontSize = 9, Right = "Page [page] of [toPage]",
                        },
                    },
                },
            };

            doc.ObjectSettings[0].HtmlContent = _htmlGenerator.Generate();

            return(doc);
        }
Example #3
0
        public string GenerateHtml(Topic topic)
        {
            var html = _generator.Generate(topic);

            var builder = new StringBuilder(html);

            topic.Substitutions.Each((key, value) => { builder.Replace(key, value); });

            var script = _webSocketScript.Replace("%WEB_SOCKET_ADDRESS%", _settings.WebsocketAddress);

            builder.Replace("</head>", script + "\n</head>");

            var tag = new HtmlTag("script").Attr("language", "javascript").Attr("src", "/topics.js");

            builder.Replace("</head>", tag.ToString() + "\n</head>");

            return(builder.ToString());
        }