Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity 0.5 Author Tutorial

36 bytes added, 00:28, 11 July 2009
m
no edit summary
preview: function( pblock ) {
var msg = _('Inserts todays today's date: "<i>${date}</i>"');
pblock.innerHTML = CmdUtils.renderTemplate( msg, {date: this._date()} );
},
</pre>
We've done two three things here. The first was to factor out the code for getting the date into the <code>_date()</code> function. This way we don't break [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself DRY] by repeating code across the preview and execute functions. Notice that to access the <code>_date()</code>, we use the <code>this</code> keyword.
The second thing we've done is to add a preview function. The first argument is the DOM element that gets displayed as the preview for your command. Modify <code>pblock</code> and you modify the preview. In this case, we set the <code>innerHTML</code> of the preview block to be the message we want.
The other third thing Iwe've done is to do some string formatting using the <code>renderTemplate()</code> function. This takes a template string and performs the appropriate substitution given the passed-in JSON object. Templates can handle a wide range of functionality, as we are currently using TrimPath's [http://code.google.com/p/trimpath/wiki/JavaScriptTemplates JavascriptTemplates]. You should read their site for more documentation. Although JavascriptTemplates has some nice properties, we are contemplating moving to [http://mjtemplate.org/ MJT] sometime soon.
=== A shortcut for localization and rendering templates ===
<pre>
preview: function( pblock ) {
var msg = 'Inserts todays today's date: "<i>${date}</i>"';
pblock.innerHTML = _( msg, {date: this._date()} );
},
=== Trust Networks ===
In the future, we're going to have something set up that we call a "[[Labs/Ubiquity/TrustNetwork|trust network]]". When you try out a Ubiquity command from a website, and determine that the command is safe (or unsafe), you'll be able to leave an approval (or a warning). When your friends with Ubiquity installed visit the same site, they'll see the approval or the warning that you left. In this way, users will be able to rely on the judgement of other people they already know and trust in order to help them make decisions about whether a command is safe to install or not.
By the way, the reason we call it "subscribing" to a command, rather than "installing" a command, is that if the javascript file changes -- if the site owner adds new commands, removes old commands, or updates existing commands -- all users subscribed to that URL will automatically get the updates. This will be very convenient for both users and developers, but it will also introduce another type of security risk: just because you decided a command was safe at one point in time doesn't mean that the command will always remain safe. For this reason, we'll need to make sure that the trust network keeps track of when commands have been modified, and notifies users of changes that may make a command unsafe.
19
edits

Navigation menu