De:Ubiquity 0.1.2 Programmier-Tutorial: Difference between revisions

Jump to navigation Jump to search
Line 545: Line 545:
</pre>
</pre>


The suggest method of a noun type always gets passed both text and html.  If the input is coming from a part of a web page that the user has selected, these
Die Vorschlags-Methode eines Substantiv-Typs erfordert stets die beiden Parameter "text" und "html"Die Eingabe stammen von dem Teil einer WebSeite, den der Anwender ausgewählt hat. Die Werte der beiden Paramter können sehr unterschiedlich sein: beides sind Strings, jedoch enthält der "html"- Parameter, im Gegensatz zum "text"-Parameter, auch HTML-Code. Unser Registerkarten-Substantiv-Typ kümmert sich aber nur um den Registerkarten-Namen im Klartext, so dass wir den "html"-Parameter ignorieren können.
values can be different: they are both strings, but the html value contains markup tags while the text value does not. The Tab noun type only cares about the plain text of the tab name, so we ignore the value of html.
 
Wir verwenden die bequeme <code>CmdUtils.makeSugg()</code> - Funktion zum erzeugen des vom Ubiquity-Parser erwarteten Eingabeobjektes. Die vollständige Signatur dieser Funktion ist:


We use the convenience function <code>CmdUtils.makeSugg()</code> to generate an
input object of the type that the Ubiquity parser expects.  The full signature of this function is
<pre>
<pre>
CmdUtils.makeSugg( text, html, data );
CmdUtils.makeSugg( text, html, data );
Line 555: Line 554:
but html and data are optional and need be provided only if they differ from text.
but html and data are optional and need be provided only if they differ from text.


If the text or html input is very long, <code>makeSugg()</code> generates a summary for us, and puts it in the <code>.summary</code> attribute of the input object.
Falls die "text"- oder "html"-Eingabe sehr lang ist, erzeugt <code>makeSugg()</code> eine Zusammenfassung für uns und hinterlegt sie im <code>.summary</code> Attribut des Eingabeobjekts.
 
Wir könnten das Gleiche auch ohne den Einsatz von <code>makeSugg()</code> erreichen, wenn wir eine Liste von anonymen Objekten zurückgeben. Das könnte dann so aussehen:


We could have accomplished mostly the same thing without calling <code>makeSugg()</code> by returning a list of anonymous objects like these:
<pre>
<pre>
{ text: tabName,
{ text: tabName,
Line 565: Line 565:
</pre>
</pre>


The input objects that our <code>.suggest()</code> method generates are the same objects that will eventually get passed in to the <code>execute()</code> and <code>preview()</code> methods of any commands that use this noun type.
Die Eingabeobjekte, die von unserer <code>.suggest()</code> - Methode erzeugt werden sind genau die Objekte, die möglicherweise an die <code>execute()</code> - Methode und an die <code>preview()</code> - Methode der Kommandos übergeben werden, die unseren Substantiv-Typ verwenden.


== Switching Tabs: The Command ==
== Switching Tabs: The Command ==
166

edits

Navigation menu