De:Ubiquity 0.1.2 Programmier-Tutorial: Difference between revisions

Line 272: Line 272:
= Kommandos mit Argumenten =
= Kommandos mit Argumenten =
== Echo ==
== Echo ==
We'll be working towards making some fun and useful commands—commands that let you control the seething tendrils of the internet with your little pinky. But, let's start by making a simple command to echo back whatever you type.
Wir sind jetzt dabei, uns einige unterhaltsame und nützliche Kommandos zu erstellen, mit denen die Kontrolle der wild auswuchernden Ranken des Internets für Dich zum Kinderspiel wird. Aber lass uns mit einem einfachen Kommando beginnen, das einfach wiederholt, was immer Du auch an Text eingetippt haben magst.


<pre>
<pre>
Line 288: Line 288:
</pre>
</pre>


This says that the command "echo" takes one argument which is arbitrary text. Whatever text the user enters will get wrapped in an input object and passed into both the preview and execute function.
Das Kommando "echo" bekommt im einzigen Argument irgendeinen beliebigen Text übergeben. Was immer der Anwender eingetippt hat, wird in ein Eingabe-Object gepackt und sowohl an die Vorschau, als auch an die  execute-Funktion durchgereicht.  


Ubiquity takes care of parsing the user's input, so you don't need to worry about handling prounoun substitution or any of the other natural-language-like features of the Ubiquity parser. Try selecting some text on a page, and Ubiq "echo this". Ubiquity should now echo the selected text.
Ubiquity kümmert sich um das Parsen der Anwender-Eingabe, so dass Du Dir keine Sorge um den Umgang mit Prounom Substitutionen oder irgendwelchen anderen umgangssprachlichen Eigenarten machen musst. Wähle auf irgendeiner Seite etwas Text und probiere das Ganze mal aus.


=== The Input Object ===
=== Das Eingabe-Objekt ===


The input object that your execute and preview functions receive has the following attributes:
Das Eingabe-Objekt, dass an Deine execute-Funktion und an Deine preview-Funktion übergeben wird, hat die folgenden Eigenschaften:


<pre>
<pre>
   inputObject.text  // a string of the input in plain text, without formatting
   inputObject.text  // ein Klartext-String ohne jede Formatierung
   inputObject.html  // a string of the input in formatted html, including tags
   inputObject.html  // ein HTML-formatiertem html, inclusive der Tags
   inputObject.data  // for non-text input types, an arbitrary data object
   inputObject.data  // für beliebiege Daten
   inputObject.summary // for very long inputs, an abbreviated display string
   inputObject.summary // für sehr lange Eingaben, Anzeige eines verkürzten Strings
</pre>
</pre>


Our example command only cares about the <code>.text</code> attribute of the input, because it simply wants plain textOften, when the user invokes your command by typing a few short words into the input box, <code>.text</code>, <code>.html</code>, and <code>.summary</code> will all have exactly the same value, and <code>.data</code> will be null. Many, if not most, commands that you write will only care about the text valueNevertheless, the other versions of the input data are provided to you in case they differ from <code>.text</code> and in case your command has a use for them.
In unserem Beispiel wird nur die <code>.text</code> Eigenschaft benutzt weil hier auch einfach nur Klartext verarbeitet werden sollIn vielen Fällen, in denen ein Anwender lediglich einige kurze Wörter eintippt, enthalten die Eigenschaften  <code>.text</code>, <code>.html</code> und <code>.summary</code> exakt denselben Wert und die <code>.data</code> Eigenschaft ist Null. Nicht alle, aber viele der Kommandos, die Du schreiben wirst, werden mit der <code>.text</code> - Eigenschft auskommenIn den anderen Fällen, in den sich die besagten Eigenschaften von der <code>.text</code>-Eigenschaft unterscheiden, kannst Du dann ja den entsprechenden Gebrauch davon machen.


=== Introduction to Noun Types ===
=== Introduction to Noun Types ===
166

edits