A little while ago James Gregory introduced Docu – a simple doc gen for .Net.

From the Docu project site:

What’s so special about docu?
* One command to build your entire documentation
* Static html, nothing fancy, no dependencies
* Templates built using the Spark view engine
* No GAC, no hard-coded paths; completely redistributable

I thought the use of Spark in a command line utility was remarkably clever. I was inspired into adding a utility to the Spark project, Xpark.exe, for transforming any xml using spark templates.

It’s not part of the RC1 on Codeplex, but you can get the bits from CodeBetter’s TeamCity site.

It’s pretty nice if you’re looking for an xslt alternative. Especially if you are using LINQ to XML to create an anonymous class model at the top of your template.


<var results="
    from s in Model.Elements('stories').Elements('story')
    select new {
        link = (string)s.Attribute('link'),
        title = (string)s.Element('title'),
        description = (string)s.Element('description'),
        thumbnail = s.Elements('thumbnail').Any() ? new {
            src = (string)s.Element('thumbnail').Attribute('src')
        } : null
    }"/>

<html>
  <head>
    <title>Top Stories</title>
    <style type="text/css">
        <include href="diggstyle.css" parse="text"/>
    </style>
  </head>
  <body>
    <div each="var story in results" class="story">
      <h3><a href="!{story.link}">${story.title}</a></h3>
      <p>
        <img if="story.thumbnail != null" class="thumbnail"
            src="!{story.thumbnail.src}"/>
        ${story.description}
      </p>
    </div>
  </body>
</html>

It’s intended to be used as a step in automated processes, like nant, nunit, or a wget/curl of a rest GET endpoint. That’s why there are stdio/stdout fallbacks for the source xml and rendered output.

curl "http://services.digg.com/stories?count=10&appkey=http://hello.com" | (continued...)
  ..\xpark diggstories.spark >livestories.html

>Xpark.exe
    Transforms Xml using a Spark template

    XPARK templatefile [inputfile [outputfile]]

      templatefile  Path to a .spark file.
      inputfile     Source xml. Path to an file or url for http GET.
      outputfile    Target file to receive template output.

    If inputfile or outputfile are not provided stdin and stdout are used.

    The Model in the template is an XDocument loaded from the source.

    The templatefile location may also contain _partial.spark files, and
    a _global.spark file with common namespaces, macros, etc.