forked from foundeo/cfdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.cfm
45 lines (45 loc) · 2.2 KB
/
doc.cfm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<cfparam name="url.name" default="cfquery">
<cfset url.name = ReReplace(url.name, "[^a-zA-Z0-9_-]", "", "ALL")>
<cfif url.name IS "index">
<cfset data = {name="CFDocs", description="Ultra Fast CFML Documentation", type="index"}>
<cfelseif FileExists(ExpandPath("./guides/en/#url.name#.md"))>
<cftry>
<!--- convert md to HTML --->
<cfset txtmark = createObject("java", "com.github.rjeschke.txtmark.Processor")>
<cfset data = txtmark.process(createObject("java", "java.io.File").init(ExpandPath("./guides/en/#url.name#.md")), "utf-8")>
<cfset request.gitFilePath = "/tree/master/guides/en/" & url.name & ".md">
<cfcatch>
<cfset data = "Error processing markdown: #encodeForHTML(cfcatch.message)# #encodeForHTML(cfcatch.detail)#">
<cfset data &= "Make sure you have installed the textMark jar file in the lib directory used to process the markup files.">
<cfset applicationStop()>
</cfcatch>
</cftry>
<cfelseif FileExists(ExpandPath("./data/en/#url.name#.json"))>
<cfset data = DeserializeJSON( FileRead(ExpandPath("./data/en/#url.name#.json")))>
<cfset request.gitFilePath = "/edit/master/data/en/" & url.name & ".json">
<cfelse>
<cfset url.name = ReReplace(url.name, "[^a-zA-Z0-9._-]", "", "ALL")>
<cfset possible = []>
<cfloop array="#application.index.functions#" index="i">
<cfif Len(url.name) LTE 3>
<cfif FindNoCase(url.name, i)>
<cfset ArrayAppend(possible, i)>
</cfif>
<cfelseif FindNoCase(url.name, i) OR FindNoCase(i, url.name)>
<cfset ArrayAppend(possible, i)>
<cfelseif LCase(Left(url.name, 3)) IS LCase(Left(i, 3)) OR LCase(Right(url.name, 3)) IS LCase(Right(i, 3))>
<cfset ArrayAppend(possible, i)>
</cfif>
</cfloop>
<cfset data = {name = url.name, description="Sorry we don't have any docs matching that name. If we should have a doc for this, please send us a pull request on github.", type="404", related=possible}>
<cfheader statuscode="404" statustext="Not Found">
</cfif>
<cfif isStruct(data)>
<cfset request.title = data.name>
<cfif structKeyExists(data, "examples") AND arrayLen(data.examples) GT 0>
<cfset request.title = request.title & " Code Examples and">
</cfif>
<cfinclude template="views/doc.cfm">
<cfelse>
<cfinclude template="views/markdown.cfm">
</cfif>