-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve readability of the project
* refactor: remove duplicate parsing in ArgsParser * refactor: extract to IndexFile from Generator * style: fix formatting and spelling * refactor: rename ArgsParser to CliArgs The name `ArgsParser` does not represent what the class does. The class stored parsed values from Cli, and it doesn't expose any methods to work with args
- Loading branch information
1 parent
d96a7ab
commit 9c07965
Showing
5 changed files
with
98 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Text; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace paper_csharp.modules.file_parser | ||
{ | ||
|
||
/// <summary> | ||
/// A collection of methods to generate an index file for a given dir path | ||
/// </summary> | ||
public class IndexFile | ||
{ | ||
/// <summary> | ||
/// Path to the directory with .html files to generate index | ||
/// </summary> | ||
public string SourceDirPath; | ||
|
||
public IndexFile(string sourceDirPath) | ||
{ | ||
SourceDirPath = sourceDirPath; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Create the index files with links to all html files in the output directory | ||
/// </summary> | ||
public void Generate() | ||
{ | ||
var indexFile = File.Create(Path.Join(this.SourceDirPath, "index.html")); | ||
|
||
var linkList = ReadAllFilePaths(this.SourceDirPath).Select(filePath => $"<a style=\"display:block\" href=\"{filePath}\">{Path.GetFileNameWithoutExtension(filePath)}</a>"); | ||
|
||
indexFile.Write(Encoding.ASCII.GetBytes(string.Join("\n", linkList))); | ||
|
||
indexFile.Close(); | ||
return; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Returns all paths to .html files | ||
/// </summary> | ||
private List<string> ReadAllFilePaths(string path) | ||
{ | ||
List<string> paths = new List<string>(); | ||
|
||
foreach (string subpath in Directory.GetFileSystemEntries(path)) | ||
{ | ||
if (Directory.Exists(subpath)) | ||
{ | ||
paths.AddRange(this.ReadAllFilePaths(subpath)); | ||
continue; | ||
} | ||
|
||
if (File.Exists(subpath) && Path.GetExtension(subpath) == ".html" && Path.GetFileName(subpath) != "index.html") | ||
{ | ||
paths.Add(Path.GetRelativePath(this.SourceDirPath, subpath)); | ||
continue; | ||
} | ||
|
||
} | ||
|
||
return paths; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9c07965
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: