documentation generator for Eggplant

I am trying to Generate documentation for all my reusable actions functions . By extending the script send earlier about building a catalogue of test scripts

The issue I am facing is that in a script I am assuminmg that there may be one or more handlers with details for each like

Description of the script
@Initial Handler aka Constructor.
@*)


Comment for handler 1
@Handler: IVEUserLogin
@Param: platform , Name of the Platform of the SUT
@return: none
@Description: This script reads from an Configuration file the Values of the various IVE Parameters and launches the main Login script accordingly. The script accepts a platform as a Parameter and according to that connects to the respective VNC Server
@Author: default
@Version: 1.0
@throws: exception
@*)


.... some code

@Initial Handler aka Constructor.
@*)


@Handler: IVEUserLogin2
@Param: platform , Name of the Platform of the SUT
@return: none
@Description: This script reads from an Configuration file the Values of the various IVE Parameters and launches the main Login script accordingly. The script accepts a platform as a Parameter and according to that connects to the respective VNC Server
@Author: default
@Version: 1.0
@throws: exception
@*)
....

and so on


How can I extract only upto the end of the first handlers documentation?

Having 2 chunk of string for both the handlers

This code does not work for me


function getDatabetween startText , endText , fullText

put "" into chunkRet
set num to 0
set prevnum to 0

repeat forever
set num to offset(startText, fullText, num)
answer num
if num is equal to 0 then exit repeat
if prevnum is not equal to 0 then
if num - prevnum is greater than 9000 then exit repeat
put chars length(startText)+prevnum to num- length(endText) of fullText into chunkRet
answer chunkRet
end if
set prevnum to num
--put num
end repeat
if chunkRet is empty then put "No description available/found" into chunkRet

return chunkRet



end getDatabetween
[/b]

