// /** // * File: HtmlTests.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using NUnit.Framework; using System; using ln.templates.html; using System.IO; namespace ln.templates.test { [TestFixture()] public class HtmlTests { [Test()] public void TestCase() { html.TemplateReader templateReader = new html.TemplateReader(); templateReader.Read("\n\n\n Hello\n\n\n

Welcome to this example.

\n

{{ 'Ich bin ein ScriptText!' }}

\n

DateTime: {{ Date }}

\n

Ein bisschen JavaScript: {{ 5 + ' mal ' + 5 + ' = ' + (5*5) }}

\n\n"); Console.WriteLine("Source rendered:\n{0}", templateReader.Document.ToString()); StringWriter stringWriter = new StringWriter(); RenderContext renderContext = new RenderContext(stringWriter); renderContext.SetScriptObject("Date", DateTime.Now); templateReader.TemplateDocument.RenderTemplate(renderContext); Console.WriteLine("Template rendered:\n{0}", stringWriter.ToString()); } [Test()] public void TestFileSystemTemplateSource() { if (File.Exists("templates.tst/frame.html")) File.Delete("templates.tst/frame.html"); if (File.Exists("templates.tst/head.html")) File.Delete("templates.tst/head.html"); Directory.CreateDirectory("templates.tst"); using (FileStream fs = new FileStream("templates.tst/frame.html", FileMode.CreateNew)) using (TextWriter tw = new StreamWriter(fs)) { tw.Write(""); tw.Flush(); } using (FileStream fs = new FileStream("templates.tst/head.html", FileMode.CreateNew)) using (TextWriter tw = new StreamWriter(fs)) { tw.Write("{{ title }}"); tw.Flush(); } FileSystemTemplateSource fileSystemTemplateSource = new FileSystemTemplateSource("templates.tst"); TemplateDocument templateDocument = fileSystemTemplateSource.GetTemplateByPath("frame.html"); StringWriter stringWriter = new StringWriter(); RenderContext renderContext = new RenderContext(stringWriter,fileSystemTemplateSource); templateDocument.RenderTemplate(renderContext); Console.WriteLine("Document rendered to: {0}", stringWriter.ToString()); } } }