Loading MustachioTemplatePreviewer.sln 0 → 100644 +25 −0 Original line number Diff line number Diff line Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30225.117 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MustachioTemplatePreviewer", "MustachioTemplatePreviewer\MustachioTemplatePreviewer.csproj", "{6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Release|Any CPU.ActiveCfg = Release|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8EAF52B3-5384-4542-8E2C-0EA4FE883549} EndGlobalSection EndGlobal MustachioTemplatePreviewer/MustachioTemplatePreviewer.csproj 0 → 100644 +14 −0 Original line number Diff line number Diff line <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="CommandLineParser" Version="2.8.0" /> <PackageReference Include="Mustachio" Version="2.1.0" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> </ItemGroup> </Project> MustachioTemplatePreviewer/Program.cs 0 → 100644 +119 −0 Original line number Diff line number Diff line //using Newtonsoft.Json.Converters; //using System; //using System.Collections.Generic; //using System.Dynamic; //using System.Text.RegularExpressions; //namespace TemplatePreviewer //{ // class Program // { // static void Main(string[] args) // { // string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); // Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+TemplatePreviewer)"); // string repoPath = appPathMatcher.Match(path).ToString(); // string templateDirectory = repoPath + "/dist"; // string payloadDirectory = repoPath + "/src/payloads"; // string previewsDirectory = repoPath + "/previews"; // Dictionary<string, string> templates = new Dictionary<string, string>(); // Dictionary<string, string> payloads = new Dictionary<string, string>(); // foreach (string s in System.IO.Directory.GetFiles(templateDirectory)) // { // System.IO.FileInfo fi = new System.IO.FileInfo(s); // templates.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); // } // foreach (string s in System.IO.Directory.GetFiles(payloadDirectory)) // { // System.IO.FileInfo fi = new System.IO.FileInfo(s); // payloads.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); // } // System.IO.Directory.CreateDirectory(previewsDirectory); // foreach (KeyValuePair<string, string> template in templates) // { // var expConverter = new ExpandoObjectConverter(); // var parsedTemplate = Mustachio.Parser.Parse(template.Value); // var preview = template.Value; // if (payloads.ContainsKey(System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json")) // { // dynamic templateModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandoObject>(payloads[System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json"], expConverter); // preview = parsedTemplate(templateModel); // } // System.IO.File.WriteAllText(previewsDirectory + "/" + template.Key, preview); // } // } // } //} using System; using System.Collections.Generic; using System.Dynamic; using CommandLine; using Newtonsoft.Json.Converters; namespace MustachioTemplatePreviewer { class MustachioTemplatePreviewer { public class Options { [Option('t', "templates", Required = true, HelpText = "The source directory containing the email templates.")] public string TemplatePath { get; set; } [Option('j', "json", Required = true, HelpText = "The directory containing JSON files with preview data for the email templates.")] public string JsonDataPath { get; set; } [Option('d', "destination", Required = true, HelpText = "The destination directory for the template preview.")] public string DestinationPath { get; set; } } static void Main(string[] args) { Parser.Default.ParseArguments<Options>(args) .WithParsed<Options>(o => { Console.WriteLine($"Source is {o.TemplatePath}"); Console.WriteLine($"JSON Data Path is {o.JsonDataPath}"); Console.WriteLine($"Destination is {o.DestinationPath}"); Dictionary<string, string> templates = new Dictionary<string, string>(); Dictionary<string, string> payloads = new Dictionary<string, string>(); foreach (string s in System.IO.Directory.GetFiles(o.TemplatePath)) { System.IO.FileInfo fi = new System.IO.FileInfo(s); templates.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); } foreach (string s in System.IO.Directory.GetFiles(o.JsonDataPath)) { System.IO.FileInfo fi = new System.IO.FileInfo(s); payloads.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); } System.IO.Directory.CreateDirectory(o.DestinationPath); foreach (KeyValuePair<string, string> template in templates) { var expConverter = new ExpandoObjectConverter(); var parsedTemplate = Mustachio.Parser.Parse(template.Value); var preview = template.Value; if (payloads.ContainsKey(System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json")) { dynamic templateModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandoObject>(payloads[System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json"], expConverter); preview = parsedTemplate(templateModel); } System.IO.File.WriteAllText(o.DestinationPath + "/" + template.Key, preview); } }); } } } No newline at end of file Loading
MustachioTemplatePreviewer.sln 0 → 100644 +25 −0 Original line number Diff line number Diff line Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30225.117 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MustachioTemplatePreviewer", "MustachioTemplatePreviewer\MustachioTemplatePreviewer.csproj", "{6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Debug|Any CPU.Build.0 = Debug|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Release|Any CPU.ActiveCfg = Release|Any CPU {6B5BDDB7-A948-4BAE-9814-222E1B2EDEF3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8EAF52B3-5384-4542-8E2C-0EA4FE883549} EndGlobalSection EndGlobal
MustachioTemplatePreviewer/MustachioTemplatePreviewer.csproj 0 → 100644 +14 −0 Original line number Diff line number Diff line <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="CommandLineParser" Version="2.8.0" /> <PackageReference Include="Mustachio" Version="2.1.0" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> </ItemGroup> </Project>
MustachioTemplatePreviewer/Program.cs 0 → 100644 +119 −0 Original line number Diff line number Diff line //using Newtonsoft.Json.Converters; //using System; //using System.Collections.Generic; //using System.Dynamic; //using System.Text.RegularExpressions; //namespace TemplatePreviewer //{ // class Program // { // static void Main(string[] args) // { // string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); // Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+TemplatePreviewer)"); // string repoPath = appPathMatcher.Match(path).ToString(); // string templateDirectory = repoPath + "/dist"; // string payloadDirectory = repoPath + "/src/payloads"; // string previewsDirectory = repoPath + "/previews"; // Dictionary<string, string> templates = new Dictionary<string, string>(); // Dictionary<string, string> payloads = new Dictionary<string, string>(); // foreach (string s in System.IO.Directory.GetFiles(templateDirectory)) // { // System.IO.FileInfo fi = new System.IO.FileInfo(s); // templates.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); // } // foreach (string s in System.IO.Directory.GetFiles(payloadDirectory)) // { // System.IO.FileInfo fi = new System.IO.FileInfo(s); // payloads.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); // } // System.IO.Directory.CreateDirectory(previewsDirectory); // foreach (KeyValuePair<string, string> template in templates) // { // var expConverter = new ExpandoObjectConverter(); // var parsedTemplate = Mustachio.Parser.Parse(template.Value); // var preview = template.Value; // if (payloads.ContainsKey(System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json")) // { // dynamic templateModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandoObject>(payloads[System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json"], expConverter); // preview = parsedTemplate(templateModel); // } // System.IO.File.WriteAllText(previewsDirectory + "/" + template.Key, preview); // } // } // } //} using System; using System.Collections.Generic; using System.Dynamic; using CommandLine; using Newtonsoft.Json.Converters; namespace MustachioTemplatePreviewer { class MustachioTemplatePreviewer { public class Options { [Option('t', "templates", Required = true, HelpText = "The source directory containing the email templates.")] public string TemplatePath { get; set; } [Option('j', "json", Required = true, HelpText = "The directory containing JSON files with preview data for the email templates.")] public string JsonDataPath { get; set; } [Option('d', "destination", Required = true, HelpText = "The destination directory for the template preview.")] public string DestinationPath { get; set; } } static void Main(string[] args) { Parser.Default.ParseArguments<Options>(args) .WithParsed<Options>(o => { Console.WriteLine($"Source is {o.TemplatePath}"); Console.WriteLine($"JSON Data Path is {o.JsonDataPath}"); Console.WriteLine($"Destination is {o.DestinationPath}"); Dictionary<string, string> templates = new Dictionary<string, string>(); Dictionary<string, string> payloads = new Dictionary<string, string>(); foreach (string s in System.IO.Directory.GetFiles(o.TemplatePath)) { System.IO.FileInfo fi = new System.IO.FileInfo(s); templates.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); } foreach (string s in System.IO.Directory.GetFiles(o.JsonDataPath)) { System.IO.FileInfo fi = new System.IO.FileInfo(s); payloads.Add(fi.Name, System.IO.File.ReadAllText(fi.FullName)); } System.IO.Directory.CreateDirectory(o.DestinationPath); foreach (KeyValuePair<string, string> template in templates) { var expConverter = new ExpandoObjectConverter(); var parsedTemplate = Mustachio.Parser.Parse(template.Value); var preview = template.Value; if (payloads.ContainsKey(System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json")) { dynamic templateModel = Newtonsoft.Json.JsonConvert.DeserializeObject<ExpandoObject>(payloads[System.IO.Path.GetFileNameWithoutExtension(template.Key) + ".json"], expConverter); preview = parsedTemplate(templateModel); } System.IO.File.WriteAllText(o.DestinationPath + "/" + template.Key, preview); } }); } } } No newline at end of file