Ejemplo n.º 1
0
        public string RenderToHtml(string pageTemplate, Dictionary <string, object> scopeArgs)
        {
            AddPage(pageTemplate);
            var template = RazorFormat.ExecuteTemplate(scopeArgs, PageName, null);

            return(template.Result);
        }
    public static string RenderToHtml <T>(this RazorFormat razor,
                                          T model, string pageName = "Page")
    {
        var template = razor.ExecuteTemplate(model, pageName, null);

        return(template.Result);
    }
Ejemplo n.º 3
0
        public void Can_Render_RazorTemplate_with_section_and_variable_placeholders()
        {
            var template            = @"<h2>Welcome to Razor!</h2>

@{ var lastName = Model.LastName; }

<p>Hello @Upper(lastName), @Model.FirstName,</p>

@section Breadcrumbs {
<h3>Breadcrumbs</h3>
@Combine("" / "", Model.FirstName, lastName)
}

@section Menus {
<h3>Menus</h3>
<ul>
@foreach (var link in Model.Links) {
	<li>@link.Name - @link.Href
		<ul>
		@{ var labels = link.Labels; }
		@foreach (var label in labels) { 
			<li>@label</li>
		}
		</ul>
	</li>
}
</ul>
}";
            var websiteTemplatePath = "websiteTemplate.cshtml";

            var websiteTemplate = @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Bellot page</title>
</head>
<body>

	<header>
		@RenderSection(""Menus"")
	</header>

	<h1>Website Template</h1>

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

	<footer>
		@RenderSection(""Breadcrumbs"")
	</footer>

</body>
</html>";

            var expectedHtml =
                @"<!doctype html>
<html lang=""en-us"">
<head>
	<title>Bellot page</title>
</head>
<body>

	<header>
		
<h3>Menus</h3>
<ul>
	<li>ServiceStack - http://www.servicestack.net
		<ul>
			<li>REST</li>
			<li>JSON</li>
			<li>XML</li>
		</ul>
	</li>
	<li>AjaxStack - http://www.ajaxstack.com
		<ul>
			<li>HTML5</li>
			<li>AJAX</li>
			<li>SPA</li>
		</ul>
	</li>
</ul>

	</header>

	<h1>Website Template</h1>

	<div id=""content""><h2>Welcome to Razor!</h2>


<p>Hello BELLOT, Demis,</p>



</div>

	<footer>
		
<h3>Breadcrumbs</h3>
Demis / Bellot

	</footer>

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

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

            RazorFormat.AddFileAndTemplate(websiteTemplatePath, websiteTemplate);
            AddViewPage("DynamicModelTpl", "/path/to/page-tpl", template, websiteTemplatePath);

            var razorTemplate = RazorFormat.ExecuteTemplate(
                person, "DynamicModelTpl", websiteTemplatePath);

            var templateOutput = razorTemplate.Result.NormalizeNewLines();

            Console.WriteLine(templateOutput);

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