public void Input_Should_Expect_Xaml(string input, string outputXaml) { var templator = new Templator(); var result = templator.Generate(input, "Test").Last().Xaml.Content; result.Should().Contain(outputXaml); }
/// <param name="date">The date to generate the defaults for.</param> static async Task Main(string?date = null) { var challengeDate = string.IsNullOrWhiteSpace(date) ? SystemClock.Instance.InTzdbSystemDefaultZone().GetCurrentDate() : LocalDatePattern.Iso.Parse(date).Value; var templator = new Templator(challengeDate); await templator.Execute(); }
public void Input_Should_Contain_CSharp(string input, string outputCSharp) { var templator = new Templator(); templator.Generate(input, "Test").First().CSharp.Content.Should().Contain(outputCSharp); //var result2 = Regex.Replace(result, @"\s+", ""); //Console.WriteLine(result); //result2.Should().Be(Regex.Replace(outputCSharp, @"\s+", "")); }
void LoadTemplateFromFile(string fn) { Templator pa = new Templator(); pa.FileName = fn; pa.IsSubTemplate = IsSubTemplate; pa.Load(); TemplateContentTextBox.Value = We7Helper.FilterXMLChars(pa.BodyContent); HeaderTextBox.Text = pa.HeadContent; BodyText = pa.BodyText; }
private static void GenerateInvoice() { var data = GetInvoiceData(); var cfg = new PdfConfig { FontPaths = new [] { "/Library/Fonts" } // this is configured for mac, on windows you have to change it }; var bytes = Templator.Create("Template/invoice.xml") .UsePdfRenderer(cfg) .Render(data); File.WriteAllBytes("Result/invoice.pdf", bytes); }
public async Task <IActionResult> OnGetAsync() { var cfg = new PdfConfig { FontPaths = new[] { "/Library/Fonts" }, }; var bytes = Templator .Create("print.xml") .UsePdfRenderer(cfg) .Render(GetData()); await Task.CompletedTask; return(this.File(bytes, "application/pdf")); }
public void StartSomeJob() { // Создание шаблона папок и файлов Templator.LoadTemplates(DirectoryPath, false, false); // Загрузка файлов с диска в буффер this.LoadFilesToBuffer(); // Просмотр буфера после загрузки туда файлов this.PrintFileBuffer(filebuffer, DirectoryPath); // Запуск отслеживателя изменений в директории и поддиректориях. Осторожно: работает асинхронно! this.StartWatchingForChangesInFiles(); // Тут всякие тесты лежат //this.StartTests(); }
public override bool Execute() { try { var templator = new Templator(); var files = Directory.GetFiles(Directory.GetCurrentDirectory(), Filter); foreach (var file in files) { Log.LogMessage(MessageImportance.High, $"Found file {file}"); var content = File.ReadAllText(file); var result = templator.Generate(content, Namespace); foreach (var generatedType in result) { Log.LogMessage(MessageImportance.High, $"Generated '{generatedType.CSharp.FileName}'"); Log.LogMessage(MessageImportance.High, $"Generated '{generatedType.Xaml.FileName}'"); var x = generatedType.Xaml; var c = generatedType.CSharp; var directory = Path.Combine(Directory.GetCurrentDirectory(), Folder); if (Directory.Exists(directory) != true) { Directory.CreateDirectory(directory); } File.WriteAllText(Path.Combine(directory, x.FileName), x.Content); File.WriteAllText(Path.Combine(directory, c.FileName), c.Content); } } } catch (Exception e) { Log.LogErrorFromException(e); return(false); } return(true); }
protected void SaveButton_Click(object sender, EventArgs e) { Templator tp = new Templator(); tp.Input = TemplateContentTextBox.Value; tp.IsSubTemplate = IsSubTemplate; tp.FromVisualBoxText(); tp.BodyText = BodyText; tp.HeadContent = HeaderTextBox.Text; tp.FileName = Server.MapPath(FileName); tp.Save(); Messages.ShowMessage("" + InfoKey + "文件成功保存!" + DateTime.Now.ToLongTimeString()); //记录日志 string content = string.Format("编辑{0}的内容", NameLabel.Text.Replace("编辑" + InfoKey + "", "")); AddLog("编辑" + InfoKey + "内容", content); }
void InitializeCssFile() { string cfn = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(ControlFile)); string tn = Path.GetFileNameWithoutExtension(Template); Templator tp = new Templator(); tp.FileName = Server.MapPath(TemplateHelper.GetTemplatePath(Template)); string cssFile = ""; WeControl c = new WeControl(); c.TagName = cfn; if (tp.CopyStyleSheet(c, ref cssFile)) { EditCssHyperLink.NavigateUrl = string.Format("manage/CssDetail.aspx?file={0}_{1}.css&folder=controls", tn, cfn); CssFileTextBox.Text = string.Format("{0}_{1}.css", tn, cfn); } StylePathTextBox.Text = Constants.TemplateUrlPath.Remove(0, 1) + "/styles"; }
public static Templator UsePdfRenderer(this Templator templator, PdfConfig cfg) { templator.SetRenderer(new PdfRenderer(cfg, templator.PrintTemplate)); return(templator); }
public static Templator UseSvgRenderer(this Templator templator, SvgConfig cfg) { templator.SetRenderer(new SvgRenderer(cfg)); return(templator); }
public void Output_Should_NOTContainXaml(string code, string xaml) { var templator = new Templator(); templator.Generate(code, "Test").First().Xaml.Content.Should().NotContain(xaml); }
public void Output_Should_NOTContainCSharp(string code, string csharp) { var templator = new Templator(); templator.Generate(code, "Test").First().CSharp.Content.Should().NotContain(csharp); }
public void Code_Should_ThrowCompileException(string code) { var tem = new Templator(); Assert.Throws <CompileException>(() => tem.Generate(code, "test")); }