diff --git a/Ficdown.Console/App.config b/Ficdown.Console/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Ficdown.Console/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Ficdown.Console/Ficdown.Console.csproj b/Ficdown.Console/Ficdown.Console.csproj new file mode 100644 index 0000000..b774665 --- /dev/null +++ b/Ficdown.Console/Ficdown.Console.csproj @@ -0,0 +1,64 @@ + + + + + Debug + AnyCPU + {C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7} + Exe + Properties + Ficdown.Console + Ficdown.Console + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {780f652d-7541-4171-bb89-2d263d3961dc} + Ficdown.Parser + + + + + \ No newline at end of file diff --git a/Ficdown.Console/Program.cs b/Ficdown.Console/Program.cs new file mode 100644 index 0000000..f927c1f --- /dev/null +++ b/Ficdown.Console/Program.cs @@ -0,0 +1,153 @@ +namespace Ficdown.Console +{ + using System; + using System.IO; + using Microsoft.SqlServer.Server; + using Parser; + using Parser.Render; + + internal class Program + { + private static void Main(string[] args) + { + string infile = null; + string output = null; + string tempdir = null; + string format = null; + string author = null; + var debug = false; + + if (args.Length == 1) + { + if (args[0] == "/?" || args[0] == "/help" || args[0] == "-help" || args[0] == "--help") + { + ShowHelp(); + } + } + else if (args.Length > 1) + { + for (var i = 0; i < args.Length; i += 2) + { + switch (args[i]) + { + case "--format": + format = args[i + 1]; + break; + case "--in": + infile = args[i + 1]; + break; + case "--out": + output = args[i + 1]; + break; + case "--template": + tempdir = args[i + 1]; + break; + case "--author": + author = args[i + 1]; + break; + case "--debug": + i--; + debug = true; + break; + default: + Console.WriteLine(@"Unknown option: {0}", args[i]); + return; + } + } + } + else + { + ShowHelp(); + } + if (string.IsNullOrWhiteSpace(format)) + { + ShowHelp(); + return; + } + if (string.IsNullOrWhiteSpace(infile) || !File.Exists(infile)) + { + Console.WriteLine(@"Source file {0} not found.", infile); + return; + } + if (string.IsNullOrWhiteSpace(output)) + if (format == "html") + output = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"html"); + else if (format == "epub") + output = "output.epub"; + + if (!string.IsNullOrWhiteSpace(output) && (Directory.Exists(output) || File.Exists(output))) + { + Console.WriteLine(@"Specified output {0} already exists.", output); + return; + } + if (!string.IsNullOrWhiteSpace(tempdir)) + { + if (!Directory.Exists(tempdir)) + { + Console.WriteLine(@"Template directory {0} does not exist.", tempdir); + return; + } + if (!File.Exists(Path.Combine(tempdir, "index.html")) || + !File.Exists(Path.Combine(tempdir, "scene.html")) || + !File.Exists(Path.Combine(tempdir, "styles.css"))) + { + Console.WriteLine( + @"Template directory must contain ""index.html"", ""scene.html"", and ""style.css"" files."); + } + } + + var parser = new FicdownParser(); + var storyText = File.ReadAllText(infile); + + Console.WriteLine(@"Parsing story..."); + + var story = parser.ParseStory(storyText); + + IRenderer rend; + switch (format) + { + case "html": + Directory.CreateDirectory(output); + rend = (string.IsNullOrWhiteSpace(tempdir) + ? new HtmlRenderer() + : new HtmlRenderer(File.ReadAllText(Path.Combine(tempdir, "index.html")), + File.ReadAllText(Path.Combine(tempdir, "scene.html")), + File.ReadAllText(Path.Combine(tempdir, "styles.css")))); + break; + case "epub": + if (string.IsNullOrWhiteSpace(author)) + { + Console.WriteLine(@"Epub format requires the --author argument."); + return; + } + rend = (string.IsNullOrWhiteSpace(tempdir) + ? new EpubRenderer(author) + : new EpubRenderer(author, File.ReadAllText(Path.Combine(tempdir, "index.html")), + File.ReadAllText(Path.Combine(tempdir, "scene.html")), + File.ReadAllText(Path.Combine(tempdir, "styles.css")))); + break; + default: + ShowHelp(); + return; + } + + Console.WriteLine(@"Rendering story..."); + + rend.Render(story, output, debug); + + Console.WriteLine(@"Done."); + } + + private static void ShowHelp() + { + Console.WriteLine( + @"Usage: ficdown.exe + --format (html|epub) + --in ""/path/to/source.md"" + [--out ""/path/to/output""] + [--template ""/path/to/template/dir""] + [--author ""Author Name"" + [--debug]"); + } + } +} diff --git a/Ficdown.Console/Properties/AssemblyInfo.cs b/Ficdown.Console/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fef4676 --- /dev/null +++ b/Ficdown.Console/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Ficdown.Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Ficdown.Console")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("dafaccf5-0218-412d-b127-665c768f85ec")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Ficdown.Parser/Ficdown.Parser.csproj b/Ficdown.Parser/Ficdown.Parser.csproj index bb548a1..bc29e23 100644 --- a/Ficdown.Parser/Ficdown.Parser.csproj +++ b/Ficdown.Parser/Ficdown.Parser.csproj @@ -30,6 +30,12 @@ 4 + + ..\packages\Epub4Net.1.2.0\lib\net40\Epub4Net.dll + + + ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll + ..\packages\MarkdownSharp.1.13.0.0\lib\35\MarkdownSharp.dll @@ -67,11 +73,30 @@ + + + True + True + Template.resx + + + + + + + + + + + + ResXFileCodeGenerator + Template.Designer.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + views\index.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + views\scene.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + + assets\styles.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + \ No newline at end of file diff --git a/Ficdown.Parser/Render/Views/index.html b/Ficdown.Parser/Render/Views/index.html new file mode 100644 index 0000000..862043b --- /dev/null +++ b/Ficdown.Parser/Render/Views/index.html @@ -0,0 +1,14 @@ + + + + + + @Title + + + +

