public XElement Format(IDirectoryTreeNode contentNode, IEnumerable<IDirectoryTreeNode> features)
        {
            var featureItemNode = contentNode as FeatureDirectoryTreeNode;
            if (featureItemNode != null)
            {
                var formattedContent = this.htmlFeatureFormatter.Format(featureItemNode.Feature);
                this.htmlImageRelocator.Relocate(contentNode, formattedContent);
                return formattedContent;
            }

            var indexItemNode = contentNode as FolderDirectoryTreeNode;
            if (indexItemNode != null)
            {
                return this.htmlIndexFormatter.Format(indexItemNode, features);
            }

            var markdownItemNode = contentNode as MarkdownTreeNode;
            if (markdownItemNode != null)
            {
                this.htmlImageRelocator.Relocate(contentNode, markdownItemNode.MarkdownContent);
                return markdownItemNode.MarkdownContent;
            }

            throw new InvalidOperationException("Cannot format a FeatureNode with a Type of " + contentNode.GetType() +
                                                " as content");
        }
Exemple #2
0
        private GeneralTree<IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode)
        {
            IDirectoryTreeNode currentNode =
                featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new GeneralTree<IDirectoryTreeNode>(currentNode);

            bool isRelevantFileFound = false;
            foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file)))
            {
                isRelevantFileFound = true;
                IDirectoryTreeNode node = featureNodeFactory.Create(rootNode.OriginalLocation, file);
                tree.Add(node);
            }

            bool isRelevantDirectoryFound = false;
            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                GeneralTree<IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    isRelevantDirectoryFound = true;
                    tree.Add(subTree);
                }
            }

            if (!isRelevantFileFound && !isRelevantDirectoryFound) return null;

            return tree;
        }
Exemple #3
0
        public XElement Format(IDirectoryTreeNode contentNode, IEnumerable <IDirectoryTreeNode> features)
        {
            var featureItemNode = contentNode as FeatureDirectoryTreeNode;

            if (featureItemNode != null)
            {
                return(htmlFeatureFormatter.Format(featureItemNode.Feature));
            }

            var indexItemNode = contentNode as FolderDirectoryTreeNode;

            if (indexItemNode != null)
            {
                return(htmlIndexFormatter.Format(indexItemNode, features));
            }

            var markdownItemNode = contentNode as MarkdownTreeNode;

            if (markdownItemNode != null)
            {
                return(markdownItemNode.MarkdownContent);
            }

            throw new InvalidOperationException("Cannot format a FeatureNode with a Type of " + contentNode.GetType() +
                                                " as content");
        }
        public XDocument Format(IDirectoryTreeNode featureNode, GeneralTree<IDirectoryTreeNode> features, DirectoryInfo rootFolder)
        {
            var xmlns = HtmlNamespace.Xhtml;
            var featureNodeOutputPath = Path.Combine(this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot);
            var featureNodeOutputUri = new Uri(featureNodeOutputPath);

            var container = new XElement(xmlns + "div", new XAttribute("id", "container"));
            container.Add(this.htmlHeaderFormatter.Format());
            container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder));
            container.Add(this.htmlContentFormatter.Format(featureNode, features));
            container.Add(this.htmlFooterFormatter.Format());

            var body = new XElement(xmlns + "body");
            body.Add(container);

            var head = new XElement(xmlns + "head");
            head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name)));

            head.Add(new XElement(xmlns + "link",
                         new XAttribute("rel", "stylesheet"),
                         new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)),
                         new XAttribute("type", "text/css")));

            head.Add(new XElement(xmlns + "link",
                         new XAttribute("rel", "stylesheet"),
                         new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.PrintStylesheet)),
                         new XAttribute("type", "text/css"),
                         new XAttribute("media", "print")));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryScript)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryDataTablesScript)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.AdditionalScripts)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("type", "text/javascript"),
                         documentReady));

            var html = new XElement(xmlns + "html",
                           new XAttribute(XNamespace.Xml + "lang", "en"),
                           head,
                           body);

            var document = new XDocument(
                                new XDeclaration("1.0", "UTF-8", null),
                                new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty),
                                html);

            return document;
        }
 public static bool Exists
 (
     [CanBeNull] this IDirectoryTreeNode directoryTreeNode
 )
 {
     // Empty string does not exist and it'll return false.
     return(Directory.Exists(directoryTreeNode?.DirectoryName ?? string.Empty));
 }
