Custom Search

Thursday, January 24, 2008

Tutorial : Application code documentation


Note: very recent i found little bug in this tutorial.
Soon i will fix it.
If you want then you may fix it.
This a challange for you...


hi,
here i show a object oriented technique for documented your code.
when you build your site then you may want a pdf file here you can get all of your code.for this purpose you can try it.

for this create two file in your application root folder named codedocumentation.cfc and codedocumentation.cfm,here the both file code.

codedocumentation.cfc
 <cfcomponent hint="Create Code Documentation" output="yes">
 
  <cffunction name="GetApplicationMap" access="remote" returntype="array">
 
   <cfargument name="SiteRootDirectory" type="string" required="yes">  
   <cfargument name="OutputFileFormat" type="string" required="yes">    
  
   <cfset FolderExploreStatus=0>
 
   <!--- Create a Array for hold all  Files List--->  
   <cfset FileArray=Arraynew(2)>
 
   <!---Root Directory's Contents--->
   <cfdirectory action="list"
    directory="#arguments.SiteRootDirectory#"
    name="ParentDirectory"
    >
 
   <!---Root Directory's Directory--->
   <cfquery name="DirectoryList" dbtype="query">
    SELECT *
    FROM ParentDirectory
    WHERE TYPE='Dir'
   </cfquery>
   
   <!---List of all Folder Path--->
   <cfset FolderPathArray=Arraynew(1)>
   <cfset TempFolderPathArray=ArrayAppend(FolderPathArray,arguments.SiteRootDirectory)>
   <!---<cfdump var="#FolderPathArray#"><br/>--->
   
 
   <!--- Create a Array for hold  Folder List--->  
   <cfset FolderArray=ArrayNew(2)>
 
   <cfset FolderCounter=1>
   <cfloop query="DirectoryList">
    <cfset FolderArray[FolderCounter][1]=DIRECTORY>
    <cfset FolderArray[FolderCounter][2]=NAME>
    
    <cfset FolderPath="#DIRECTORY#\#NAME#\">
    <!---<cfdump var="#FolderPath#"><br/>--->
    <cfset TempFolderPathArray=ArrayAppend(FolderPathArray,FolderPath)>
    <cfset FolderCounter=FolderCounter+1>
   </cfloop>
 
   <cfset FolderNumber=ArrayLen(FolderArray)>
  
   <cfif FolderNumber GT 0>
    <cfloop condition=" FolderExploreStatus EQ 0 ">
  <cfset CurrentFolderDirectory=FolderArray[1][1]>
  <cfset CurrentFolderName=FolderArray[1][2]>
  
  <cfset CurrentFolderPath="#CurrentFolderDirectory#\#CurrentFolderName#\">
  
  <!--- List the Current directory's Directory--->  
  <cfdirectory
   action="list"
   name="ChildDirectory"
   directory="#CurrentFolderPath#"
   > 
 
  <!--- List the Current directory's Directory--->  
  <cfquery name="ChildDirectoryList" dbtype="query">    
   SELECT *
   FROM ChildDirectory
   WHERE TYPE='Dir'
  </cfquery>
    
  <cfset TempFolderArrayDelete=ArrayDeleteAt(FolderArray,1)>
    
  <cfset FolderCounter=ArrayLen(FolderArray)>
  <cfset FolderCounter=FolderCounter+1>
   
  <cfloop query="ChildDirectoryList">
   <cfset FolderArray[FolderCounter][1]=DIRECTORY>
   <cfset FolderArray[FolderCounter][2]=NAME>  
   
   <cfset FolderPath="#DIRECTORY#\#NAME#\">
   <!---<cfdump var="#FolderPath#"><br/>--->
   <cfset TempFolderPathArray=ArrayAppend(FolderPathArray,FolderPath)>
   <cfset FolderCounter=FolderCounter+1>
  </cfloop>
 
  <cfset FolderNumber=ArrayLen(FolderArray)>
  <cfif FolderNumber LT 1>
   <cfset FolderExploreStatus=1>
  </cfif>
  
    </cfloop>
   </cfif>
   
   <!---Now we find final folder path array--->
   
   <cfset TotalFolder=ArrayLen(FolderPathArray)>
   
   <cfloop from="1" to="#TotalFolder#" index="index">
   
    <!---<cfoutput>#FolderPathArray[index]#</cfoutput><br/>--->
    <!---Root Directory's .cfm FileList--->
    <cfdirectory action="list"
   filter="*.cfm"
  directory="#FolderPathArray[index]#"
  name="CFMFileList"
  >
  
    <!---Root Directory's .cfml FileList--->
    <cfdirectory action="list"
   filter="*.cfml"
  directory="#FolderPathArray[index]#"
  name="CFMLFileList"
  >
  
    <!---Root Directory's .cfc FileList--->
    <cfdirectory action="list"
   filter="*.cfc"
  directory="#FolderPathArray[index]#"
  name="CFCFileList"
  >
  
    <!---Root Directory's .htm FileList--->
    <cfdirectory action="list"
   filter="*.htm"
  directory="#FolderPathArray[index]#"
  name="HTMFileList"
  >
  
    <!---Root Directory's .html FileList--->
    <cfdirectory action="list"
   filter="*.html"
  directory="#FolderPathArray[index]#"
  name="HTMLFileList"
  >
  
    <!---Root Directory's .css FileList--->
    <cfdirectory action="list"
   filter="*.css"
  directory="#FolderPathArray[index]#"
  name="CSSFileList"
  >
  
    <!---Root Directory's .js FileList--->   
    <cfdirectory action="list"
   filter="*.js"
  directory="#FolderPathArray[index]#"
  name="JSFileList"
  >
  
    <!---Root Directory's All FileList--->  
    <cfquery name="FileList" dbtype="query">
  SELECT *
  FROM CFMFileList
  UNION
  
  SELECT *
  FROM CFMLFileList
  UNION
  
  SELECT *
  FROM CFCFileList
  UNION
  
  SELECT *
  FROM HTMFileList
  UNION
  
  SELECT *
  FROM HTMLFileList
  UNION
  
  SELECT *
  FROM CSSFileList
  UNION
  
  SELECT *
  FROM JSFileList
    </cfquery>
  
    <cfset FileCounter=ArrayLen(FileArray)>
    <cfif FileCounter EQ 0>
  <cfset FileCounter=1>
    </cfif>
    <cfloop query="FileList">
   <cfset FileArray[FileCounter][1]=NAME>
   <cfset FilePath="#DIRECTORY#\#NAME#">
   <cfset FileArray[FileCounter][2]=FilePath>
   
  <cfset FileCounter=FileCounter+1>
    </cfloop>
   
   </cfloop>
   
   <!---Now we find final file array--->
   <cfdump var="#FileArray#">
   
   <cfset TotalFile=ArrayLen(FileArray)>
   
   <cfif TotalFile GT 0>
    <cfdocument format="#arguments.OutputFileFormat#">
  <cfdocumentsection>
   <cfdocumentitem type="footer">
    <font size="-3">Page #cfdocument.currentpagenumber#</font>
   </cfdocumentitem>
     
   <cfloop from="1" to="#TotalFile#" index="position">
 
    <cfdocumentitem type="header">
     <cfoutput>
   <font size="-3">
    <i>
     Code Documentation
    </i>
   </font>
     </cfoutput>
    </cfdocumentitem>
 
    <cffile
     action="read"
     file="#FileArray[position][2]#"
     variable="FileCode"
     >
    <cfoutput>
     <h3>
   <i>
    #FileArray[position][2]#
   </i>
     </h3>
     <br/>
 
     <h2>
   #FileArray[position][1]#
     </h2>
    </cfoutput>
    <br/>
    
    <cfoutput>
     #HTMLCodeFormat(wrap(FileCode,75))#
    </cfoutput>
   </cfloop>
    </cfdocumentsection>
    </cfdocument> 
   </cfif>
 
   <cfreturn FolderPathArray>
  </cffunction>
 </cfcomponent>
   
codedocumentation.cfm
 <cfset ApplicationRootpath=ExpandPath(".")>
 
 <cfif IsDefined("Form.GetMap")>
  <cfscript>
   ApplicationMapObject=CreateObject("Component","codedocumentation");
  </cfscript>
  <cfset ApplicationMapObject.GetApplicationMap(Form.ApplicationRootpath,Form.FileFormat)>
 </cfif>
 
 <div align="center">
  <cfform name="FileFormatForm" action="#CGI.SCRIPT_NAME#" method="post" target="_blank">
   <cfselect name="FileFormat" label="Output Format">
    <option value="pdf">PDF</option>
    <option value="flashpaper">Flash Paper</option>
   </cfselect>
   <cfinput type="hidden" name="ApplicationRootpath" value="#ApplicationRootpath#">
   <cfinput type="submit" name="GetMap" value="Get Application Map">
  </cfform>
 
 
 </div>
   
hei..
now run the codedocumentation.cfm file in your browser.
submit the form.
what you see...?
yes its object oriented web programming.