Finding bugs in your translator

 < Day Day Up > 

If the TRanslateMarkup() function contains certain types of errors, the translator loads properly, but it fails without an error message when you invoke it. Although failing silently prevents Dreamweaver from becoming unstable, it can hinder development, especially when you need to find one small syntax error in multiple lines of code.

If your translator fails, one effective debugging method is to turn the translator into a command, as described in the following steps:

1.

Copy the entire contents of the translator file to a new document, and save it in the Configuration/Commands folder inside the Dreamweaver application folder.

2.

At the top of the document, between the SCRIPT tags, add the following function:

function commandButtons(){ return new Array( "OK","translateMarkup(dreamweaver. getDocumentPath('document'), dreamweaver.getSiteRoot(), dreamweaver.getDocumentDOM().documentElement.outerHTML); window .close()", "Cancel", "window.close()"); }

3.

At the end of the translateMarkup() function, comment out the return whateverTheReturnValueIs line, and replace it with dreamweaver.getDocumentDOM().documentElement.outerHTML = whateverTheReturnValueIs, as shown in the following example:

   // return theCode;   dreamweaver.getDocumentDOM().documentElement.outerHTML = theCode; }  /* end of translateMarkup() */ 

4.

In the BODY of the document, add the following form with no text boxes:

 <body> <form> Hello. </form> </body> 

5.

Restart Dreamweaver, and select your translator command from the Commands menu. When you click OK, the TRanslateMarkup() function is called, which simulates translation.

If no error message appears and translation still fails, you probably have a logic error in your code.

6.

Add alert() statements in strategic spots throughout the TRanslateMarkup() function so you can make sure you're getting the proper branches and so you can check the values of variables and properties at different points:

 for (var i=0; i< foo.length; i++){   alert("we're at the top of foo.length array, and the value of i is " + i);   /* rest of loop */ } 

7.

After adding the alert() statements, select your command from the Commands menu, click Cancel, and select it again. This process reloads the command file and incorporates your changes.

     < Day Day Up > 


    Developing Extensions for Macromedia Dreamweaver 8
    Developing Extensions for Macromedia Dreamweaver 8
    ISBN: 0321395409
    EAN: 2147483647
    Year: 2005
    Pages: 282

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net