Beispiel #1
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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Executes the specified input and returns the resulting output
        /// </summary>
        /// <param name="input"></param>
        /// <param name="hashKey"></param>
        /// <param name="options">Arguments to pass to the template engine including the Model</param>
        /// <param name="inspector"></param>
        /// <param name="assembliesToReference"></param>
        /// <returns></returns>
        public string Execute(TextReader input, string hashKey = null, object options = null, Action <string> inspector = null, params Assembly[] assembliesToReference)
        {
            Assembly templateAssembly;

            if (!string.IsNullOrEmpty(hashKey) && CompiledTemplates.ContainsKey(hashKey))
            {
                templateAssembly = CompiledTemplates[hashKey];
            }
            else
            {
                if (assembliesToReference == null || assembliesToReference.Length == 0)
                {
                    assembliesToReference = GetDefaultAssembliesToReference();
                }
                templateAssembly = GetTemplateAssembly(input, hashKey, assembliesToReference, out CSharpCodeProvider codeProvider, out GeneratorResults results);
                OutputToInspector(inspector, codeProvider, results);
            }

            return(GetRazorTemplateResult(options, templateAssembly));
        }