@Title

+ @Description +

Begin reading...

+ + \ No newline at end of file diff --git a/Ficdown.Parser/Render/Views/scene.html b/Ficdown.Parser/Render/Views/scene.html new file mode 100644 index 0000000..358f193 --- /dev/null +++ b/Ficdown.Parser/Render/Views/scene.html @@ -0,0 +1,12 @@ + + + + + + @Title + + + + @Content + + \ No newline at end of file diff --git a/Ficdown.Parser/packages.config b/Ficdown.Parser/packages.config index a4c765d..764fdfe 100644 --- a/Ficdown.Parser/packages.config +++ b/Ficdown.Parser/packages.config @@ -1,4 +1,6 @@  + + \ No newline at end of file diff --git a/Ficdown.sln b/Ficdown.sln index 31900f9..04e58fa 100644 --- a/Ficdown.sln +++ b/Ficdown.sln @@ -1,12 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30110.0 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ficdown.Parser", "Ficdown.Parser\Ficdown.Parser.csproj", "{780F652D-7541-4171-BB89-2D263D3961DC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ficdown.Parser.Tests", "Ficdown.Parser.Tests\Ficdown.Parser.Tests.csproj", "{756192E2-BA47-4850-8096-289D44878A7E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ficdown.Console", "Ficdown.Console\Ficdown.Console.csproj", "{C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {756192E2-BA47-4850-8096-289D44878A7E}.Debug|Any CPU.Build.0 = Debug|Any CPU {756192E2-BA47-4850-8096-289D44878A7E}.Release|Any CPU.ActiveCfg = Release|Any CPU {756192E2-BA47-4850-8096-289D44878A7E}.Release|Any CPU.Build.0 = Release|Any CPU + {C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C9D8CF8A-3CBE-4E45-91A3-37F8256A81A7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE