public static string Parse(
            Compiler docsCompiler, Folder folder, string fullPath, string trail, string versionUrl)
        {
            bool convertToHtml = docsCompiler.ConvertToHtml;
            if (!File.Exists(fullPath))
                throw new FileNotFoundException(string.Format("{0} was not found", fullPath));

            var contents = File.ReadAllText(fullPath);
            contents = CodeBlockFinder.Replace(
                contents, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value, convertToHtml));
            contents = CodeFinder.Replace(
                contents,
                match =>
                GenerateCodeBlockFromFile(match.Groups[1].Value.Trim(), docsCompiler.CodeSamplesPath, convertToHtml));

            if (folder != null)
                contents = FilesListFinder.Replace(contents, match => GenerateFilesList(folder, false));

            if (convertToHtml)
            {
                contents = contents.ResolveMarkdown(
                    docsCompiler.Output,
                    !string.IsNullOrWhiteSpace(docsCompiler.Output.RootUrl) ? trail : string.Empty,
                    versionUrl);
            }

            contents = NotesFinder.Replace(
                contents, match => InjectNoteBlocks(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));

            return contents;
        }
Exemple #2
0
		public void SaveImage(Folder ofFolder, string fullFilePath)
		{
			var outputPath = Path.Combine(OutputPath, ofFolder.Trail, ofFolder.Slug, "images");
			if (!Directory.Exists(outputPath))
				Directory.CreateDirectory(outputPath);

			File.Copy(fullFilePath, Path.Combine(outputPath, Path.GetFileName(fullFilePath)), true);
		}
Exemple #3
0
        private void CompileFolder(Folder folder, string versionUrl)
        {
            var fullFolderSlug = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            var fullPath = Path.Combine(_fullPath, fullFolderSlug);
            if (!File.Exists(Path.Combine(fullPath, DocsListFileName)))
                return;

            var docs = DocsListParser.Parse(Path.Combine(fullPath, DocsListFileName)).ToArray();
            foreach (var item in docs)
            {
                if (item.Slug != null)
                    item.Slug = item.Slug.TrimStart('\\', '/');
                item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
                folder.Items.Add(item);

                var document = item as Document;
                if (document != null)
                {
                    var strippedSlug = document.Slug.Replace(".markdown", string.Empty);
                    document.Content = DocumentationParser.Parse(this, null, Path.Combine(fullPath, document.Slug), document.Trail, versionUrl);
                    document.Slug = strippedSlug;
                    Output.SaveDocItem(document);
                    continue;
                }

                var subFolder = item as Folder;
                if (subFolder != null)
                {
                    CompileFolder(subFolder, versionUrl);
                    continue;
                }
            }

            var contents = DocumentationParser.Parse(this, folder, Path.Combine(fullPath, "index.markdown"),
                                                     string.IsNullOrWhiteSpace(folder.Trail) ? folder.Slug : folder.Trail + "/" + folder.Slug,
                                                     versionUrl);
            Output.SaveDocItem(new Document
            {
                Title = folder.Title,
                Content = contents,
                Trail = fullFolderSlug,
                Slug = "index"
            });

            // Copy images
            var imagesPath = Path.Combine(fullPath, "images");
            if (Directory.Exists(imagesPath))
            {
                var images = Directory.GetFiles(imagesPath);
                foreach (var image in images)
                {
                    var imageFileName = Path.GetFileName(image);
                    if (imageFileName == null) continue;
                    Output.SaveImage(folder, image);
                }
            }
        }
