dth*_*her 15 c# spark-view-engine
我的客户端应用程序需要生成HTML.我想使用像Spark这样的模板/视图引擎解决方案,但我不确定Spark是否可以在ASP.NET应用程序之外使用.有没有人知道以这种方式使用Spark的任何样本或文档?
(如果您知道可以单独使用的其他视图引擎解决方案,我也很想知道这些.)
dth*_*her 14
除了其他示例,我在Spark源代码中找到了一个简单的例子.Xpark项目是一个使用Spark转换XML的命令行应用程序.Spark的创建者Louis DeJardin描述了Xpark如何在他的博客上运作.
相关的代码片段是:
// Create an engine using the templates path as the root location
// as well as the shared location
var engine = new SparkViewEngine
{
DefaultPageBaseType = typeof(SparkView).FullName,
ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared"))
};
SparkView view;
// compile and instantiate the template
view = (SparkView)engine.CreateInstance(
new SparkViewDescriptor()
.AddTemplate(templateName));
// render the view to stdout
using (var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.UTF8))
{
view.RenderView(writer);
}
Run Code Online (Sandbox Code Playgroud)
这足以让我指出正确的方向.但我肯定会深入研究其他例子.