{"id":329,"date":"2013-01-11T04:06:36","date_gmt":"2013-01-11T04:06:36","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=329"},"modified":"2013-01-11T04:06:36","modified_gmt":"2013-01-11T04:06:36","slug":"combining-generated-and-flare-managed-content","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/combining-generated-and-flare-managed-content\/","title":{"rendered":"Combining Generated and Flare-managed Content"},"content":{"rendered":"<p>One way to combine generated content with Flare-managed content is to use snippets. Here is a generic structure:<\/p>\n<p>Generated topics each contain:<\/p>\n<p style=\"padding-left: 30px;\">Generated snippet &#8211; periodically refreshed<\/p>\n<p style=\"padding-left: 30px;\">Generated snippet &#8211; updated with Flare editors<\/p>\n<p>Consider a simple case where the generated content comes from a CSV file. For this example, the CSV is analogous to a table with two columns. The first column is a name of some reference subject and the second column is the description.<\/p>\n<p>Flowers,Flowers are structures which are part of some plants&#8230;<br \/>\nUnicorns,Unicorns are figments which occur in some imaginations\u2026<br \/>\nSunbeams,Sunbeams bathe the earth in radiation when another object does not block the sun&#8230;<br \/>\nRainbows,Rainbows lead to the other side\u2026<\/p>\n<p>The term CSV is thrown around loosely. For this example, the CSV has only two entries per line. The entries are delimited by one comma. To provide a simple example, the content itself does not have commas. Here is one way to read a CSV with Visual Basic:<\/p>\n<p><a title=\"How to: Read From Comma-Delimited Text Files in Visual Basic\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cakac7e6.aspx\" target=\"_blank\">How to: Read From Comma-Delimited Text Files in Visual Basic<\/a> from MSDN<\/p>\n<p>This example dispenses with the exception handling for reading clarity. But bad files should be expected and handled. There is a decent discussion at the bottom of the article about other considerations.<\/p>\n<p>To create the TOC, topics, and snippets, Linq to XML is used. This has been discussed in previous blog entries. The procedures in the sample are fairly targeted. Generalized, overloaded procedures would be better. But reading clarity, the scopes of the procedures are narrow.<\/p>\n<p>This example also assumes a specific project structure and existing folders. A working utility should check for folders and add folders if necessary. The flexibility to specify sub folders is also a plus. And of course we don&#8217;t want to limit ourselves to CSV. But rather than cloud the example, here is the code without all of that:<\/p>\n<pre class=\"lang:vb decode:true\">Module Module1\r\n\r\n    Public Sub CreateSnippet(ByVal fileName As String, ByVal description As String)\r\n        Dim Snippet As XDocument = _\r\n            &lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n            &lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\"&gt;\r\n                &lt;head&gt;\r\n                &lt;\/head&gt;\r\n                &lt;body&gt;\r\n                    &lt;p&gt;&lt;%= description %&gt;&lt;\/p&gt;\r\n                &lt;\/body&gt;\r\n            &lt;\/html&gt;\r\n        Snippet.Save(\"C:\\Example\\Content\\Resources\\Snippets\\\" &amp; fileName)\r\n    End Sub\r\n\r\n    Public Sub CreateTopic(ByVal fileName As String, ByVal topicName As String)\r\n        Dim Topic As XDocument = _\r\n            &lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n            &lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\"&gt;\r\n                &lt;head&gt;&lt;title&gt;&lt;%= topicName %&gt;&lt;\/title&gt;\r\n                &lt;\/head&gt;\r\n                &lt;body&gt;\r\n                    &lt;h1&gt;&lt;%= topicName %&gt;&lt;\/h1&gt;\r\n                    &lt;MadCap:snippetBlock src=&lt;%= \"Resources\/Snippets\/\" &amp; topicName &amp; \"-Refreshable.flsnp\" %&gt;\/&gt;\r\n                    &lt;MadCap:snippetBlock src=&lt;%= \"Resources\/Snippets\/\" &amp; topicName &amp; \"-EditInFlare.flsnp\" %&gt;\/&gt;\r\n                &lt;\/body&gt;\r\n            &lt;\/html&gt;\r\n        Topic.Save(\"C:\\Example\\Content\\\" &amp; fileName)\r\n    End Sub\r\n\r\n    Sub Main()\r\n        Dim FlareToc As XDocument = _\r\n            &lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n            &lt;CatapultToc&gt;&lt;\/CatapultToc&gt;\r\n\r\n        Using MyReader As New FileIO.TextFieldParser(\"C:\\Example\\wonderful-things.csv\")\r\n            MyReader.TextFieldType = FileIO.FieldType.Delimited\r\n            MyReader.SetDelimiters(\",\")\r\n            Dim currentRow As String()\r\n            While Not MyReader.EndOfData\r\n                currentRow = MyReader.ReadFields()\r\n                CreateTopic(currentRow.First &amp; \".htm\", currentRow.First)\r\n                CreateSnippet(currentRow.First &amp; \"-Refreshable.flsnp\", currentRow.Last)\r\n                CreateSnippet(currentRow.First &amp; \"-EditInFlare.flsnp\", \"Default text\")\r\n                FlareToc.Add()\r\n                FlareToc.Root.Add(&lt;TocEntry Link=&lt;%= \"\/Content\/\" &amp; currentRow.First &amp; \".htm\" %&gt; Title=&lt;%= currentRow.First %&gt;&gt;&lt;\/TocEntry&gt;)\r\n            End While\r\n        End Using\r\n        FlareToc.Save(\"C:\\Example\\Project\\TOCs\\wonderful-things.fltoc\")\r\n    End Sub\r\nEnd Module<\/pre>\n<p>Here are the generated files in the folders:<\/p>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/combining-generated-and-flare-managed-content\/generated-flare-files\/\" rel=\"attachment wp-att-340\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-340\" alt=\"generated-flare-files\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/generated-flare-files.png\" width=\"968\" height=\"438\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/generated-flare-files.png 968w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/generated-flare-files-300x135.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/01\/generated-flare-files-624x282.png 624w\" sizes=\"(max-width: 968px) 100vw, 968px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Here is the TOC:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;CatapultToc&gt;\r\n  &lt;TocEntry Link=\"\/Content\/Flowers.htm\" Title=\"Flowers\"&gt;&lt;\/TocEntry&gt;\r\n  &lt;TocEntry Link=\"\/Content\/Unicorns.htm\" Title=\"Unicorns\"&gt;&lt;\/TocEntry&gt;\r\n  &lt;TocEntry Link=\"\/Content\/Sunbeams.htm\" Title=\"Sunbeams\"&gt;&lt;\/TocEntry&gt;\r\n  &lt;TocEntry Link=\"\/Content\/Rainbows.htm\" Title=\"Rainbows\"&gt;&lt;\/TocEntry&gt;\r\n&lt;\/CatapultToc&gt;<\/pre>\n<p>Here is a snippet:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\"&gt;\r\n  &lt;head&gt;&lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;p&gt;Flowers are structures which are part of some plants...&lt;\/p&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>And here is a topic:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;html xmlns:MadCap=\"http:\/\/www.madcapsoftware.com\/Schemas\/MadCap.xsd\"&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Flowers&lt;\/title&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;h1&gt;Flowers&lt;\/h1&gt;\r\n    &lt;MadCap:snippetBlock src=\"Resources\/Snippets\/Flowers-Refreshable.flsnp\" \/&gt;\r\n    &lt;MadCap:snippetBlock src=\"Resources\/Snippets\/Flowers-EditInFlare.flsnp\" \/&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One way to combine generated content with Flare-managed content is to use snippets. Here is a generic structure: Generated topics each contain: Generated snippet &#8211; periodically refreshed Generated snippet &#8211; updated with Flare editors Consider a simple case where the generated content comes from a CSV file. For this example, the CSV is analogous to&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/combining-generated-and-flare-managed-content\/\">Continue reading <span class=\"screen-reader-text\">Combining Generated and Flare-managed Content<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/329"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":23,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/329\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}