Exemple #4
0
        private void CompileFolder(Folder folder)
        {
            var fullPath = Path.Combine(_fullPath, folder.Trail, folder.Slug ?? string.Empty);
            if (!File.Exists(Path.Combine(fullPath, DocsListFileName)))
                return;

            var outputPath = Path.Combine(_outputPath, folder.Trail, folder.Slug ?? string.Empty);
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            CompileFile(folder.Title, Path.Combine(fullPath, "index.markdown"), Path.Combine(outputPath, "index.html"));

            // Copy images
            // TODO: Thumbs, lightbox
            var imagesPath = Path.Combine(fullPath, "images");
            if (Directory.Exists(imagesPath))
            {
                if (!Directory.Exists(Path.Combine(outputPath, "images")))
                    Directory.CreateDirectory(Path.Combine(outputPath, "images"));

                var images = Directory.GetFiles(imagesPath);
                foreach (var image in images)
                {
                    var imageFileName = Path.GetFileName(image);
                    if (imageFileName == null) continue;
                    File.Copy(image, Path.Combine(outputPath, "images", imageFileName), true);
                }
            }

            var docs = DocsListParser.Parse(Path.Combine(fullPath, DocsListFileName));

            foreach (var item in docs)
            {
                if (item.Slug != null)
                    item.Slug = item.Slug.TrimStart('\\', '/');
                item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
                folder.Items.Add(item);

                var document = item as Document;
                if (document != null)
                {
                    CompileFile(document.Title, Path.Combine(fullPath, document.Slug), Path.Combine(outputPath, document.Slug.Replace(".markdown", ".html")));
                    continue;
                }

                var subFolder = item as Folder;
                if (subFolder != null)
                {
                    CompileFolder(subFolder);
                    continue;
                }
            }
        }
Exemple #5
0
        public void SaveImage(Folder ofFolder, string fullFilePath)
        {
            var outputPath = Path.Combine(OutputPath, ofFolder.Trail, ofFolder.Slug, "images");
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
                
            var destFileName = Path.Combine(outputPath, Path.GetFileName(fullFilePath));

            //Console.WriteLine("Copying {0} to {1}", fullFilePath, destFileName);

            File.Copy(fullFilePath, destFileName, true);
        }
        private static string GenerateFilesList(Folder folder, bool recursive)
        {
            if (folder.Items == null)
                return string.Empty;
 
            var sb = new StringBuilder();
            foreach (var item in folder.Items)
            {
                sb.AppendFormat("* [{0}]({1})", item.Title, item.Slug);
                sb.AppendLine();
            }

            return sb.ToString();
        }
Exemple #7
0
        public static string Parse(Compiler docsCompiler, Folder folder, string fullPath, string currentSlug)
        {
            if (!File.Exists(fullPath))
                throw new FileNotFoundException(string.Format("{0} was not found", fullPath));

            var contents = File.ReadAllText(fullPath);
            contents = CodeBlockFinder.Replace(contents, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value));
            contents = CodeFinder.Replace(contents, match => GenerateCodeBlockFromFile(match.Groups[1].Value.Trim(), docsCompiler.CodeSamplesPath));

            if (folder != null)
            {
                contents = FilesListFinder.Replace(contents, match => GenerateFilesList(folder, false));
            }

            if (docsCompiler.Output.RootUrl == null)
                contents = contents.ResolveMarkdown(docsCompiler.Output, currentSlug);
            else
                contents = contents.ResolveMarkdown(docsCompiler.Output, currentSlug);

            contents = NotesFinder.Replace(contents, match => InjectNoteBlocks(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));

            return contents;
        }
Exemple #8
0
        /// <summary>
        /// TCopy images.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        private void CopyImages(Folder folder, string fullPath)
        {
            // Copy images
            var imagesPath = Path.Combine(fullPath, "images");
            if (!Directory.Exists(imagesPath))
                return;
 
            var images = Directory.GetFiles(imagesPath);
            foreach (var image in images)
            {
                var imageFileName = Path.GetFileName(image);
                if (imageFileName == null)
                {
                    continue;
                }

                this.Output.SaveImage(folder, image);
            }
        }
