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.
From bharathh’s code, modified slightly by Doug.@@)
(* 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 {{
[[tab]]
[[tab & tab]]
[[tab & tab & tab & suiteName]] Script Catalog
[[tab & tab]]"
[[tab & tab]]
[[tab]]
}}
logFile merge(headerTemplate), outputFile
(* Creating body *)
set bodyTemplate to {{
[[tab]]<BODY>
[[tab & tab]]<H1>Script Catalog for Suite - [[suiteName]]</H1>
[[if the number of items of lScripts is greater than 0 then]]
[[tab & tab]]<TABLE BGCOLOR=lightyellow BORDER="0" CELLSPACING="2" CELLPADDING="8">
[[tab & tab & tab]]<TR>
[[tab & tab & tab]]<TH> Script Name </TH>
[[tab & tab & tab]]<TH COLSPAN="10"> Description </TH>
[[tab & tab & 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 & tab & tab]]<TR CELLPADDING="2">
[[tab & tab & tab]]<TD>[[scriptName]]</TD>
[[put getScriptDescription(scriptFolder & it) into sDescription]]
[[tab & tab & tab]]<TD CLASS="sp" COLSPAN="10">[[sDescription]]</TD>
[[tab & tab & tab]]</TR>
[[end if
end repeat]]
[[tab & tab]]</TABLE>
[[else]]
[[tab & 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
set num to offset("@@",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 & tab]]<TITLE>
[[tab & tab & tab & scriptName]] Script Details
[[tab & tab]]</TITLE>"
[[tab & tab]]<LINK REL=STYLESHEET HREF="style.css" TYPE="text/css">
[[tab]]</HEAD>
}}
logFile merge(headerTemplate), scriptHelpFile
put file scriptPath into sFile
put getListOfDataBetween( "(*@@@" ,"@@@*)" , sFile) into handlerList
answer handlerList
(* Creating body *)
set bodyTemplate to {{
[[tab]]<BODY>
[[tab & tab]]<H1>[[scriptName]]</H1>
[[tab & tab]]<TABLE BGCOLOR=lightyellow BORDER="0" CELLSPACING="2" CELLPADDING="8">
[[tab & tab & tab]]<TR>
[[tab & tab & tab]]<TH> Script Name:[[scriptName]] </TH>
[[tab & tab & tab]]<TH COLSPAN="10"> Handler List</TH>
[[tab & tab & 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 & tab & tab]]<TR CELLPADDING="2">
[[tab & tab & tab]]<TD>[[handlerName]]</TD>
[[tab & tab & tab]]</TR>
[[put split(handlerDesc, "@") into handlerDescComp]]
[[tab & tab & 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 & tab & tab]]<TD>[[propsName]]</TD>
[[tab & tab & tab]]<TD CLASS="sp" COLSPAN="10">[[propsVal]]</TD>
[[end repeat]]
[[tab & tab & tab]]</TR>
[[end repeat]]
[[tab & 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