public void Write(string outputDirectory, IPokemonSaveInfo saveInfo) { Directory.CreateDirectory(outputDirectory); string titleForPostFile = $"{DateTime.Now:yyyy-MM-dd}-{_title.Replace('_', '-').Replace(' ', '-')}"; string outputFile = Path.Combine(outputDirectory, $"{titleForPostFile}.md"); var data = new { Title = _title, Date = DateTime.Now.ToString("yyyy-MM-dd HH:mm"), BoxPokemonCount = saveInfo.BoxPokemon.Count(), Model = saveInfo }; foreach (string partialFile in Directory.EnumerateFiles(Path.Combine("Resources", "blogpostpartials"))) { string partialFileName = Path.GetFileNameWithoutExtension(partialFile); Handlebars.RegisterTemplate(partialFileName, File.ReadAllText(partialFile)); } var template = Handlebars.Compile(File.ReadAllText(Path.Combine("Resources", "blogpost.hb"))); using (StreamWriter outputWriter = new StreamWriter(outputFile)) { outputWriter.Write(template(data)); } }
public void Write(string outputDirectory, IPokemonSaveInfo saveInfo) { AppDomain domain = null; if (AppDomain.CurrentDomain.IsDefaultAppDomain()) { // RazorEngine cannot clean up from the default appdomain... Console.WriteLine("Switching to secound AppDomain, for RazorEngine..."); AppDomainSetup adSetup = new AppDomainSetup(); adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; var current = AppDomain.CurrentDomain; domain = AppDomain.CreateDomain( "PokeSiteDomain", null, current.SetupInformation, new PermissionSet(PermissionState.Unrestricted)); } Directory.CreateDirectory(outputDirectory); string outputFile = Path.Combine(outputDirectory, "index.html"); string template = File.ReadAllText("Resources/template.cshtml"); DynamicViewBag viewBag = new DynamicViewBag(new Dictionary <string, object>() { ["Title"] = Title }); IEnumerable <string> cssFiles = CopyCSS(outputDirectory); viewBag.AddValue("CSSFiles", cssFiles.ToList()); // Compile and run Razor template using (StreamWriter outputWriter = new StreamWriter(outputFile)) { Engine.Razor.RunCompile(template, "test", outputWriter, saveInfo.GetType(), saveInfo, viewBag); } if (domain != null) { // RazorEngine will cleanup. AppDomain.Unload(domain); } }
public JekyllMarkdownGenerator(string pageTitle, IPokemonSaveInfo saveInfo) { _title = pageTitle; }
public HtmlGenerator(string pageTitle, IPokemonSaveInfo saveInfo) { _title = pageTitle; }