コード例 #1
0
 public Type CompileSingle(ViewCodeSource source, ViewEngineOptions options) {
     var info = new ViewCompilerInfo
                    {
                        AssemblyName = Guid.NewGuid().ToString(),
                        InMemory = true,
                        Sources = new[] {source},
                        Options =  options,
                    };
     var assembly = this.Compile(info);
     return assembly.GetType(source.Key.Replace("/","_0_"));
 }
コード例 #2
0
        public void very_simple_bml_test() {
            var compiler = new BrailCompiler();
            var options = new MvcViewEngineOptions();
            var src = new ViewCodeSource
                          {
                              Key = "/test/x",
                              DirectContent =
                                  @"
bml:
    p : ""${i}"""
                          };
            var type = compiler.CompileSingle(src, options);
            Assert.NotNull(type);
            var view = (IView)type.create<BrailBase>(types: new Type[] { typeof(BooViewEngine) }, parameters: new object[] { null });
            var sw = new StringWriter();
            var vc = new ViewContext();
            vc.ViewData = new ViewDataDictionary();
            vc.ViewData["i"] = 3;
            view.Render(vc,sw);
            Assert.AreEqual("<p>3</p>",sw.ToString());
        }
コード例 #3
0
        public void ZE_BUG_can_call_compiler_in_bml_repeatedly()
        {
            var compiler = new BrailCompiler();
            var options = new MvcViewEngineOptions();
            var src = new ViewCodeSource
            {
                Key = "/test/x",
                DirectContent =
                    @"
bml:
    p : ""${i}"""
            };
            compiler.CompileSingle(src, options);
            src = new ViewCodeSource
            {
                Key = "/test/x2",
                DirectContent =
                    @"
bml:
    p : ""${i}"""
            };
            compiler.CompileSingle(src, options);
        }
コード例 #4
0
     public void very_simple_mixed_test()
     {
         var compiler = new BrailCompiler();
         var options = new MvcViewEngineOptions();
         var src = new ViewCodeSource
         {
             Key = "/test/x",
             DirectContent = @"<p>${i}</p>"
         };
         var src2 = new ViewCodeSource
         {
             Key = "/test/x2",
             DirectContent = @"bml:
 p : ""${i+i}"""
         };
         var info = new ViewCompilerInfo {Sources = new[] {src, src2}, InMemory = true, Options = options};
         var ass = compiler.Compile(info);
         var type1 = ass.GetType("/test/x".Replace("/", "_0_"));
         var type2 = ass.GetType("/test/x2".Replace("/", "_0_"));
         var view1 = (IView)type1.create<BrailBase>(types: new Type[] { typeof(BooViewEngine) }, parameters: new object[] { null });
         var view2 = (IView)type2.create<BrailBase>(types: new Type[] { typeof(BooViewEngine) }, parameters: new object[] { null });
         var sw = new StringWriter();
         var vc = new ViewContext();
         vc.ViewData = new ViewDataDictionary();
         vc.ViewData["i"] = 3;
         view1.Render(vc, sw);            
         Assert.AreEqual("<p>3</p>", sw.ToString());
         sw = new StringWriter();
         view2.Render(vc, sw);
         Assert.AreEqual("<p>6</p>", sw.ToString());
     }
コード例 #5
0
        public void timestamp_test()
        {
            var compiler = new BrailCompiler();
            var options = new MvcViewEngineOptions();
            var src = new ViewCodeSource
            {
                Key = "/test/x",
                DirectContent =
                    @"
bml:
    p : ""${i}"""
            };
            var type = compiler.CompileSingle(src, options);
            var attr = type.getFirstAttribute<TimeStampAttribute>();
            Assert.AreEqual(src.LastModified.ToString("dd.MM.yyyy HH:mm:ss"), attr.DateString);
        }
コード例 #6
0
 public BrailRenamerAndTimeStamper(ViewCodeSource[] sources) {
     this.staticsources = true;
     this.sources = sources;
 }