|
| 1 | +<cfcomponent hint="Core class for ColdDoc documentation generation framework" output="false"> |
| 2 | + |
| 3 | +<!------------------------------------------- PUBLIC -------------------------------------------> |
| 4 | + |
| 5 | +<cffunction name="init" hint="Constructor" access="public" returntype="ColdDoc" output="false"> |
| 6 | + <cfscript> |
| 7 | + variables.instance = {}; |
| 8 | + |
| 9 | + return this; |
| 10 | + </cfscript> |
| 11 | +</cffunction> |
| 12 | + |
| 13 | +<cffunction name="generate" hint="generates the documentation" access="public" returntype="void" output="false"> |
| 14 | + <cfargument name="inputSource" hint="either, the string directory source, OR an array of structs containing inputDir and inputMapping key" type="any" required="yes"> |
| 15 | + <cfargument name="inputMapping" hint="the base mapping for the folder. Only required if the inputSource is a string." type="string" required="false" default=""> |
| 16 | + <cfscript> |
| 17 | + var qMetaData = 0; |
| 18 | + var source = 0; |
| 19 | + |
| 20 | + if(NOT hasStrategy()) |
| 21 | + { |
| 22 | + throwException("colddoc.StrategyNotSetException", "No Template Strategy has been set.", |
| 23 | + "Create a Template Strategy, and set it with setStrategy() before calling generate()"); |
| 24 | + } |
| 25 | + |
| 26 | + if(isSimpleValue(arguments.inputSource)) |
| 27 | + { |
| 28 | + source = [{ inputDir=arguments.inputSource, inputMapping=arguments.inputMapping }]; |
| 29 | + } |
| 30 | + else |
| 31 | + { |
| 32 | + source = arguments.inputSource; |
| 33 | + } |
| 34 | + |
| 35 | + qMetaData = buildMetaDataCollection(source); |
| 36 | + |
| 37 | + getStrategy().run(qMetaData); |
| 38 | + </cfscript> |
| 39 | +</cffunction> |
| 40 | + |
| 41 | +<cffunction name="getStrategy" hint="Returns the current document templating strategy that is being userd" access="public" returntype="any" output="false" |
| 42 | + colddoc:generic="colddoc.strategy.AbstractTemplateStrategy"> |
| 43 | + <cfreturn instance.strategy /> |
| 44 | +</cffunction> |
| 45 | + |
| 46 | +<cffunction name="setStrategy" hint="Set the document templating strategy that is going to be used" access="public" returntype="void" output="false"> |
| 47 | + <cfargument name="strategy" hint="The strategy object that is called to generate the doc. Usually extends colddoc.strategy.AbstractTemplateStrategy." |
| 48 | + type="any" required="true" colddoc:generic="colddoc.strategy.AbstractTemplateStrategy"> |
| 49 | + <cfset instance.strategy = arguments.strategy /> |
| 50 | +</cffunction> |
| 51 | + |
| 52 | +<cffunction name="hasStrategy" hint="whether this object has a strategy" access="public" returntype="boolean" output="false"> |
| 53 | + <cfreturn StructKeyExists(instance, "strategy") /> |
| 54 | +</cffunction> |
| 55 | + |
| 56 | +<!------------------------------------------- PACKAGE -------------------------------------------> |
| 57 | + |
| 58 | +<!------------------------------------------- PRIVATE -------------------------------------------> |
| 59 | + |
| 60 | +<cffunction name="buildMetaDataCollection" hint="builds the searchable meta data collection" access="private" returntype="query" output="false"> |
| 61 | + <cfargument name="inputSource" hint="an array of structs containing inputDir and inputMapping" type="array" required="yes"> <!--- of struct ---> |
| 62 | + |
| 63 | + <cfscript> |
| 64 | + var qFile = 0; |
| 65 | + var qMetaData = QueryNew("package,name,extends,metadata,type,implements,fullextends"); |
| 66 | + var cfcPath = 0; |
| 67 | + var packagePath = 0; |
| 68 | + var cfcName = 0; |
| 69 | + var meta = 0; |
| 70 | + var i = 0; |
| 71 | + var implements = 0; |
| 72 | + var fullextends = 0; |
| 73 | + </cfscript> |
| 74 | + |
| 75 | + <cfloop index="i" from="1" to="#ArrayLen(arguments.inputSource)#"> |
| 76 | + |
| 77 | + <cfdirectory action="list" directory="#arguments.inputSource[i].inputDir#" recurse="true" name="qFiles" filter="*.cfc"> |
| 78 | + |
| 79 | + <cfloop query="qFiles"> |
| 80 | + <cfscript> |
| 81 | + currentPath = replace(directory, arguments.inputSource[i].inputDir, ""); |
| 82 | + currentPath = reReplace(currentPath, "[/\\]", ""); |
| 83 | + currentPath = reReplace(currentPath, "[/\\]", ".", "all"); |
| 84 | + |
| 85 | + if(len(currentPath)) |
| 86 | + { |
| 87 | + packagePath = ListAppend(arguments.inputSource[i].inputMapping, currentPath, "."); |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + packagePath = arguments.inputSource[i].inputMapping; |
| 92 | + } |
| 93 | + |
| 94 | + cfcName = ListGetAt(name, 1, "."); |
| 95 | + |
| 96 | + try |
| 97 | + { |
| 98 | + if (Len(packagePath)) { |
| 99 | + meta = getComponentMetaData(packagePath & "." & cfcName); |
| 100 | + } |
| 101 | + else { |
| 102 | + meta = getComponentMetaData(cfcName); |
| 103 | + } |
| 104 | + |
| 105 | + //let's do some cleanup, in case CF sucks. |
| 106 | + if(Len (packagePath) AND NOT meta.name contains packagePath) |
| 107 | + { |
| 108 | + meta.name = packagePath & "." & cfcName; |
| 109 | + } |
| 110 | + |
| 111 | + QueryAddRow(qMetaData); |
| 112 | + QuerySetCell(qMetaData, "package", packagePath); |
| 113 | + QuerySetCell(qMetaData, "name", cfcName); |
| 114 | + QuerySetCell(qMetaData, "metadata", meta); |
| 115 | + QuerySetCell(qMetaData, "type", meta.type); |
| 116 | + |
| 117 | + implements = getImplements(meta); |
| 118 | + implements = listQualify(arrayToList(implements), ':'); |
| 119 | + |
| 120 | + QuerySetCell(qMetaData, "implements", implements); |
| 121 | + |
| 122 | + fullextends = getInheritence(meta); |
| 123 | + fullextends = listQualify(arrayToList(fullextends), ':'); |
| 124 | + |
| 125 | + QuerySetCell(qMetaData, "fullextends", fullextends); |
| 126 | + |
| 127 | + //so we cane easily query direct desendents |
| 128 | + if(StructKeyExists(meta, "extends")) |
| 129 | + { |
| 130 | + if(meta.type eq "interface") |
| 131 | + { |
| 132 | + QuerySetCell(qMetaData, "extends", meta.extends[structKeyList(meta.extends)].name); |
| 133 | + } |
| 134 | + else |
| 135 | + { |
| 136 | + QuerySetCell(qMetaData, "extends", meta.extends.name); |
| 137 | + } |
| 138 | + } |
| 139 | + else |
| 140 | + { |
| 141 | + QuerySetCell(qMetaData, "extends", "-"); |
| 142 | + } |
| 143 | + |
| 144 | + } |
| 145 | + catch(Any exc) |
| 146 | + { |
| 147 | + warnError(packagePath & "." & cfcName, exc); |
| 148 | + } |
| 149 | + </cfscript> |
| 150 | + </cfloop> |
| 151 | + |
| 152 | + </cfloop> |
| 153 | + |
| 154 | + <cfreturn qMetaData /> |
| 155 | +</cffunction> |
| 156 | + |
| 157 | +<cffunction name="warnError" hint="Warn the user that there was an error through cftrace" access="private" returntype="void" output="false"> |
| 158 | + <cfargument name="cfcName" hint="the name of the cfc" type="string" required="Yes"> |
| 159 | + <cfargument name="error" hint="the error struct" type="any" required="Yes"> |
| 160 | + <cfset var dump = 0 /> |
| 161 | + <!--- |
| 162 | + <cfset _trace(error)> |
| 163 | + ---> |
| 164 | + <cfsetting showdebugoutput="true"> |
| 165 | + <cftrace category="ColdDoc" inline="true" type="Warning" text="Warning, the following script has errors: #arguments.cfcName#, #toString(arguments.error)#"> |
| 166 | +</cffunction> |
| 167 | + |
| 168 | +<cffunction name="getImplements" hint="gets an array of the interfaces that this metadata implements" access="private" returntype="array" output="false"> |
| 169 | + <cfargument name="metadata" hint="the metadata to look at" type="struct" required="Yes"> |
| 170 | + <cfscript> |
| 171 | + var localmeta = arguments.metadata; |
| 172 | + var interfaces = {}; |
| 173 | + var key = 0; |
| 174 | + var imeta = 0; |
| 175 | + |
| 176 | + if(arguments.metadata.type neq "component") |
| 177 | + { |
| 178 | + return ArrayNew(1); |
| 179 | + } |
| 180 | + |
| 181 | + while(StructKeyExists(localmeta, "extends")) |
| 182 | + { |
| 183 | + if(StructKeyExists(localmeta, "implements")) |
| 184 | + { |
| 185 | + for(key in localmeta.implements) |
| 186 | + { |
| 187 | + imeta = localmeta.implements[local.key]; |
| 188 | + interfaces[imeta.name] = 1; |
| 189 | + } |
| 190 | + } |
| 191 | + localmeta = localmeta.extends; |
| 192 | + } |
| 193 | + |
| 194 | + interfaces = structKeyArray(interfaces); |
| 195 | + |
| 196 | + arraySort(interfaces, "textnocase"); |
| 197 | + |
| 198 | + return interfaces; |
| 199 | + </cfscript> |
| 200 | +</cffunction> |
| 201 | + |
| 202 | +<cffunction name="getInheritence" hint="gets an array of the classes that this metadata extends, in order of extension" access="private" returntype="array" output="false"> |
| 203 | + <cfargument name="metadata" hint="the metadata to look at" type="struct" required="Yes"> |
| 204 | + <cfscript> |
| 205 | + { |
| 206 | + var localmeta = arguments.metadata; |
| 207 | + //ignore top level |
| 208 | + var inheritence = []; |
| 209 | + |
| 210 | + while(StructKeyExists(localmeta, "extends")) |
| 211 | + { |
| 212 | + //manage interfaces |
| 213 | + if(localmeta.type eq "interface") |
| 214 | + { |
| 215 | + localmeta = localmeta.extends[structKeyList(localmeta.extends)]; |
| 216 | + } |
| 217 | + else |
| 218 | + { |
| 219 | + localmeta = localmeta.extends; |
| 220 | + } |
| 221 | + |
| 222 | + ArrayPrepend(inheritence, localmeta.name); |
| 223 | + } |
| 224 | + |
| 225 | + return inheritence; |
| 226 | + } |
| 227 | + </cfscript> |
| 228 | +</cffunction> |
| 229 | + |
| 230 | + |
| 231 | +<cffunction name="_trace"> |
| 232 | + <cfargument name="s"> |
| 233 | + <cfset var g = ""> |
| 234 | + <cfsetting showdebugoutput="true"> |
| 235 | + <cfsavecontent variable="g"> |
| 236 | + <cfdump var="#arguments.s#"> |
| 237 | + </cfsavecontent> |
| 238 | + <cftrace text="#g#"> |
| 239 | +</cffunction> |
| 240 | + |
| 241 | +<cffunction name="_dump"> |
| 242 | + <cfargument name="s"> |
| 243 | + <cfargument name="abort" default="true"> |
| 244 | + <cfset var g = ""> |
| 245 | + <cfdump var="#arguments.s#"> |
| 246 | + <cfif arguments.abort> |
| 247 | + <cfabort> |
| 248 | + </cfif> |
| 249 | +</cffunction> |
| 250 | + |
| 251 | +<cffunction name="throwException" access="private" hint="Throws an Exception" output="false"> |
| 252 | + <cfargument name="type" hint="The type of exception" type="string" required="Yes"> |
| 253 | + <cfargument name="message" hint="The message to accompany the exception" type="string" required="Yes"> |
| 254 | + <cfargument name="detail" type="string" hint="The detail message for the exception" required="No" default=""> |
| 255 | + <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#"> |
| 256 | +</cffunction> |
| 257 | + |
| 258 | + |
| 259 | +</cfcomponent> |
0 commit comments