コード例 #1
0
        // Once all of the code is finished highlighting, we can generate the HTML file
        // and write out the documentation. Pass the completed sections into the template
        // found in `Resources/Nocco.cshtml`
        public static string GenerateHtml(SourceInfo source, SourceModel model, IList<SourceInfo> sources)
        {
            var htmlTemplate = CreateHtmlTemplate();

            htmlTemplate.Title = Path.GetFileName(source.InputPath);
            htmlTemplate.PathToCss = Path.Combine(source.PathToRoot, "nocco.css").Replace('\\', '/');
            htmlTemplate.PathToJs = Path.Combine(source.PathToRoot, "prettify.js").Replace('\\', '/');
            htmlTemplate.GetSourcePath =
                s => Path.Combine(source.PathToRoot, Path.GetExtension(s) == ".html" ? s : (s + ".html").Substring(2)).Replace('\\', '/');
            htmlTemplate.Sources = sources;
            htmlTemplate.Model = model;

            htmlTemplate.Execute();

            return htmlTemplate.GetBuffer();
        }
コード例 #2
0
ファイル: Nocco.cs プロジェクト: sfadeev/renocco
        private static IList<SourceInfo> CollectSourceInfos(IEnumerable<string> files)
        {
            // Don't include certain directories
            var foldersToExclude = new[] { "\\docs", "\\bin", "\\obj", "\\packages", "\\.nuget", "\\.git", "\\.svn" };

            var result = new List<SourceInfo>();

            var index = new SourceInfo
            {
                InputPath = Path.Combine(_options.InputDir, "index.html").Replace('\\', '/'),
                Transformer = new IndexTransformer()
            };

            int depth;
            var destination = GetDestination(index.InputPath, out depth);
            var pathToRoot = string.Concat(Enumerable.Repeat(".." + Path.DirectorySeparatorChar, depth));

            index.OutputPath = destination;
            index.PathToRoot = pathToRoot;

            result.Add(index);

            foreach (var filename in files)
            {
                if (foldersToExclude.Any(folder => Path.GetDirectoryName(filename).Contains(folder)))
                {
                    continue;
                }

                if (Directory.Exists(filename))
                {
                    result.Add(new SourceInfo { InputPath = filename });
                    continue;
                }

                var transformer = GetTransformer(filename);

                if (transformer == null) continue;

                // Check if the file extension should be ignored
                if (transformer.ShouldIgnore(filename)) continue;

                destination = GetDestination(filename, out depth);
                pathToRoot = string.Concat(Enumerable.Repeat(".." + Path.DirectorySeparatorChar, depth));

                result.Add(new SourceInfo
                {
                    Transformer = transformer,
                    InputPath = filename,
                    OutputPath = destination,
                    PathToRoot = pathToRoot
                });
            }

            return result;
        }