Inheritance: IPlugin, IRazorPlugin, IRazorConfig
 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();            
 }
Esempio n. 3
0
 public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents, RazorPageType pageType)
     : this()
 {
     RazorFormat = razorFormat;
     FilePath    = fullPath;
     Name        = name;
     Contents    = contents;
     PageType    = pageType;
 }
Esempio n. 4
0
		public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents, RazorPageType pageType)
			: this()
		{
			RazorFormat = razorFormat;
			FilePath = fullPath;
			Name = name;
			Contents = contents;
			PageType = pageType;
		}
Esempio n. 5
0
        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!"));
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 public ErrorViewPage(RazorFormat razorFormat, Exception ex)
     : base(razorFormat, null, DefaultPageName, ErrorPage(ex, DefaultContents))
 {
     this.ex = ex;
 }
Esempio n. 12
0
 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();
        }
Esempio n. 14
0
        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<>));
 }
Esempio n. 16
0
 public IRazorTemplate ExecuteTemplate <T>(T model)
 {
     return(RazorFormat.ExecuteTemplate(model, this.PageName, this.Template));
 }
Esempio n. 17
0
        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;
        }
Esempio n. 18
0
		public ViewPageRef(RazorFormat razorFormat, string fullPath, string name, string contents)
			: this(razorFormat, fullPath, name, contents, RazorPageType.ViewPage) {}
Esempio n. 19
0
 public ErrorViewPage(RazorFormat razorFormat, Exception ex)
     : base(razorFormat, null, DefaultPageName, ErrorPage(ex, DefaultContents))
 {
     this.ex = ex;
 }
Esempio n. 20
0
 public void TestFixtureSetUp()
 {
     mvcRazorFormat = new RazorFormat { DefaultBaseType = typeof(CustomRazorBasePage<>) };
     mvcRazorFormat.Init();
 }
Esempio n. 21
0
        /// <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
        }