Exemplo n.º 1
0
        private static void LoadFromFileSystem(string rootDir)
        {
            DirectoryInfo dir = new DirectoryInfo(rootDir);

            if (dir.Exists)
            {
                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    DustTemplate template = new DustTemplate(file);
                    template.Compile();
                }

                DirectoryInfo[] subDirs = dir.GetDirectories();
                foreach (DirectoryInfo subDir in subDirs)
                {
                    files = subDir.GetFiles();
                    foreach (FileInfo file in files)
                    {
                        string fileName = file.Name;
                        fileName = fileName.Substring(0, fileName.Length - file.Extension.Length);
                        string       templateName = string.Format("{0}_{1}", subDir.Name, fileName);
                        DustTemplate template     = new DustTemplate(file, templateName);
                        template.Compile();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void SetCompiledTemplate(DustTemplate template)
        {
            string name   = template.Name.ToLowerInvariant();
            string script = template.CompiledScript;

            if (!CompiledTemplates.ContainsKey(name))
            {
                CompiledTemplates.Add(name, script);
            }
            else
            {
                CompiledTemplates[name] = script;
            }
        }
Exemplo n.º 3
0
        public static void SetTemplate(DustTemplate template)
        {
            Args.ThrowIf <ArgumentNullException>(string.IsNullOrEmpty(template.Name), "template.Name must be specified");

            string name = template.Name.ToLowerInvariant();

            if (!Templates.ContainsKey(name))
            {
                Templates.Add(name, template);
            }
            else
            {
                Templates[name] = template;
            }
        }
Exemplo n.º 4
0
        private static StringBuilder GetTemplateScripts(string appName, string fileExt, string dustRoot)
        {
            DirectoryInfo dustDir = new DirectoryInfo(dustRoot);
            StringBuilder script  = new StringBuilder();

            if (dustDir.Exists)
            {
                FileInfo[] files = dustDir.GetFiles("*.{0}"._Format(fileExt));
                foreach (FileInfo file in files)
                {
                    DustTemplate template = new DustTemplate(file, "{0}{1}"._Format(appName, Path.GetFileNameWithoutExtension(file.FullName)));
                    script.AppendLine(Regex.Unescape(template.CompiledScript));
                }
            }
            return(script);
        }