Using Spark View Engine in a stand alone application
Asked Answered
C

5

16

My client application needs to generate HTML. I'd like to use a template/view engine solution like Spark, but I'm not sure whether Spark can be used outside of an ASP.NET application. Does anyone know of any samples or documentation about using Spark in this way?

(If you know of other view engine solutions that can be used stand-alone, I'd be curious to hear about those, too.)

Coadjutress answered 20/10, 2009 at 21:24 Comment(0)
C
15

In addition to the other examples, I found a simple one in the Spark source itself. The Xpark project is a command-line application for transforming XML using Spark. Louis DeJardin, the creator of Spark, described how Xpark works on his blog.

The relevant code snippets are:

    // 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);
    }

This was enough to get me pointed in the right direction. But I'll definitely dive into the other examples as well.

Coadjutress answered 22/10, 2009 at 14:17 Comment(0)
D
3

You should check out Docu, this project uses the Spark view engine to generate HTML documentation (not from an ASP.NET web application).

Be warned though, I don't know that the project is using Spark version 1.0, it might be an earlier build.

http://docu.jagregory.com/

http://github.com/jagregory/docu

Distillery answered 21/10, 2009 at 22:5 Comment(0)
V
1

Sure. Probably the most complete example is to look at the Spark view engine code for ASP.NET MVC itself.

It's also under test, so reading the tests should give you a very good starting point.

Vaticinal answered 20/10, 2009 at 22:20 Comment(0)
T
1

If it helps anyone else, I needed to accomplish something similar using the Spark engine outside of an MVC project.
I created a sample (very simplified) C# project of using the Spark view engine to do simple template operations. Maybe someone could use it as a starting point /shrug
http://jezel.googlecode.com/files/SparkTemplateExample.zip

Most of my template code is based off of reviewing Jonas Gauffin's C# WebServer project where he uses the Spark Engine for templates in a similar fashion.

Tannic answered 22/3, 2011 at 18:52 Comment(0)
N
0

See the examples in: https://github.com/SparkViewEngine/spark/tree/master/src/Samples/DirectUsage

Unfortunately these appear to require System.Web.Mvc, which I'd rather not reference.

Nicolella answered 2/7, 2015 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.