There are a bunch of updates related to Spark so I think I’ll just run through them in whatever order.

First, the documentation and downloads area have moved to a Drupal cms at http://dev.dejardin.org instead of using the Trac site’s built-in wiki.

There’s a new release of Spark view engine available on the download page.

The first thing to watch out for is a breaking change: support for the $expression; syntax has been removed due to collisions with normal prototype and jquery usage. Anyplace that was using that syntax will need to change to ${expression} but beyond that any valid csharp expression still works to produce output.

Another requested change from Tim Schmidt has been made to support single-quoted string literals when csharp appears in a spark file. That’s to allow xml attributes to use double quotes even though they contain expressions. For example, the code below that writes out a string if a product is in stock:


<ul>
  <li each="var product in Products"
    class="${product.Quantity != 0 ? 'instock' : 'outofstock'}">
      ${product.Name}
  </li>
</ul>

The quotes are changed when the generated class is produced. The generated class contains the following:


Output.Write(product.Quantity != 0 ? "instock" : "outofstock");

An even more significant enhancements has been made to the conditional syntax. This is based on some excellent feedback and ideas from Pablo Blamirez a few weeks back.


<test if="!user.IsLoggedIn">
  <p>Please sign in.
    ${Form.FormTag(new {controller="account", action="login"})}
    user ${Form.Textbox("user")} pass ${"you get the idea..."}
    ${Form.EndFormTag()}
  </p>
  <else if="user.IsAdministrator"/>
  <p>Administrator ${user.Name} etc.</p>
  <else/>
  <p>Hello, ${user.Name}.</p>
</test>

Note the empty <else/> elements. The previous formats are still supported, so you could use <if condition=""> instead of <test if=""> and the else elements may also be used in a way where they follow the original test. So the following is equivalent.


<test if="!user.IsLoggedIn">
  <p>Please sign in.
    ${Form.FormTag(new {controller="account", action="login"})}
    user ${Form.Textbox("user")} pass ${"you get the idea..."}
    ${Form.EndFormTag()}
  </p>
</test>
<else if="user.IsAdministrator">
  <p>Administrator ${user.Name} etc.</p>
</else>
<else>
  <p>Hello, ${user.Name}.</p>
</else>

In the end it’s a stylistic preference.

One Response to “Some significant syntax changes”

Tim Schmidt

July 20th, 2008 - 9:45 pm

Excellent! I’m already using the new syntax and I’m digging it. I was busy today or I would’ve gotten the namespace patch to you. I’ll get to it at some point in the next couple days.

Leave a Reply

Note: This post is over a month old. You may want to check later in this blog to see if there is new information relevant to your comment.