Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void ShouldBeAbleToCompileSourceWithDustScript()
        {
            string source   = "Hello {Name}";
            string compiled = DustScript.Compile(source, "test");

            OutLine(compiled);
        }
Esempio n. 3
0
        public void ShouldBeAbleToRenderWithDustScript()
        {
            string source   = "Hello {Name}";
            string compiled = DustScript.Compile(source, "test");
            string output   = DustScript.Render(compiled, "test", new { Name = "Bananas" });

            OutLine(output);
        }
Esempio n. 4
0
        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);
        }