52
edits
(→Using semantic roles in preview and execute: Deleting extraneous args from execute) |
No edit summary |
||
| (11 intermediate revisions by 3 users not shown) | |||
| Line 2: | Line 2: | ||
Ubiquity 0.5 introduces an updated command API, reflecting the changes in [[Labs/Ubiquity/Parser_2|the parser]] as well as the new [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|ability to localize (some) commands]]. This tutorial will walk you through some of the key changes you will need to make. If you are interested in writing a new Ubiquity command from scratch, please refer to the [[Labs/Ubiquity/Ubiquity_Source_Tip_Author_Tutorial|updated Command Authoring Tutorial]]. | Ubiquity 0.5 introduces an updated command API, reflecting the changes in [[Labs/Ubiquity/Parser_2|the parser]] as well as the new [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|ability to localize (some) commands]]. This tutorial will walk you through some of the key changes you will need to make. If you are interested in writing a new Ubiquity command from scratch, please refer to the [[Labs/Ubiquity/Ubiquity_Source_Tip_Author_Tutorial|updated Command Authoring Tutorial]]. | ||
== Screencast Tutorial for Parser 2 API Conversion == | |||
A screencast walkthrough showing how to convert a command to Parser 2 format for Ubiquity 0.5 is available [http://mitcho.com/blog/projects/converting-your-ubiquity-command-to-ubiquity-0-5/ here]. If this is your first time converting a command, it is recommended that you first watch the walkthrough, as it provides a clear step-by-step visual explanation of what needs to be changed. | |||
== A note on (backwards) compatibility == | == A note on (backwards) compatibility == | ||
| Line 20: | Line 24: | ||
We strongly encourage that all community commands be rewritten in Parser 2 format to take advantage of new (and upcoming) features. | We strongly encourage that all community commands be rewritten in Parser 2 format to take advantage of new (and upcoming) features. | ||
=== Supporting both Parser 1 and Parser 2 in Your Command Feed === | |||
There is a property added to the Command API that allows you to present different commands to clients running Parser 1 and Parser 2, called CmdUtils.parserVersion. A command can provide different options to CmdUtils.CreateCommand() and behave differently depending on this value, allowing a single command feed to cater to whatever parser the user is using. | |||
if (CmdUtils.parserVersion == 2) { | |||
//parser 2 command here | |||
} else { | |||
//parser 1 command here | |||
} | |||
== Converting your command == | == Converting your command == | ||
| Line 116: | Line 130: | ||
data ); | data ); | ||
}, | }, | ||
execute: function( args) { | execute: function(args) { | ||
var data = {}; | var data = {}; | ||
data.query = args.object.text; | data.query = args.object.text; | ||
| Line 126: | Line 140: | ||
... | ... | ||
As always, it is best to first check whether the requisite arguments were filled in the | As always, it is best to first check whether the requisite arguments were filled in the parser before using it. | ||
=== Making your command localizable === | === Making your command localizable === | ||
edits