public void SetUp() { RazorFormat.Instance = null; RazorFormat = new RazorFormat { PageBaseType = typeof(CustomRazorBasePage<>), VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), }.Init(); }
public void SetUp() { RazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>), VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), TemplateProvider = { CompileInParallelWithNoOfThreads = 0 }, }; RazorFormat.Init(); }
public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents, RazorPageType pageType) : this() { RazorFormat = razorFormat; FilePath = fullPath; Name = name; Contents = contents; PageType = pageType; }
public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents, RazorPageType pageType) : this() { RazorFormat = razorFormat; FilePath = fullPath; Name = name; Contents = contents; PageType = pageType; }
public void OnBeforeEachTest() { RazorFormat.Instance = null; razorFormat = new RazorFormat { VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), PageBaseType = typeof(CustomRazorBasePage<>), EnableLiveReload = false, }.Init(); razorFormat.AddFileAndPage("/views/TheLayout.cshtml", LayoutHtml); }
public void Simple_static_example() { RazorFormat.Instance = null; var razor = new RazorFormat { VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), EnableLiveReload = false, }.Init(); var page = razor.CreatePage("Hello @Model.Name! Welcome to Razor!"); var html = razor.RenderToHtml(page, new { Name = "World" }); html.Print(); Assert.That(html, Is.EqualTo("Hello World! Welcome to Razor!")); }
public void OnBeforeEachTest() { RazorFormat.Instance = null; var fileSystem = new InMemoryVirtualPathProvider(new BasicAppHost()); fileSystem.WriteFile("/views/TheLayout.cshtml", LayoutHtml); InitializeFileSystem(fileSystem); RazorFormat = new RazorFormat { VirtualFileSources = fileSystem, PageBaseType = typeof(CustomRazorBasePage<>), EnableLiveReload = false, PrecompilePages = PrecompileEnabled, WaitForPrecompilationOnStartup = WaitForPrecompileEnabled, }.Init(); }
public override async Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName) { if (HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes)) { return; } Filter?.Invoke(httpReq); httpRes.ContentType = MimeTypes.Html; if (RazorFormat == null) { RazorFormat = RazorFormat.Instance; } var contentPage = RazorPage ?? RazorFormat.GetContentPage(PathInfo); if (contentPage == null) { httpRes.StatusCode = (int)HttpStatusCode.NotFound; httpRes.EndHttpHandlerRequest(); return; } var model = Model; if (model == null) { httpReq.Items.TryGetValue("Model", out model); } if (model == null) { var modelType = RazorPage?.ModelType; model = modelType == null || modelType == typeof(DynamicRequestObject) ? null : await DeserializeHttpRequestAsync(modelType, httpReq, httpReq.ContentType); } using (RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes)) { httpRes.EndHttpHandlerRequest(skipHeaders: true); } }
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName) { httpRes.ContentType = ContentType.Html; if (RazorFormat == null) { RazorFormat = RazorFormat.Instance; } var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo); if (contentPage == null) { httpRes.StatusCode = (int)HttpStatusCode.NotFound; httpRes.EndHttpRequest(); return; } if (RazorFormat.WatchForModifiedPages) { RazorFormat.ReloadIfNeeeded(contentPage); } //Add good caching support //if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes)) // return; var model = Model; if (model == null) { httpReq.Items.TryGetValue("Model", out model); } if (model == null) { var modelType = RazorPage != null?RazorPage.GetRazorTemplate().ModelType : null; model = modelType == null || modelType == typeof(DynamicRequestObject) ? null : DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType); } RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes); }
public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName) { HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes); if (httpRes.IsClosed) { return; } httpRes.ContentType = MimeTypes.Html; if (RazorFormat == null) { RazorFormat = RazorFormat.Instance; } var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo); if (contentPage == null) { httpRes.StatusCode = (int)HttpStatusCode.NotFound; httpRes.EndHttpHandlerRequest(); return; } var model = Model; if (model == null) { httpReq.Items.TryGetValue("Model", out model); } if (model == null) { var modelType = RazorPage != null ? RazorPage.ModelType : null; model = modelType == null || modelType == typeof(DynamicRequestObject) ? null : DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType); } RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes); }
public ErrorViewPage(RazorFormat razorFormat, Exception ex) : base(razorFormat, null, DefaultPageName, ErrorPage(ex, DefaultContents)) { this.ex = ex; }
public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents) : this(razorFormat, fullPath, name, contents, RazorPageType.ViewPage) { }
public void TestFixtureSetUp() { this.products = new List<Product> { new Product("Pen", 1.99m), new Product("Glass", 9.99m), new Product("Book", 14.99m), new Product("DVD", 11.99m), }; productArgs = new { products = products }; var mvcRazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>) }; mvcRazorFormat.Init(); }
public string RenderToString <T>(T model) { var template = RazorFormat.ExecuteTemplate(model, this.PageName, this.Template); return(template.Result); }
public void TestFixtureSetUp() { var mvcRazorFormat = new RazorFormat(); mvcRazorFormat.Init(typeof(CustomRazorBasePage<>)); }
public IRazorTemplate ExecuteTemplate <T>(T model) { return(RazorFormat.ExecuteTemplate(model, this.PageName, this.Template)); }
public virtual RazorFormat Init() { if (Instance != null) { Log.Warn("RazorFormat plugin should only be initialized once"); if (ViewManager != null && PageResolver != null) return this; Log.Warn("Incomplete initialization, RazorFormat.Instance set but ViewManager/PageResolver is null"); } Instance = this; this.ViewManager = CreateViewManager(); this.PageResolver = CreatePageResolver(); this.ViewManager.Init(); if (EnableLiveReload.GetValueOrDefault()) { this.LiveReload = LiveReloadFactory(this.ViewManager); this.LiveReload.StartWatching(this.ScanRootPath); } return this; }
public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents) : this(razorFormat, fullPath, name, contents, RazorPageType.ViewPage) {}
public ErrorViewPage(RazorFormat razorFormat, Exception ex) : base(razorFormat, null, DefaultPageName, ErrorPage(ex, DefaultContents)) { this.ex = ex; }
public void TestFixtureSetUp() { mvcRazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>) }; mvcRazorFormat.Init(); }
/// <summary> /// Configure ServiceStack Razor views. /// </summary> /// <param name="container">The container.</param> private void ConfigureView(Container container) { // Enable ServiceStack Razor var razor = new RazorFormat(); razor.Deny.RemoveAt(0); Plugins.Add(razor); // Enable support for Swagger API browser Plugins.Add(new SwaggerFeature { UseBootstrapTheme = true, LogoUrl = "//lh6.googleusercontent.com/-lh7Gk4ZoVAM/AAAAAAAAAAI/AAAAAAAAAAA/_0CgCb4s1e0/s32-c/photo.jpg" }); //Plugins.Add(new CorsFeature()); // Uncomment if the services to be available from external sites }