Comments

  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Hi, looks like I should have read ahead to this post before I replied to the last one. ;-)

    To simply extract the text between a starting and ending delimiter, this should work:
    function getDataBetween startText, endText, fullText
    	put offset of startText in fullText into num
    	if num is zero then return empty -- startText wasn't found
    	add the length of startText to num -- skip past the starting delimiter
    	return item 1 delimited by endText of chars num to last of fullText
    end getDataBetween
    
    It looks like maybe you were trying to get more than one delimited chunk at once though? Here's a variation that returns a list of things enclosed by a pair of delimiters:
    function getListOfDataBetween startText, endText, fullText
    	set returnList to an empty list
    	split fullText by startText -- turn it into a list
    	delete item 1 of fullText -- delete the part before the first startText
    	repeat with each item of fullText
    		insert item 1 delimited by endText of it into returnList
    	end repeat
    	return returnList
    end getListOfDataBetween
    
    This code assumes relatively simple cases (no nesting, etc.) but should work for what you want. So, for example, you could call it like this to get a list of every documentation block in a script:
    -- assume the text of a script is in aScript
    set docList to getListOfDataBetween("(*@@", "@@*)", aScript)
    
    repeat with each item doc of docList
    	put ">>>"
    	put doc-- process further
    end repeat
    
    I hope this helps. I'll try to find time to work on a complete script soon. In the meantime let us know if you need more help, and please post your final script once you get it all working.
  • I have started on The Doc generator . Wanted to take your opinion/code :) on this . I am seperating out the Script and all its handlers into individual html Files . Later on I want to cross Link the same ..

    Can you advise on the Directory Structure and other tips ...
    Please note that the Code has issues in it while Parsing the Handler Parameters .
    1 Problem is How do I use a Property List in a nice way so that the handlerName is the Key and values is a List of ( parameters again a List ) , Author , Version , ReturnVal and Description



    @This script creates an HTML page that lists all the scripts
    located in a suite. This script can be called from the
    command line or run directly in Eggplant.
    @*)

    (* Allows Script to be run from command line *)
    params suitePath

    setlogging off

    set preferredBrowser to "Safari" -- or set to "Firefox", "OmniWeb", etc. --doug

    set suiteName to ""

    if suitePath is empty then
    (* Getting Suite Information *)
    put getSuitePath() into suitePath
    if suitePath is empty then exit handler --doug
    end if

    put item 1 to -2 delimited by "." of the last item delimited by "/" of suitePath into suiteName --doug

    (* Getting output file *)
    put getOutputFile(suiteName) into outputFile

    (* Go through file list to catalog them *)
    put suitePath & "/Scripts/" into scriptsFolder
    put the files of scriptsFolder into lScripts

    createStyleSheetFor outputFile --doug

    (* Creating output file as HTML *)
    createHTMLPage outputFile, lScripts, suiteName, scriptsFolder

    repeat with each item of lScripts
    if it ends with ".script" then
    put chars 1 to -8 of it's name into scriptName
    put getOutputFile(scriptName) into scriptOutFile
    answer scriptOutFile
    createStyleSheetFor scriptOutFile --doug
    put createHTMLOfScript (scriptOutFile , scriptName) into res
    end if
    end repeat


    (* Open file with Browser *)
    open outputFile with preferredBrowser

    (* Sub for logging *)
    on logFile strToLog, outputFile
    --put "+++++ Writing " & strToLog
    put strToLog & return after file outputFile
    end logFile

    function getSuitePath
    (* Select suite to catalog *)
    answer folder "Select Suite to Catalog" \
    in folder (items 1 to -4 delimited by "/" of the long name of me)

    (* Check for empty string in case of cancel *)
    if it is empty then return it

    (* Check if valid eggplant suite has been chosen *)
    if it ends with ".suite" then return it
    else return empty
    end getSuitePath

    function getOutputFile suiteName
    set tempStr to suiteName
    replace every occurrence of " " with "_" in tempStr

    put "~/Sites/ScriptCatalogs/" & tempStr & ".html" into outputFile
    create file outputFile
    return outputFile
    end getOutputFile

    on createHTMLPage outputFile, lScripts, suiteName, scriptFolder --doug
    (* Creating Header *)
    set headerTemplate to {{
    <HTML>
    tab<HEAD>
    tab &amp; tab<TITLE>
    tab &amp; tab &amp; tab &amp; suiteName Script Catalog
    tab &amp; tab</TITLE>"
    tab &amp; tab<LINK REL=STYLESHEET HREF="style.css" TYPE="text/css">
    tab</HEAD>
    }}
    logFile merge(headerTemplate), outputFile

    (* Creating body *)
    set bodyTemplate to {{
    tab<BODY>
    tab &amp; tab<H1>Script Catalog for Suite - suiteName</H1>

    if the number of items of lScripts is greater than 0 then
    tab &amp; tab<TABLE BGCOLOR=lightyellow BORDER="0" CELLSPACING="2" CELLPADDING="8">
    tab &amp; tab &amp; tab<TR>
    tab &amp; tab &amp; tab<TH> Script Name </TH>
    tab &amp; tab &amp; tab<TH COLSPAN="10"> Description </TH>
    tab &amp; tab &amp; tab</TR>
    [[repeat with each item of lScripts
    if it ends with ".script" then
    put chars 1 to -8 of it's name into scriptName ]]

    tab &amp; tab &amp; tab<TR CELLPADDING="2">
    tab &amp; tab &amp; tab<TD>scriptName</TD>
    put getScriptDescription(scriptFolder &amp; it) into sDescription
    tab &amp; tab &amp; tab<TD CLASS="sp" COLSPAN="10">sDescription</TD>
    tab &amp; tab &amp; tab</TR>
    [[end if
    end repeat]]
    tab &amp; tab</TABLE>
    else
    tab &amp; tab<h2> No scripts available for cataloging</h2>
    end if
    tab</BODY>
    </HTML>
    }}
    logFile merge(bodyTemplate), outputFile


    end createHTMLPage

    function getScriptDescription scriptName
    put "" into sDesc

    put file scriptName into sFile
    --if sFile begins with "{\rtf" then put rtfToText(sFile) into sFile --doug
    set num to 0
    set prevnum to 0

    repeat forever
    @",sFile, num)
    if num is equal to 0 then exit repeat
    if prevnum is not equal to 0 then
    if num - prevnum is greater than 1000 then exit repeat
    put chars 2+prevnum to num-2 of sFile into sDesc
    end if
    set prevnum to num
    --put num
    end repeat
    if sDesc is empty then put "No description available/found" into sDesc


    return sDesc
    end getScriptDescription




    function createHTMLOfScript scriptHelpFile ,scriptName, suiteName


    put "" into sDesc
    put getSuitePath() into suitePath
    put suitePath & "/Scripts/" into scriptsFolder
    put scriptsFolder&scriptName&".script" into scriptPath
    answer scriptPath

    (* Creating Header *)
    set headerTemplate to {{
    <HTML>
    tab<HEAD>
    tab &amp; tab<TITLE>
    tab &amp; tab &amp; tab &amp; scriptName Script Details
    tab &amp; tab</TITLE>"
    tab &amp; tab<LINK REL=STYLESHEET HREF="style.css" TYPE="text/css">
    tab</HEAD>
    }}
    logFile merge(headerTemplate), scriptHelpFile
    put file scriptPath into sFile
    @*)&quot; , sFile) into handlerList
    answer handlerList

    (* Creating body *)
    set bodyTemplate to {{
    tab<BODY>
    tab &amp; tab<H1>scriptName</H1>
    tab &amp; tab<TABLE BGCOLOR=lightyellow BORDER="0" CELLSPACING="2" CELLPADDING="8">
    tab &amp; tab &amp; tab<TR>
    tab &amp; tab &amp; tab<TH> Script Name:scriptName </TH>
    tab &amp; tab &amp; tab<TH COLSPAN="10"> Handler List</TH>
    tab &amp; tab &amp; tab</TR>
    repeat with each item of handlerList
    set handlerTemp to line 1 of handlerList
    answer handlerTemp
    put chars length("Handler:") to length(handlerTemp) of handlerTemp into HandlerName
    put chars length(handlerTemp) to length(handlerList) of handlerTemp into handlerDesc
    answer handlerDesc
    tab &amp; tab &amp; tab<TR CELLPADDING="2">
    tab &amp; tab &amp; tab<TD>handlerName</TD>
    tab &amp; tab &amp; tab</TR>
    put split(handlerDesc, "@") into handlerDescComp
    tab &amp; tab &amp; tab<TR CELLPADDING="2">
    repeat for each item handlerComp in handlerDescComp
    put split(handlerComp, ":") into handlerProps
    put item 1 of handlerProps into propsName
    put item 2 of handlerProps into propsVal
    tab &amp; tab &amp; tab<TD>propsName</TD>
    tab &amp; tab &amp; tab<TD CLASS="sp" COLSPAN="10">propsVal</TD>
    end repeat
    tab &amp; tab &amp; tab</TR>
    end repeat
    tab &amp; tab</TABLE>
    tab</BODY>
    </HTML>
    }}
    logFile merge(bodyTemplate), scriptHelpFile
    end createHTMLOfScript



    function getListOfDataBetween startText, endText, fullText
    set returnList to an empty list
    split fullText by startText -- turn it into a list
    delete item 1 of fullText -- delete the part before the first startText
    repeat with each item of fullText
    insert item 1 delimited by endText of it into returnList
    end repeat
    return returnList
    end getListOfDataBetween





    to createStyleSheetFor anOutputFile --doug
    put {{
    BODY? ? {
    background: peru;
    font: 11pt "Arial";
    color: black;
    margin-left: 10%;
    margin-right: 15%;
    margin-top: 2%;
    }
    BODY.sp? {
    background: brown;
    font: 11pt "Comic Sans MS";
    color: crimson;
    margin-left: 10%;
    margin-right: 15%;
    margin-top: 2%;
    font-weight: bold
    }
    TD? ? ? ?{font: 11pt "Arial"; color: black; text-align: left; font-weight: bold}
    TD.sp? ? {font: 11pt "Arial"; color: gray; text-align: justify}
    TH? ? ? ?{font: 14pt "Arial"; color: navy; font-weight: bold}
    H1? ? ? ?{font: 20pt "Arial"; color: maroon; font-weight: bold}
    H2? ? ? ?{font: 16pt "Arial"; color: gray; font-weight: bold}
    A? ? ? ? {font: 11pt "Arial"; color: navy; font-style: italic}
    A.sp? ? ?{font: 11pt "Arial"; color: white; font-style: italic; font-weight:bold}
    FONT.sp? {font: 10pt "Arial"; color: firebrick}
    P? ? {text-align: justify}
    P.pic? ? {text-align: center}
    P.indent {margin-left: 2em}
    P.outdent {margin-left: -2em}
    }} into stylesheetContents

    put anOutputFile into styleFile
    put "style.css" into the last item delimited by "/" of styleFile

    if there is not a file styleFile then
    put stylesheetContents into file styleFile -- create the file
    end if
    end to createStyleSheetFor
    
    
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Okay, I decided to put some time into getting this into a fully functional state. I did some thinking about what it should look like and examined some other similar tools. I ended up reworking a significant amount of the script, but I think you'll be pleased with the result.

    The resulting script is posted in the Examples forum, here:
    http://www.redstonesoftware.com/phpbb2/viewtopic.php?p=863.

    Of course, a tool like this is always open for more tweaking, so have at it! But I think you'll find the basic functionality is quite usable now.

    Cheers!
Sign In or Register to comment.