Spark appears in The Weekly Source Code

, , , , 1 Comment »

The Weekly Source Code 30 to be specific, by Scott Hanselman.

I’ve been followed Hanselman now for a while and had the opportunity to see him in person at mix08 presenting a session on Asp.Net MVC. He’s a funny guy and a great speaker.

So that’s pretty cool. I’m glad he liked how Spark came together.

Some significant syntax changes

, , , , , 1 Comment »

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.

Spark macros and recursion

, , , , , , No Comments »

I have a buddy using Spark on a project and there are some things he was excited to show me earlier today. I asked him to email me an example so I could put up a post about it. It’s especially relevant because earlier in the week a question came up about a case where threaded comments were being rendered in a recursive collection. This is the same type of situation.

A <macro> element in Spark is used to add a function to the generated class. Inside the macro all of the html and output is captured and the function returns it as string. So it can be used in an ${expression}. The function can also call itself, as you can see below.

<viewdata clusterList="List[[Cluster]]" />

$Form.FormTag(new {method="get"});
<p>
  $Form.LabelFor("topic", "Topic:");
  $Form.TextField("topic");
</p>
$Form.EndFormTag();

<style>
    ul.cluster { margin-left:25px; }
</style>

<p if="clusterList != null">
    $displayClusters(clusterList);
</p>

<macro name="displayClusters" clusters="List[[Cluster]]">
    <ul class="cluster">
        <for each="var cluster in clusters">
            <li>$cluster.Name;</li>

            <if condition="cluster.Clusters != null">
                $displayClusters(cluster.Clusters);
            </if>
        </for>
    </ul>
</macro>

This is using the MonoRail version of the Spark view engine of course. You can tell by the use of the Form helper. But that’s a cool example of building a ul-nested li tree where the function string displayClusters(List<Clusters> clusters) is calling itself.

Also note the use of the anonymous type used as an option dictionary in the new {method="get"}. Very nice.

One of those Zen computer moments

, , , 1 Comment »

I’m installing a vmware guest for a particular role and I need Windows SDK installed. It’s a 1.4 gb iso file – not a problem. It’s downloaded to a local \install directory (a habit I’ve formed when installing anything that’s downloaded).

The next step, to mount the iso as a virtual cd, is very easy. The host o/s can mount any iso on the virtual cd drive of the guest o/s but first I need to copy the iso from the guest to the host drive. And my Zen moment of introspection is when I think: I’m connected to a virtual machine. I’m about to open a UNC location on the real machine which is hosting this fake machine in order to copy a file I just downloaded. So I’m copying a file onto a real drive from a fake hard drive which itself actually exists as files on that real drive I’m copying to.

Since I have explorer open I point it to to the unc location of the virtual drive on the host o/s. So my guest o/s is now displaying to me, as if it was network files, the actual files inside which exists everything that is currently running on guest o/s which has allowed me to view them.

Sort of like looking at a crystal ball that contains the universe and everything in it, including the observer and the crystal ball. A PC version of an out of body experience.

Computers just keep getting cooler.

Busy times

, , 1 Comment »

Lots of things going on lately. Flew to NY and back in the past few days for a meeting at 1 World Financial Center building.


View Larger Map

Really interesting location. From one side of the building you can see Liberty Island, and from the other you can see the World Trade Center location.

Yes, yes. Blackberry cameras are really bad. You’ll just have to take my word for it – the vertical smudge is the statue which you could can see perfectly fine in person.

And on a positive note this trip is sort of a milestone. I’ve had a mild phobia of flying which I’ve never allowed to interfere with personal or professional travel. That is to say I’ve never declined the opportunity to travel for work because of it. But I have relied on a heavy regimen of airport bar Long Island Iced Teas pre-flight. This trip however marks the first time I simply drove to the airport, walked on a plane, and was either asleep or bored for the entire flight both ways. Yay.

Design by j david macor.com.Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in