Ejemplo n.º 1
0
        public RazorFormat AddPage(string websiteTemplate, string pageTemplate)
        {
            RazorFormat.AddTemplate("websiteTemplate", websiteTemplate);
            RazorFormat.AddPage(
                new ViewPageRef(RazorFormat, "/path/to/tpl", PageName, pageTemplate)
            {
                Template = "websiteTemplate",
            });

            return(RazorFormat);
        }
Ejemplo n.º 2
0
        private RazorPage AddViewPage(string pageName, string pagePath, string pageContents, string templatePath = null)
        {
            var dynamicPage = new RazorPage(razorFormat,
                                            pagePath, pageName, pageContents, RazorPageType.ViewPage)
            {
                TemplatePath = templatePath
            };

            razorFormat.AddPage(dynamicPage);
            return(dynamicPage);
        }
Ejemplo n.º 3
0
        public static void AddFileAndView(this RazorFormat razorFormat, ViewPageRef viewPage)
        {
            var pathProvider = (InMemoryVirtualPathProvider)razorFormat.VirtualPathProvider;

            pathProvider.AddFile(viewPage.FilePath, viewPage.Contents);
            razorFormat.AddPage(viewPage);
        }
Ejemplo n.º 4
0
        public static RazorPage AddFileAndPage(this RazorFormat razorFormat, string filePath, string contents)
        {
            var pathProvider = (IWriteableVirtualPathProvider)razorFormat.VirtualPathProvider;

            pathProvider.AddFile(filePath, contents);
            return(razorFormat.AddPage(filePath));
        }
Ejemplo n.º 5
0
        public RazorFormat Create(string pageTemplate)
        {
            var razorFormat = new RazorFormat();

            razorFormat.AddPage(
                new RazorPage(razorFormat, "/path/to/tpl", PageName, pageTemplate));

            return(razorFormat);
        }
 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);
 }
Ejemplo n.º 7
0
        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_compile_simple_view_by_name()
        {
            const string template = "This is my sample view, Hello @Model.Name!";

            RazorFormat.VirtualFileSources.WriteFile("/Views/simple.cshtml", template);
            var addedView = RazorFormat.AddPage("/Views/simple.cshtml");
            var viewPage  = RazorFormat.GetViewPage("simple");

            Assert.That(addedView == viewPage);

            var result = RazorFormat.RenderToHtml(viewPage, new { Name = "World" });

            Assert.That(result, Is.EqualTo("This is my sample view, Hello World!"));
        }
Ejemplo n.º 9
0
        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 static RazorPage AddFileAndPage(this RazorFormat razorFormat, string filePath, string contents)
 {
     razorFormat.VirtualFileSources.WriteFile(filePath, contents);
     return(razorFormat.AddPage(filePath));
 }
Ejemplo n.º 11
0
        public void Can_Render_Static_RazorContentPage_that_populates_variable_and_displayed_on_website_template()
        {
            var websiteTemplate = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Static page</title>
</head>
<body>
	<header>
		@RenderSection(""Header"")
	</header>

	<div id='menus'>
		@RenderSection(""Menu"")
	</div>

	<h1>Website Template</h1>

	<div id=""content"">@RenderBody()</div>

</body>
</html>".NormalizeNewLines();

            var template = @"<h1>Static Markdown Template</h1>
@section Menu {
  @Menu(""Links"")
}

@section Header {
<h3>Static Page Title</h3>
}

<h3>heading 3</h3>
<p>paragraph</p>";

            var expectedHtml = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Static page</title>
</head>
<body>
	<header>
		
<h3>Static Page Title</h3>

	</header>

	<div id='menus'>
		
  <ul>
<li><a href='About Us'>About Us</a></li>
<li><a href='Blog'>Blog</a></li>
<li><a href='Links' class='selected'>Links</a></li>
<li><a href='Contact'>Contact</a></li>
</ul>


	</div>

	<h1>Website Template</h1>

	<div id=""content""><h1>Static Markdown Template</h1>




<h3>heading 3</h3>
<p>paragraph</p></div>

</body>
</html>".NormalizeNewLines();

            RazorFormat.TemplateService.TemplateBaseType = typeof(CustomViewBase <>);

            var websiteTemplatePath = "websiteTemplate.cshtml";

            RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);

            var staticPage = new ViewPageRef(RazorFormat,
                                             "pagetpl", "StaticTpl", template, RazorPageType.ContentPage)
            {
                Service  = RazorFormat.TemplateService,
                Template = websiteTemplatePath,
            };

            RazorFormat.AddPage(staticPage);
            RazorFormat.TemplateService.RegisterPage("pagetpl", "StaticTpl");
            RazorFormat.TemplateProvider.CompileQueuedPages();

            var templateOutput = RazorFormat.RenderStaticPage("pagetpl").NormalizeNewLines();

            Console.WriteLine(templateOutput);
            Assert.That(templateOutput, Is.EqualTo(expectedHtml));
        }