Spark View Engine
What is Spark
It's a view engine for Asp.Net Mvc and Castle Project MonoRail frameworks. The idea is to allow the html to dominate the flow and the code to fit seamlessly.
For example,
<ul>
<li each='var p in ViewData.Model.Products'>
${p.Name} ${Html.ActionLink[[ProductController]](c=>c.Edit(p.Id), "Edit")}
</li>
</ul>
The full csharp language is available in a way that doesn't interfere with the harmony and balance of the markup. The view template files produced compiled classes.
Key Resources
Download Spark Most recent build and release notes
Documentation Note: table of contents at the right has links to multiple wiki pages.
Spark Development Google group
Where's Lou - tagged Spark
See also PerformanceBenchmarks.
Source Code
For "edge" code - both Castle Project MonoRail and Asp.Net Mvc view engine
svn co http://dev.dejardin.org/svn/spark/trunk/ Spark cd Spark build
For Castle Project MonoRail view engine in contrib trunk
svn co http://svn.castleproject.org:8080/svn/castlecontrib/viewengines/spark/trunk Spark cd Spark build
Assuming you're using a particular build of castle you would copy those assemblies onto over the ones which are a part of the project at bin/castle.
You can browse the source online at source:/trunk/src
Other Links
Castle Dev Group - Spark view engine
Mvc dev group - Contributing a view engine
What it looks like
As a brief example of a master and a view spark xml:
application.xml
<html>
<head>
<viewdata Title="string"/>
<title>${Title}</title>
</head>
<body>
<use content="view"/>
</body>
</html>
demo.xml
<h1>${Title}</h1>
<viewdata Posts="System.Collections.Generic.IList[[SampleCode.Models.Post]]" />
<for each="var post in Posts">
<h2>${H(post.Title)}</h2>
<div>${post.Brief}</div>
</for>
And an action on a controller
public ActionResult Demo()
{
return View("Demo", "Application", new
{
Title = "Some Blog",
Posts = new[]
{
new Post { Title = "Hello World", Brief = "<p>Something</p>"},
new Post { Title = "Spark Headlines", Brief = "<p>Something else</p>"}
}
});
}
More complete documentation about view engine features will be at SparkDocumentation.
The following class is generated and compiled by the view engine. (note - this is out of date... The output is now a TextWriter?, but the general idea remains the same.)
public class CompiledSparkView : MvcContrib.SparkViewEngine.SparkViewBase
{
System.Collections.Generic.IList<SparkDemoSite.Models.Post> Posts
{ get { return (System.Collections.Generic.IList<SparkDemoSite.Models.Post>)ViewData["Posts"]; } }
string Title
{ get { return (string)ViewData["Title"]; } }
public void ProcessView()
{
var output = BindContent("view");
output.Append("<h1>");
output.Append(Title);
output.Append("</h1>\r\n");
output.Append("\r\n");
foreach (var post in Posts)
{
output.Append("\r\n <h2>");
output.Append(Html.Encode(post.Title));
output.Append("</h2>\r\n <div>");
output.Append(post.Brief);
output.Append("</div>\r\n");
} //foreach var post in Posts
output.Append("\r\n");
}
public override string ProcessRequest()
{
ProcessView();
var output = BindContent("master");
output.Append("<html>\r\n <head>\r\n ");
output.Append("\r\n <title>");
output.Append(Title);
output.Append("</title>\r\n </head>\r\n <body>\r\n ");
output.Append(Content["view"]);
output.Append("\r\n </body>\r\n</html>\r\n");
return _content["master"].ToString();
}
}
Attachments
- spark.20080714.zip (3.0 MB) -
Spark build output
, added by louis.dejardin on 07/14/08 03:19:35.
