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_")); }
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()); }
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); }
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()); }
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); }
public BrailRenamerAndTimeStamper(ViewCodeSource[] sources) { this.staticsources = true; this.sources = sources; }