Exemplo n.º 1
0
        public void CompileBasicTemplate()
        {
            string code     = ParseTemplate();
            string assyCode = @"
using System;
using System.Text;
using Clifton.Core.TemplateEngine;

public class RuntimeCompiled : IRuntimeAssembly
{
  public string GetTemplate(params object[] paramList)
  {
";

            assyCode += code;
            assyCode += @"
    return sb.ToString();
  }
}";

            Assembly         assy = CreateAssembly(assyCode);
            IRuntimeAssembly t    = (IRuntimeAssembly)assy.CreateInstance("RuntimeCompiled");
            string           ret  = t.GetTemplate();

            Assert.AreEqual("  Literal\r\nA line with \" + str.ToString() + \" and \" + i.ToString() + \" with @ignore me\r\n", ret);
        }
Exemplo n.º 2
0
        private IRuntimeAssembly GetAssembly(string assyCode)
        {
            IRuntimeAssembly t = null;
            List <string>    errors;
            Assembly         assy = Compiler.Compile(assyCode, out errors, References);

            if (assy == null)
            {
                proc.IfNotNull((p) => errors.ForEach(errMsg => p.ProcessInstance <LoggerMembrane, ST_CompilerError>(err => err.Error = errMsg)));
                throw new TemplateEngineException(errors);
            }
            else
            {
                t = (IRuntimeAssembly)assy.CreateInstance("RuntimeCompiled");
            }

            return(t);
        }
Exemplo n.º 3
0
        //public bool IsCached(string template)
        //{
        //	return cachedAssemblies.ContainsKey(GetHash(template));
        //}

        public bool IsCached(string template, out IRuntimeAssembly t)
        {
            return(cachedAssemblies.TryGetValue(GetHash(template), out t));
        }
Exemplo n.º 4
0
 //public bool IsCached(string template)
 //{
 //    return cachedAssemblies.ContainsKey(GetHash(template));
 //}
 public bool IsCached(string template, out IRuntimeAssembly t)
 {
     return cachedAssemblies.TryGetValue(GetHash(template), out t);
 }