Пример #1
0
 public void transform(HtmlDocument document, TemplateEnvironment environment, List <PageStackItem> pageDefinitions)
 {
     using (var sha = SHA256.Create())
     {
         var controllerNode = HtmlRapierQueries.getControllerNode("treeMenu", document.DocumentNode);
         if (controllerNode != null)
         {
             var file = controllerNode.GetAttributeValue("data-hr-config-menu", default(String));
             if (file != null)
             {
                 try
                 {
                     using (var stream = fileFinder.ReadFile(file))
                     {
                         byte[] checksum = sha.ComputeHash(stream);
                         var    hash     = BitConverter.ToString(checksum).Replace("-", String.Empty);
                         controllerNode.SetAttributeValue("data-hr-config-treemenu-version", hash);
                     }
                 }
                 catch (FileNotFoundException)
                 {
                     //Ignored, just means we don't write a hash
                 }
             }
         }
     }
 }
Пример #2
0
        public void transform(HtmlDocument document, TemplateEnvironment environment, List <PageStackItem> pageDefinitions)
        {
            var controllerNode = HtmlRapierQueries.getControllerNode("treeMenu", document.DocumentNode);

            if (controllerNode != null)
            {
                controllerNode.SetAttributeValue("data-hr-config-treemenu-editmode", "true");
                controllerNode.AddClass("treemenu-editor");
                var rootControllerDoc = new HtmlDocument();
                rootControllerDoc.LoadHtml(rootEditor);
                controllerNode.InsertBefore(rootControllerDoc.DocumentNode, controllerNode.FirstChild);
                //Find templates
                var folderModel = HtmlRapierQueries.getModelNode("childItems", controllerNode);
                if (folderModel != null)
                {
                    var folderTemplate = HtmlRapierQueries.getModelTemplate(folderModel);
                    if (folderTemplate != null)
                    {
                        var firstElement = folderTemplate.FirstElementChild();
                        if (firstElement != null)
                        {
                            MakeDraggable(firstElement);
                        }

                        var insertNode = folderTemplate.Select("[data-hr-on-click='toggleMenuItem']").FirstOrDefault();
                        if (insertNode != null)
                        {
                            var childModel = HtmlRapierQueries.getModelNode("children", folderTemplate);
                            if (childModel != null)
                            {
                                var doc = new HtmlDocument();
                                doc.LoadHtml(folderEditor);
                                insertNode.AppendChild(doc.DocumentNode);
                                insertNode.AddClass("treemenu-editor-folder");
                            }
                        }
                    }

                    var linkTemplate = HtmlRapierQueries.getModelTemplate(folderModel, "link");
                    if (linkTemplate != null)
                    {
                        var insertNode = linkTemplate.FirstElementChild();
                        if (insertNode != null)
                        {
                            insertNode.InnerHtml += linkEditor;
                            insertNode.AddClass("treemenu-editor-link");
                            MakeDraggable(insertNode);
                        }
                    }
                }
            }
        }