public override void Configure(Funq.Container container) { //http://stackoverflow.com/questions/13206038/servicestack-razor-default-page/13206221 var razor3 = new RazorFormat(); this.Plugins.Add(razor3); this.Plugins.Add(new RequestLogsFeature() { EnableErrorTracking = true, EnableResponseTracking = true, EnableSessionTracking = true, EnableRequestBodyTracking = true, RequiredRoles = new string[0] }); this.PreRequestFilters.Add(SimplePreRequestFilter); this.RequestFilters.Add(SimpleRequestFilter); //this.SetConfig( new EndpointHostConfig() // { // DebugMode = false, // } ); this.Routes.Add<HelloRequest>("/hello"); this.Routes.Add<HelloRequest>("/hello/{Name}"); this.Routes.Add<FooRequest>("/Foo/{WhatToSay}"); this.Routes.Add<DefaultViewFooRequest>("/DefaultViewFoo/{WhatToSay}"); }
public void SetUp() { RazorFormat.Instance = null; RazorFormat = new RazorFormat { PageBaseType = typeof(CustomRazorBasePage <>), VirtualFileSources = new InMemoryVirtualPathProvider(new BasicAppHost()), }.Init(); }
public void SetUp() { RazorFormat.Instance = null; RazorFormat = new RazorFormat { PageBaseType = typeof(CustomRazorBasePage <>), VirtualFileSources = new MemoryVirtualFiles(), }.Init(); }
public void SetUp() { RazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage <>), VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), TemplateProvider = { CompileInParallelWithNoOfThreads = 0 }, }; RazorFormat.Init(); }
public RazorFormat Create(string pageTemplate) { var razorFormat = new RazorFormat(); razorFormat.AddPage( new RazorPage(razorFormat, "/path/to/tpl", PageName, pageTemplate)); return(razorFormat); }
public void Pages_with_errors_still_throw_exceptions_when_rendering() { const string template = "This is a bad template, Hello @SomeInvalidMember.Name!"; Assert.Throws <HttpCompileException>(() => { RazorFormat.AddFileAndPage("/simple.cshtml", template); RazorFormat.RenderToHtml("/simple.cshtml", new { Name = "World" }); }); }
public void Can_Use_HtmlHelper_In_Page() { const string pageSource = "@Html.TextBox(\"textBox\")"; var page = RazorFormat.CreatePage(pageSource); var output = RazorFormat.RenderToHtml(page, model: templateArgs); Assert.That(output, Is.EqualTo(@"<input id=""textBox"" name=""textBox"" type=""text"" value="""" />")); }
public void Can_Use_Model_Directive_With_HtmlHelper() { string pageSource = "@model " + typeof(Person).FullName + @" @Html.TextBoxFor(a => a.FirstName)"; var page = RazorFormat.CreatePage(pageSource); var output = RazorFormat.RenderToHtml(page, model: templateArgs); Assert.That(output, Is.EqualTo(@"<input id=""FirstName"" name=""FirstName"" type=""text"" value=""Demis"" />")); }
/// <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); container.Register <IRedisClientsManager>(c => new RedisManagerPool()); Plugins.Add(new OpenApiFeature { ApiDeclarationFilter = api => { foreach (var path in new[] { api.Paths["/auth"], api.Paths["/auth/{provider}"] }) { path.Get = path.Put = path.Delete = null; } }, OperationFilter = (verb, op) => { if (op.RequestType == nameof(SwaggerRangeTest)) { var intRange = op.Parameters.FirstOrDefault(p => p.Name == nameof(SwaggerRangeTest.IntRange)); intRange.Minimum = 1; intRange.Maximum = 2; var dobleRange = op.Parameters.FirstOrDefault(p => p.Name == nameof(SwaggerRangeTest.DoubleRange)); dobleRange.Minimum = 1.1; dobleRange.Maximum = 2.2; } }, Tags = { new OpenApiTag { Name = "TheTag", Description = "TheTag Description", ExternalDocs = new OpenApiExternalDocumentation { Description = "Link to External Docs Desc", Url = "http://example.org/docs/path", } } } }); // 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 }
public void New_pages_begin_compilation_when_added() { const string template = "This is my sample template, Hello @Model.Name!"; RazorFormat.AddFileAndPage("/simple.cshtml", template); var page = RazorFormat.GetContentPage("/simple.cshtml"); FuncUtils.WaitWhile(() => page.MarkedForCompilation || page.IsCompiling, millisecondTimeout: 5000); Assert.That(page.IsValid); }
public void Pages_with_errors_dont_cause_exceptions_on_thread_starting_the_precompilation() { const string template = "This is a bad template, Hello @SomeInvalidMember.Name!"; RazorFormat.AddFileAndPage("/simple.cshtml", template); var page = RazorFormat.GetContentPage("/simple.cshtml"); FuncUtils.WaitWhile(() => page.MarkedForCompilation || page.IsCompiling, millisecondTimeout: 5000); Assert.That(page.CompileException, Is.Not.Null); }
public void OnBeforeEachTest() { RazorFormat.Instance = null; var fileSystem = new InMemoryVirtualPathProvider(new BasicAppHost()); RazorFormat = new RazorFormat { VirtualPathProvider = fileSystem, EnableLiveReload = false, }.Init(); }
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 static RazorFormat AddPage(this RazorFormat razor, string pageTemplate, string pageName = "Page") { razor.AddPage( new ViewPageRef(razor, "/path/to/tpl", pageName, pageTemplate) { Service = razor.TemplateService }); razor.TemplateService.RegisterPage("/path/to/tpl", pageName); razor.TemplateProvider.CompileQueuedPages(); return(razor); }
public void Can_Access_ViewData() { const string val = "Hello"; const string pageSource = @"@{ Html.ViewData[""X""] = """ + val + @"""; } @Html.ViewData[""X""] "; var page = RazorFormat.CreatePage(pageSource); var output = RazorFormat.RenderToHtml(page, model: templateArgs).Trim(); Assert.That(output, Is.EqualTo(val)); }
public void OnBeforeEachTest() { RazorFormat.Instance = null; var fileSystem = new MemoryVirtualFiles(); RazorFormat = new RazorFormat { VirtualFileSources = fileSystem, EnableLiveReload = false, }.Init(); }
public void Can_Access_ViewBag_From_Layout() { const string val = "Hello"; const string pageSource = @"@{ ViewBag.X = """ + val + @"""; }@ViewBag.X"; var page = RazorFormat.CreatePage(pageSource); RazorFormat.AddFileAndPage(staticTemplatePath, @"<title>@ViewBag.X</title><body>@RenderBody()</body>"); var output = RazorFormat.RenderToHtml(page, model: templateArgs).Trim(); Assert.That(output, Is.EqualTo(@"<title>Hello</title><body>Hello</body>")); }
public RazorFormat Create(string websiteTemplate, string pageTemplate) { var razorFormat = new RazorFormat(); razorFormat.AddTemplate("/path/to/websitetpl", websiteTemplate); razorFormat.AddPage( new RazorPage(razorFormat, "/path/to/tpl", PageName, pageTemplate) { TemplatePath = "/path/to/websitetpl", }); return(razorFormat); }
public void Can_Render_RazorTemplate() { const string mockContents = "[Replaced with Template]"; RazorFormat.AddFileAndPage(staticTemplatePath, staticTemplateContent); var page = RazorFormat.CreatePage(mockContents); var expectedHtml = staticTemplateContent.ReplaceFirst(RazorFormat.TemplatePlaceHolder, mockContents); var templateOutput = RazorFormat.RenderToHtml(page, model: templateArgs); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }
public void HTML_encoding() { var template = @"<p>Some Content @Model.stringContainingHtml</p> ".NormalizeNewLines(); var expectedHtml = @"<p>Some Content <span>html</span></p> ".NormalizeNewLines(); var html = RazorFormat.CreateAndRenderToHtml(template, new { stringContainingHtml = "<span>html</span>" }); Assert.That(html, Is.EqualTo(expectedHtml)); }
public void Integrating_content_and_code() { var template = @"<p>Send mail to [email protected] telling him the time: @DateTime.Now.</p> ".NormalizeNewLines(); var expectedHtml = @"<p>Send mail to [email protected] telling him the time: 02/06/2011 06:38:34.</p> ".NormalizeNewLines(); var html = RazorFormat.CreateAndRenderToHtml(template, model: productArgs); Assert.That(html, Does.Match(expectedHtml.Substring(0, expectedHtml.Length - 25))); }
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(); mvcRazorFormat.Init(typeof(CustomRazorBasePage <>)); }
public HtmlBodyMail() { VirtualPathProvider = new FileSystemVirtualPathProvider(new BasicAppHost(), Path.Combine("~".MapHostAbsolutePath(), TemplateDir)); RazorFormat.Instance = null; Razor = new RazorFormat { VirtualPathProvider = VirtualPathProvider, EnableLiveReload = false, PrecompilePages = true, WaitForPrecompilationOnStartup = true, //PageBaseType = typeof(ViewPage<>), }.Init(); }
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName) { httpRes.ContentType = ContentType.Html; if (RazorFormat == null) { RazorFormat = RazorFormat.Instance; } RazorPage contentPage; if (RazorFormat is CmsRazorFormat) { var cmsRazorFormat = (RazorFormat as CmsRazorFormat); contentPage = RazorPage ?? cmsRazorFormat.GetPageByPathInfo(PathInfo, httpReq); if (contentPage == null) // also search the views directories { // Search for the item in the views before you give up!!! var pageName = PathInfo.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).Last(); contentPage = cmsRazorFormat.GetPageByName(pageName, httpReq, null); } } else { contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo); } if (contentPage == null) { httpRes.StatusCode = (int)HttpStatusCode.NotFound; httpRes.EndHttpRequest(); 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 void Can_Render_RazorTemplate() { const string mockContents = "[Replaced with Template]"; RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent); var page = AddViewPage("MockPage", "/path/to/page", mockContents, staticTemplatePath); var expectedHtml = staticTemplateContent.ReplaceFirst(RazorFormat.TemplatePlaceHolder, mockContents); var templateOutput = page.RenderToString(templateArgs); Console.WriteLine(templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }
public void Can_Render_RazorPage() { RazorFormat.AddFileAndPage(staticTemplatePath, staticTemplateContent); var dynamicPage = RazorFormat.AddFileAndPage(dynamicPagePath, dynamicPageContent); var expectedHtml = dynamicPageContent .Replace("@Model.FirstName", person.FirstName) .Replace("@Model.LastName", person.LastName); expectedHtml = staticTemplateContent.Replace(RazorFormat.TemplatePlaceHolder, expectedHtml); var templateOutput = RazorFormat.RenderToHtml(dynamicPage, model: templateArgs); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }
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!")); }
/// <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 }
public void Can_Render_RazorPage() { RazorFormat.AddFileAndTemplate(staticTemplatePath, staticTemplateContent); var dynamicPage = AddViewPage("DynamicTpl", dynamicPagePath, dynamicPageContent, staticTemplatePath); var expectedHtml = dynamicPageContent .Replace("@Model.FirstName", person.FirstName) .Replace("@Model.LastName", person.LastName); expectedHtml = staticTemplateContent.Replace(RazorFormat.TemplatePlaceHolder, expectedHtml); var templateOutput = dynamicPage.RenderToHtml(templateArgs); Console.WriteLine(templateOutput); Assert.That(templateOutput, Is.EqualTo(expectedHtml)); }
public void OnBeforeEachTest() { RazorFormat.Instance = null; var fileSystem = new InMemoryVirtualPathProvider(); fileSystem.WriteFile("/views/TheLayout.cshtml", LayoutHtml); InitializeFileSystem(fileSystem); RazorFormat = new RazorFormat { VirtualFileSources = fileSystem, PageBaseType = typeof(CustomRazorBasePage <>), EnableLiveReload = false, PrecompilePages = PrecompileEnabled, WaitForPrecompilationOnStartup = WaitForPrecompileEnabled, }.Init(); }
public void Simple_static_example() { var razor = new RazorFormat { //DefaultBaseType = typeof(CustomRazorBasePage<>), //Change custom base ViewPage VirtualPathProvider = new InMemoryVirtualPathProvider(new BasicAppHost()), TemplateProvider = { CompileInParallelWithNoOfThreads = 0 }, }; razor.Init(); razor.AddPage("Hello @Model.Name! Welcome to Razor!"); var html = razor.RenderToHtml(new { Name = "World" }); html.Print(); Assert.That(html, Is.EqualTo("Hello World! Welcome to Razor!")); }
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(); mvcRazorFormat.Init(typeof(CustomRazorBasePage<>)); }
public void TestFixtureSetUp() { var mvcRazorFormat = new RazorFormat(); mvcRazorFormat.Init(typeof(CustomRazorBasePage<>)); }