public string Templates(string appName, bool min = false) { string result = string.Empty; if (_compiledTemplates == null) { _compiledTemplates = new Dictionary <string, string>(); } lock (_compiledTemplatesLock) { if (_compiledTemplates.ContainsKey(appName)) { result = _compiledTemplates[appName]; } else { // templates are in ~s:/dao/dust and ~a:/dao/dust string dustRelativePath = ViewsRelativePath; DirectoryInfo commonTemplateDir = new DirectoryInfo(ServerRoot.GetAbsolutePath(dustRelativePath)); Fs appFs = AppFs(appName); DirectoryInfo appTemplateDir = new DirectoryInfo(appFs.GetAbsolutePath(dustRelativePath)); StringBuilder tmp = new StringBuilder(); tmp.AppendLine(DustScript.CompileDirectory(commonTemplateDir)); tmp.AppendLine(DustScript.CompileDirectory(appTemplateDir)); _compiledTemplates[appName] = tmp.ToString(); result = _compiledTemplates[appName]; } } return(result); }
public void ShouldBeAbleToCompileSourceWithDustScript() { string source = "Hello {Name}"; string compiled = DustScript.Compile(source, "test"); OutLine(compiled); }
public void ShouldBeAbleToRenderWithDustScript() { string source = "Hello {Name}"; string compiled = DustScript.Compile(source, "test"); string output = DustScript.Render(compiled, "test", new { Name = "Bananas" }); OutLine(output); }
public void ShouldBeAbleToRenderTemplateFromDirectory() { // create a test directory DirectoryInfo root = new DirectoryInfo("c:\\temp\\{0}_"._Format(MethodBase.GetCurrentMethod().Name).RandomLetters(5)); // write test templates into it string source = "Hello {Name}"; source.SafeWriteToFile(Path.Combine(root.FullName, "test.dust")); // render something using the directory templates string output = DustScript.Render(root, "test", new { Name = "Gorilla" }); OutLine(output); }