Exemple #9
0
        /// <summary>
        /// Processes an item.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string ProcessItem(Folder folder, string versionUrl, IDocumentationItem item, string fullPath)
        {
            if (item.Slug != null)
                item.Slug = item.Slug.TrimStart('\\', '/');
 
            item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            folder.Items.Add(item);

            var document = item as Document;
            if (document != null)
                return this.CompileDocument(versionUrl, document, fullPath);
 
            var subFolder = item as Folder;
            if (subFolder != null)
                return CompileFolder(subFolder, versionUrl);
 
            return string.Empty;
        }
Exemple #10
0
 /// <summary>
 /// Process index item.
 /// </summary>
 /// <param name="folder">
 /// The folder.
 /// </param>
 /// <param name="versionUrl">
 /// The version url.
 /// </param>
 /// <param name="fullPath">
 /// The full path.
 /// </param>
 /// <param name="fullFolderSlug">
 /// The full folder slug.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private string ProcessIndexItem(Folder folder, string versionUrl, string fullPath, string fullFolderSlug)
 {
     var contents = DocumentationParser.Parse(
         this,
         folder,
         Path.Combine(fullPath, "index.markdown"),
         string.IsNullOrWhiteSpace(folder.Trail) ? folder.Slug : folder.Trail + "/" + folder.Slug,
         versionUrl);
     this.Output.SaveDocItem(
         new Document { Title = folder.Title, Content = contents, Trail = fullFolderSlug, Slug = "index" });
     return contents;
 }
Exemple #11
0
        /// <summary>
        /// Process item as markdown.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <param name="fullFolderSlug">
        /// The full folder slug.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string ProcessAsMarkdown(Folder folder, string versionUrl, string fullPath, string fullFolderSlug)
        {
            var output = string.Empty;
            output += this.ProcessIndexItem(folder, versionUrl, fullPath, fullFolderSlug);

            var docs = DocsListParser.Parse(Path.Combine(fullPath, DocsListFileName)).ToArray();
            foreach (var item in docs)
            {
                Console.WriteLine("CompileFolder - processing item {0}", item.Trail);
                output += this.ProcessItem(folder, versionUrl, item, fullPath);
            }

            this.CopyImages(folder, fullPath);
            return output;
        }
Exemple #12
0
        /// <summary>
        /// Processes item as HTML.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <param name="fullPath">
        /// The full path.
        /// </param>
        /// <param name="fullFolderSlug">
        /// The full folder slug.
        /// </param>
        private void ProcessAsHtml(Folder folder, string versionUrl, string fullPath, string fullFolderSlug)
        {
            var docs = DocsListParser.Parse(Path.Combine(fullPath, DocsListFileName)).ToArray();
            foreach (var item in docs)
            {
                Console.WriteLine("CompileFolder - processing item {0}", item.Trail);
                this.ProcessItem(folder, versionUrl, item, fullPath);
            }

            var contents = DocumentationParser.Parse(
                this,
                folder,
                Path.Combine(fullPath, "index.markdown"),
                string.IsNullOrWhiteSpace(folder.Trail) ? folder.Slug : folder.Trail + "/" + folder.Slug,
                versionUrl);
            this.Output.SaveDocItem(
                new Document { Title = folder.Title, Content = contents, Trail = fullFolderSlug, Slug = "index" });

            this.CopyImages(folder, fullPath);
        }
Exemple #13
0
        /// <summary>
        /// Compiles the folder.
        /// </summary>
        /// <param name="folder">
        /// The folder.
        /// </param>
        /// <param name="versionUrl">
        /// The version url.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string CompileFolder(Folder folder, string versionUrl)
        {
            var fullFolderSlug = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            var fullPath = Path.Combine(this.destinationFullPath, fullFolderSlug);

            if (!File.Exists(Path.Combine(fullPath, DocsListFileName)))
                return string.Empty;
 
            if (this.ConvertToHtml)
            {
                this.ProcessAsHtml(folder, versionUrl, fullPath, fullFolderSlug);
                return string.Empty;
            }

            if (this.Output.ContentType == OutputType.Markdown)
                return this.ProcessAsMarkdown(folder, versionUrl, fullPath, fullFolderSlug);
 
            return string.Empty;
        }