1,007
edits
(→Echo) |
|||
Line 375: | Line 375: | ||
== Introduction to Noun Types == | == Introduction to Noun Types == | ||
Noun types specify what ''kind'' of input your command can accept for each one of its arguments. | |||
For the "echo" command, we wanted the object-role argument to accept any text whatsoever, so for its nountype we passed in the predefined <code>noun_arb_text</code> object. This object accepts any arbitrary text as a valid argument and passes it to the command unchanged. | |||
This is OK for very simple commands, like echoing back the user's input. But for commands that take structured data, you will want to use more specific nountypes. | |||
For example, if a command can take a date (like the "check calendar" command), you would want to use <code>noun_type_date</code> as the nountype of the argument. <code>noun_type_date</code> provides several benefits to your command: it does all of the date parsing for you; it suggests dates that the user might want to enter (for instance, it defaults to today's date). And, it lets the parser know that your command takes a date. This is useful because when the user selects a date on a page and invokes Ubiquity, your command -- along with "check calendar" -- will be one of the top suggestions. | |||
You can write your own noun types -- we'll get into that later. For now, let's take a look at the built-in nountypes that your command can use. These include: | |||
* noun_arb_text (Arbitrary text) | * noun_arb_text (Arbitrary text) | ||
Line 407: | Line 400: | ||
Once you are familiar with writing commands, you should check out the [http://hg.toolness.com/ubiquity-firefox/file/6caa9d66b3bb/ubiquity/chrome/content/nlparser/en/nountypes.js nountypes.js], which has the implementation for most of the noun-types. You can see what noun types are already available for your commands to use, what still needs to be written, and where the existing implementations could use improvement — and then come [[Labs/Ubiquity#Participation|get involved]] to help us improve them. | Once you are familiar with writing commands, you should check out the [http://hg.toolness.com/ubiquity-firefox/file/6caa9d66b3bb/ubiquity/chrome/content/nlparser/en/nountypes.js nountypes.js], which has the implementation for most of the noun-types. You can see what noun types are already available for your commands to use, what still needs to be written, and where the existing implementations could use improvement — and then come [[Labs/Ubiquity#Participation|get involved]] to help us improve them. | ||
Here's an example of what a noun type looks like: | |||
<pre> | |||
var noun_type_foo = { | |||
_name: "foo", | |||
suggest: function( text, html, callback ) { | |||
}, | |||
default: function() { | |||
} | |||
}; | |||
</pre> | |||
== Insert Email: Commands with Specific Argument Types == | == Insert Email: Commands with Specific Argument Types == |
edits