/// <summary> /// Generate the documentation for all files in <paramref name="job"/> /// </summary> /// <param name="job"></param> public static void ProcessJob(NoccoJob job) { Helpers.LogMessages( "Starting new job: ", "Path: " + job.JobBaseDirectory.ToString(), "Language: " + job.Language.Name ); Helpers.LogMessages("Destination folder: " + job.OuputFolder.ToString()); //truncate output to the best of our abilities if (job.TruncateOutputDirectory) Helpers.TryDeleteFolderRecursively(job.OuputFolder.FullName); //create docs folder if (!job.OuputFolder.Exists) job.OuputFolder.Create(); //deliver resources by cloning the directory string AbsoluteResourceDirectory = App.ResolveDirectory(App.Settings.ResourceDirectory); foreach (string file in Directory.GetFiles(AbsoluteResourceDirectory, "*.*", SearchOption.AllDirectories)) { string destFile = file.Replace(AbsoluteResourceDirectory, job.OuputFolder.FullName); string destDir = Path.GetDirectoryName(destFile); if (!Directory.Exists(destDir)) Directory.CreateDirectory(destDir); File.Copy(file, destFile, true); } Helpers.LogMessages("Cloned base resources to destination"); //summary of the generated documents List<DocumentSummary> GeneratedDocuments = new List<DocumentSummary>(); //get the candidates List<FileInfo> JobCandidates = job.GetCandidates().ToList(); //process each candidate file foreach (FileInfo candidate in JobCandidates) { GeneratedDocuments.Add(GenerateDocumentHtml(candidate, job.OuputFolder, job, JobCandidates.Except(new[] { candidate }))); } if (job.GenerateIndexFile) { //create the index file GenerateIndexHtml(job.OuputFolder, job, GeneratedDocuments); } }
/// <summary> /// Generates the HTML result for a single source file. /// </summary> /// <param name="sourceFile"></param> /// <param name="docsDirectory"></param> /// <param name="job"></param> /// <returns>Generated document FileInfo</returns> private static DocumentSummary GenerateDocumentHtml(FileInfo sourceFile, DirectoryInfo docsDirectory, NoccoJob job, IEnumerable<FileInfo> othersInSameJob) { DocumentSummary summary = new DocumentSummary() { DocumentFile = sourceFile }; var destinationFile = GetAbsoluteDocDestination(sourceFile, docsDirectory, job.JobBaseDirectory); //the relative path from the destination file to the documation folder string docsRelative = Helpers.GetPathRelativeTo(destinationFile.Directory, docsDirectory); //get the opposite direction for the index page summary.RelativeUri = Helpers.ConvertPathSeparator(Path.Combine( Helpers.GetPathRelativeTo(docsDirectory, destinationFile.Directory), destinationFile.Name)); AbDocumentTemplate TemplateGenerator = Helpers.GetTemplateGenerator<AbDocumentTemplate>( new FileInfo(App.ResolveDirectory(App.Settings.DocumentTemplateFile))); //setup template generator settings TemplateGenerator.Title = sourceFile.Name; summary.Title = TemplateGenerator.Title; if (job.GenerateInlineIndex) { //list of other files in this same job, relative to myself TemplateGenerator.OtherDocumentsInJob = othersInSameJob.DefaultIfEmpty() .Select(o => { var abs = GetAbsoluteDocDestination(o, docsDirectory, job.JobBaseDirectory); return Path.Combine(Helpers.GetPathRelativeTo(destinationFile.Directory, abs.Directory), abs.Name); }) .ToArray(); } TemplateGenerator.Sections = ParseSections(sourceFile, job.Language, summary); TemplateGenerator.DocsRelative = docsRelative; if (job.GenerateIndexFile) { TemplateGenerator.IndexFile = Helpers.ConvertPathSeparator(Path.Combine(docsRelative, job.IndexFilename)); } //generate documenation file TemplateGenerator.Generate(destinationFile.FullName); return summary; }
/// <summary> /// Generates the index HTML for a job. /// </summary> /// <param name="sourceFile"></param> /// <param name="docsDirectory"></param> /// <param name="job"></param> private static void GenerateIndexHtml(DirectoryInfo docsDirectory, NoccoJob job, ICollection<DocumentSummary> generatedDocuments) { //the absolute destination path for the index file var destinationFile = new FileInfo(Path.Combine(docsDirectory.FullName, job.IndexFilename)); //the relative path from the destination file to the documation folder string docsRelative = Helpers.GetPathRelativeTo(destinationFile.Directory, docsDirectory); AbIndexTemplate TemplateGenerator = Helpers.GetTemplateGenerator<AbIndexTemplate>( new FileInfo(App.ResolveDirectory(App.Settings.IndexTemplateFile))); //setup template generator settings TemplateGenerator.Title = job.ProjectName ?? "index"; TemplateGenerator.DocsRelative = docsRelative; var documents = generatedDocuments.ToArray(); TemplateGenerator.GeneratedDocuments = documents; //generate documenation file TemplateGenerator.Generate(destinationFile.FullName); }
static void Main(string[] args) { var options = new CommandLineOptions(); var parser = new CommandLineParser(new CommandLineParserSettings { CaseSensitive = false, IgnoreUnknownArguments = true }); var res = parser.ParseArguments(args, options); if (!res) { Console.WriteLine("check your parameters and try again"); return; } //check to see if we have a language directive for the specified type LanguageConfig Language = Helpers.GetLanguage(options.FileType); if (Language == null) { Console.WriteLine("We don't know how to handle the requested type. You can add a definition to the language.json file and try again."); Environment.Exit(1); } //override settings App.Settings.BeVerbose = options.Verbose; DirectoryInfo OutputDirectory = null; if (!string.IsNullOrWhiteSpace(options.OutputFolder)) { if (Path.IsPathRooted(options.OutputFolder)) OutputDirectory = new DirectoryInfo(options.OutputFolder); else OutputDirectory = new DirectoryInfo(Path.Combine(options.Path, options.OutputFolder)); } else { OutputDirectory = new DirectoryInfo(Path.Combine(options.Path, App.Settings.DefaultDocsFolderName)); } //get a new job NoccoJob Job = new NoccoJob(new DirectoryInfo(options.Path), Language, options.FileType, OutputDirectory) { ProjectName = options.ProjectName, IndexFilename = !string.IsNullOrWhiteSpace(options.IndexFilename) ? options.IndexFilename : App.Settings.DefaultIndexFileName, GenerateInlineIndex = options.GenerateInlineIndex, GenerateIndexFile = options.GenerateFullIndex, TruncateOutputDirectory = options.Truncate }; //begin processing Nocco.ProcessJob(Job); Helpers.LogMessages("Finished processing"); Environment.Exit(0); }