September 21, 2007
DekiScript - New Features in Hayes+ (1.8.2)
Steve Bjorg @ 10:56 pm
Hayes+ (1.8.2) went out the door today and it includes many improvements to DekiScript, the built-in expression language for creating dynamic content. Read on to learn about parametric templates, nil check, string concatenation, and magic identifiers.
Parametric Templates
With Hayes+, it is now possible to insert templates with arguments.
To insert a template, use the wiki.template function:
{{ wiki.template('MyTemplate') }}
The “Template:” prefix can be omitted from the template path since it’s redundant.
Arguments to the template can be passed in optionally as a map expression:
{{ wiki.template('MyTemplate', { first: 'John', last: 'Smith' }) }}
Arguments can accessed within the template page by using the args variable like so:
Lastname: {{ args.last }}; Firstname: {{ args.first }}
Parametric templates open waste new possibilities for creating effective content with greater ease. Check out the Map Directions demo which showcases a pretty sophisticated template.
Nil check
Adding template arguments also requires a way to detect if an argument is missing and provide an alternate value for it. The new ?? operator is used to accomplish this task. If the expression to the left of ?? is nil, then the expression to the right is evaluated and used instead.
Let’s expand on our template example from above and rewrite it to use default values when an argument is missing:
Lastname: {{ args.last ?? "missing" }}; Firstname: {{ args.first ?? "missing" }}
String concatenation
We’ve also added .. as the string concatenation operator. This allows strings to be built dynamically based on return values or environment variables.
For example, the following script find all pages containing the logged-in user’s name, excluding the current page:
{{ wiki.search('-path:"' .. page.path .. '" ' .. user.name) }}
The .. operator will automatically convert both expressions to its left and right to strings before concatenating them.
Magic Identifiers
The last addition to DekiScript is also the most esoteric one. Hayes+ includes a PubSub (i.e. publish-subscribe) mechanism so that components embedded through DekiScript can talk with each other. This capability is already leveraged by several extensions that ship with Hayes+. Check out the the Windows Live Contacts and Dynamic Controls demo.
The magic identifier is created by using the @ prefix. This will create a string that is constant within the page, but unique across multiple instances of the page. This property is critical when you embed communicating components with templates. Using constant strings to identify communication channels would cause unintended chatter between components that happen to use the same string.
The following is an example of the Google AJAX search control being used to communicate to Yahoo! term extraction service, which then sends the extracted terms back to a second Google search control. The magic identifiers are used here to establish guaranteed unique channels to avoid interference.
{{ google.search{ publish: @clip, tabbed: true, options: { web: true, news: true, blogs: true } } }}
{{ yahoo.extractterms{ subscribe: @clip, publish: @terms, max: 2 } }}
{{ google.search{ subscribe: @terms, tabbed: true } }}
New Syntax
You can read more about the new additions on the DekiScript page. And don’t hesitate to post on the forums your questions or ideas. Your feedback shapes the product, so speak up!
categories: Deki Wiki





No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL
Leave a comment