Exemple #6
0
        private GeneralTree <IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode)
        {
            IDirectoryTreeNode currentNode =
                featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new GeneralTree <IDirectoryTreeNode>(currentNode);

            bool isRelevantFileFound = false;

            foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file)))
            {
                isRelevantFileFound = true;

                IDirectoryTreeNode node = null;
                try
                {
                    node = featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("The file, {0}, will be ignored because it could not be read in properly", file.FullName);
                    }
                }

                if (node != null)
                {
                    tree.Add(node);
                }
            }

            bool isRelevantDirectoryFound = false;

            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                GeneralTree <IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    isRelevantDirectoryFound = true;
                    tree.Add(subTree);
                }
            }

            if (!isRelevantFileFound && !isRelevantDirectoryFound)
            {
                return(null);
            }

            return(tree);
        }
Exemple #7
0
 public static void Deconstruct(
     [CanBeNull] this IDirectoryTreeNode directoryTreeNode,
     [CanBeNull] out string directoryName,
     [CanBeNull] out IEnumerable <string> directoryNames,
     [CanBeNull] out IEnumerable <string> fileNames)
 {
     directoryName  = directoryTreeNode?.DirectoryName;
     directoryNames = directoryTreeNode?.DirectoryNames;
     fileNames      = directoryTreeNode?.FileNames;
 }
        public static bool IsIndexMarkDownNode(this IDirectoryTreeNode node)
        {
            var markdownItemNode = node as MarkdownTreeNode;

            if (markdownItemNode != null &&
                markdownItemNode.OriginalLocation.Name.StartsWith("index", StringComparison.InvariantCultureIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
Exemple #9
0
    private XElement FormatList(IDirectoryTreeNode node, IEnumerable<FeatureDirectoryTreeNode> items)
    {
      // <ul class="list">...</ul>

      var list = new XElement(this.xmlns + "ul", new XAttribute("class", "list"));

      foreach (var li in items.Select(item => FormatListItem(item.GetRelativeUriTo(node.OriginalLocationUrl), item.Feature.Name, item.Feature.Description)))
      {
        list.Add(li);
      }

      return list;
    }
Exemple #10
0
        public Uri GeneratePathToFeature(IDirectoryTreeNode directoryTreeNode)
        {
            var fileInfo = directoryTreeNode.OriginalLocation as FileInfo;
            if (fileInfo != null)
            {
                var nodeFilename = directoryTreeNode.OriginalLocation.Name.Replace(directoryTreeNode.OriginalLocation.Extension, string.Empty);
                var nodeDitaName = nodeFilename.ToDitaName() + ".dita";
                var newUri = fileInfo.Directory.ToFileUriCombined(nodeDitaName);
                
                return this.configuration.FeatureFolder.ToUri().MakeRelativeUri(newUri);
            }

            throw new InvalidOperationException("Cannot Generate Path to a file that is not a feature");
        }
        public virtual void Relocate(IDirectoryTreeNode node, XElement parsedFeature)
        {
            var images = parsedFeature.Descendants(HtmlNamespace.Xhtml + "img");

            foreach (var image in images)
            {
                var sourceValue = image.Attribute("src").Value;

                if (!String.IsNullOrEmpty(sourceValue))
                {
                    var relativePathToImage = Path.Combine(Path.GetDirectoryName(node.RelativePathFromRoot), sourceValue);
                    var source = Path.Combine(configuration.FeatureFolder.FullName, relativePathToImage);
                    var destination = Path.Combine(configuration.OutputFolder.FullName, relativePathToImage);
                    File.WriteAllBytes(destination, File.ReadAllBytes(source));
                }
            }
        }
        public Uri GeneratePathToFeature(IDirectoryTreeNode directoryTreeNode)
        {
            var fileInfo = directoryTreeNode.OriginalLocation as FileInfo;

            if (fileInfo != null)
            {
                string nodeFilename =
                    directoryTreeNode.OriginalLocation.Name.Replace(directoryTreeNode.OriginalLocation.Extension,
                                                                    string.Empty);
                string nodeDitaName = nodeFilename.ToDitaName() + ".dita";
                Uri    newUri       = fileInfo.Directory.ToFileUriCombined(nodeDitaName);

                return(configuration.FeatureFolder.ToUri().MakeRelativeUri(newUri));
            }

            throw new InvalidOperationException("Cannot Generate Path to a file that is not a feature");
        }
        private GeneralTree<IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode)
        {
            IDirectoryTreeNode currentNode =
                featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new GeneralTree<IDirectoryTreeNode>(currentNode);

            bool isRelevantFileFound = false;
            foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file)))
            {
                isRelevantFileFound = true;

                IDirectoryTreeNode node = null;
                try
                {
                    node = featureNodeFactory.Create(rootNode.OriginalLocation, file);
                }
                catch (Exception)
                {     
                    if (log.IsWarnEnabled) log.WarnFormat("The file, {0}, will be ignored because it could not be read in properly", file.FullName);
                }

                if (node != null) tree.Add(node);
            }

            bool isRelevantDirectoryFound = false;
            foreach (DirectoryInfo subDirectory in directory.GetDirectories())
            {
                GeneralTree<IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode);
                if (subTree != null)
                {
                    isRelevantDirectoryFound = true;
                    tree.Add(subTree);
                }
            }

            if (!isRelevantFileFound && !isRelevantDirectoryFound) return null;

            return tree;
        }
        public XElement Format(IDirectoryTreeNode node, IEnumerable<IDirectoryTreeNode> features)
        {
            /*
       <div id="feature">
         <h1>Folder Name</h1>
          <ul class="list">
              <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
              <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
              <li><a href="[link]"><span class="title">[title]</span><span class="separator"> - </span><span class="description">[description]</span></a></li>
          </ul>
       <div>
       */
            var directoryInfo = node.OriginalLocation as DirectoryInfo;

            if (directoryInfo == null)
            {
                throw new ArgumentOutOfRangeException("node", "Argument node must contain a DirectoryInfo.");
            }

            string[] files = directoryInfo.GetFiles().Select(f => f.FullName).ToArray();

            IDirectoryTreeNode[] featuresThatAreDirectChildrenOfFolder =
                features.Where(f => f.OriginalLocation is FileInfo).Where(
                    f => files.Contains(f.OriginalLocation.FullName)).ToArray();

            var div = new XElement(xmlns + "div",
                                   new XAttribute("id", "feature"),
                                   new XElement(xmlns + "h1", node.Name));

            MarkdownTreeNode markdownTreeNode =
                featuresThatAreDirectChildrenOfFolder.Where(n => n.IsIndexMarkDownNode()).OfType<MarkdownTreeNode>().
                    FirstOrDefault();
            if (markdownTreeNode != null)
            {
                div.Add(
                    new XElement(
                        xmlns + "div",
                        new XAttribute("class", "folderDescription"),
                        markdownTreeNode.MarkdownContent));
            }

            div.Add(FormatList(node, featuresThatAreDirectChildrenOfFolder.OfType<FeatureDirectoryTreeNode>()));

            return div;
        }
        private XElement FormatList(IDirectoryTreeNode node, IEnumerable<FeatureDirectoryTreeNode> items)
        {
            // <ul class="list">...</ul>

            var list = new XElement(xmlns + "ul", new XAttribute("class", "list"));

            foreach (
                XElement li in
                    items.Select(
                        item =>
                        FormatListItem(item.GetRelativeUriTo(node.OriginalLocationUrl), item.Feature.Name,
                                       item.Feature.Description)))
            {
                list.Add(li);
            }

            return list;
        }
        public void Then_can_crawl_all_folders_including_subfolders_for_features_successfully()
        {
            string rootPath = @"FakeFolderStructures\FeatureCrawlerTests";
            GeneralTree <IDirectoryTreeNode> features = Kernel.Get <DirectoryTreeCrawler>().Crawl(rootPath);

            Assert.NotNull(features);

            IDirectoryTreeNode indexMd = features.ChildNodes[0].Data;

            indexMd.ShouldNotBeNull();
            indexMd.Name.ShouldEqual("This is an index written in Markdown");
            indexMd.RelativePathFromRoot.ShouldEqual("index.md");
            indexMd.ShouldBeType <MarkdownTreeNode>();

            IDirectoryTreeNode levelOneFeature = features.ChildNodes[1].Data;

            levelOneFeature.ShouldNotBeNull();
            levelOneFeature.Name.ShouldEqual("Addition");
            levelOneFeature.RelativePathFromRoot.ShouldEqual("LevelOne.feature");
            levelOneFeature.ShouldBeType <FeatureDirectoryTreeNode>();

            IDirectoryTreeNode subLevelOneDirectory = features.ChildNodes[2].Data;

            subLevelOneDirectory.ShouldNotBeNull();
            subLevelOneDirectory.Name.ShouldEqual("Sub Level One");
            subLevelOneDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\");
            subLevelOneDirectory.ShouldBeType <FolderDirectoryTreeNode>();

            GeneralTree <IDirectoryTreeNode> subLevelOneNode = features.ChildNodes[2];

            subLevelOneNode.ChildNodes.Count.ShouldEqual(3);

            IDirectoryTreeNode levelOneSublevelOneFeature = subLevelOneNode.ChildNodes[0].Data;

            levelOneSublevelOneFeature.ShouldNotBeNull();
            levelOneSublevelOneFeature.Name.ShouldEqual("Addition");
            levelOneSublevelOneFeature.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\LevelOneSublevelOne.feature");
            levelOneSublevelOneFeature.ShouldBeType <FeatureDirectoryTreeNode>();

            IDirectoryTreeNode levelOneSublevelTwoFeature = subLevelOneNode.ChildNodes[1].Data;

            levelOneSublevelTwoFeature.ShouldNotBeNull();
            levelOneSublevelTwoFeature.Name.ShouldEqual("Addition");
            levelOneSublevelTwoFeature.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\LevelOneSublevelTwo.feature");
            levelOneSublevelTwoFeature.ShouldBeType <FeatureDirectoryTreeNode>();

            GeneralTree <IDirectoryTreeNode> subLevelTwoNode = subLevelOneNode.ChildNodes[2];

            subLevelTwoNode.ChildNodes.Count.ShouldEqual(1);

            IDirectoryTreeNode subLevelTwoDirectory = subLevelOneNode.ChildNodes[2].Data;

            subLevelTwoDirectory.ShouldNotBeNull();
            subLevelTwoDirectory.Name.ShouldEqual("Sub Level Two");
            subLevelTwoDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\SubLevelTwo\");
            subLevelTwoDirectory.ShouldBeType <FolderDirectoryTreeNode>();

            IDirectoryTreeNode levelOneSublevelOneSubLevelTwoDirectory = subLevelOneNode.ChildNodes[2].ChildNodes[0].Data;

            levelOneSublevelOneSubLevelTwoDirectory.ShouldNotBeNull();
            levelOneSublevelOneSubLevelTwoDirectory.Name.ShouldEqual("Addition");
            levelOneSublevelOneSubLevelTwoDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\SubLevelTwo\LevelOneSublevelOneSubLevelTwo.feature");
            levelOneSublevelOneSubLevelTwoDirectory.ShouldBeType <FeatureDirectoryTreeNode>();
        }
        public XDocument Format(IDirectoryTreeNode featureNode, GeneralTree <IDirectoryTreeNode> features,
                                DirectoryInfo rootFolder)
        {
            XNamespace xmlns = HtmlNamespace.Xhtml;
            string     featureNodeOutputPath = Path.Combine(configuration.OutputFolder.FullName,
                                                            featureNode.RelativePathFromRoot);
            var featureNodeOutputUri = new Uri(featureNodeOutputPath);

            var container = new XElement(xmlns + "div", new XAttribute("id", "container"));

            container.Add(htmlHeaderFormatter.Format());
            container.Add(htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder));
            container.Add(htmlContentFormatter.Format(featureNode, features));
            container.Add(htmlFooterFormatter.Format());

            var body = new XElement(xmlns + "body");

            body.Add(container);

            var head = new XElement(xmlns + "head");

            head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name)));

            head.Add(new XElement(xmlns + "link",
                                  new XAttribute("rel", "stylesheet"),
                                  new XAttribute("href",
                                                 featureNodeOutputUri.MakeRelativeUri(htmlResources.MasterStylesheet)),
                                  new XAttribute("type", "text/css")));

            head.Add(new XElement(xmlns + "link",
                                  new XAttribute("rel", "stylesheet"),
                                  new XAttribute("href",
                                                 featureNodeOutputUri.MakeRelativeUri(htmlResources.PrintStylesheet)),
                                  new XAttribute("type", "text/css"),
                                  new XAttribute("media", "print")));

            head.Add(new XElement(xmlns + "script",
                                  new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(htmlResources.jQueryScript)),
                                  new XAttribute("type", "text/javascript"),
                                  new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                                  new XAttribute("src",
                                                 featureNodeOutputUri.MakeRelativeUri(htmlResources.AdditionalScripts)),
                                  new XAttribute("type", "text/javascript"),
                                  new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                                  new XAttribute("type", "text/javascript"),
                                  documentReady));

            var html = new XElement(xmlns + "html",
                                    new XAttribute(XNamespace.Xml + "lang", "en"),
                                    head,
                                    body);

            var document = new XDocument(
                new XDeclaration("1.0", "UTF-8", null),
                new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN",
                                  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty),
                html);

            return(document);
        }