Speaker: Paul Colton
Learn how to use the powerful ScriptDoc tool to add useful documentation for Code Assist.


View video

Hi. This is Paul, and today, I'm going to show you Aptana's ScriptDoc support. Let's get started by creating a new project.

We'll start by going "New Project," and I'll just create a simple project. We'll call this "ScriptDoc Sample," hit Finish, and now, we'll add a new HTML file to the project. Secondly, we'll now add a new JavaScript file to this project as well.

Now, we'll begin by adding the reference to the Java Script file we just added inside of the HTML file, so, in this case, it's "new_file.js." And notice we're going to go back to the Code Assist profiles that it has detected the addition of the new script tag inside HTML and shows you that new_file.js is now essentially a child of a new file, that HTML.

So we'll start by creating a new function, and we'll call it "getName". It'll simply just return my name, return Paul. Now, we'll create a variable called "name". We'll call the function getName, which returns the name. Now, we'll see what's available on the name object. You'll see that the basic information is there, but it doesn't know that "name" is a string. As we know, Java Script is a typeless system; therefore, we need a way of telling Aptana what the return value of this function is, and we do that be adding a ScriptDoc comment section.

So we'll do "/**" we do at "@return" and our curly brace string, curly brace, means that this function returns a type of string. Now, if we go back down and we type "name." you'll now see that the list has grown larger as it shows specific functions available on string; for example "characterAt". "characterAtZero," for example, returns the character at Position Zero of the string.

Now, what would be nice is to take that doc and put it to an external file. That's where ScriptDoc comes in. So let's start by adding a new file to our project, a new ScriptDoc file, and we'll give it the same name as our JS file, except it'll be ".sdoc". Now, notice we'll go back to Code Assist, and all of the sudden, the new_file.sdoc, shows up as a child of the new_file.js. Because the filenames are the same, the association between those files is automatically created.

Now, what we'll do is we'll move the comment block that we added in the JavaScript file, and we'll put it inside of our new .sdoc file. We'll give it a short description, and now, we'll go back here, and we need a way to associate those two functions together, and you do that by using the ScriptDoc @id tag. You can give it any name you like. In this case, we use the same name as the function. Now, we'll go to the corresponding .sdoc file. It will give this comment block the same ID.

Now, we'll go and reselect our JavaScript file. Now, you'll notice that with only the ID present in this file, we still get full Code Assist on the name object. It still knows it's a string. Notice all the same functions of String that are available, including, of course, our favorite, characterAt. And that's because the .sdoc documentation has been associated with that function. We now know its return type to be a string.

Next, what we can do is we can actually add a parameter document description to the .sdoc so let's say that it'll take a single string argument called "name", and we'll give it a short description, so we're putting that in the .sdoc file. Now, we'll go back to the JavaScript file; it will add that name there, and now, notice we're going to try to call the getName function, then all of the sudden, the Code Assist shows us that getName contains a parameter called "name" with the type string and the return type is also string, so updating the .sdoc automatically means Code Assist now knows more information about that function.

The more information you put in your comment block, the more Aptana can help you during your development process. That concludes this short demonstration. We hope that you'll please try and download Aptana and give it a shot. Thank you very much.

[End of Video]