Created
January 5, 2012 08:23
-
-
Save russplaysguitar/1564239 to your computer and use it in GitHub Desktop.
A generalized "pass-through" from cfscript to any cf tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent | |
output="false" | |
hint="I define the application settings and event handlers."> | |
<!--- Define the application. ---> | |
<cfset this.name = hash( getCurrentTemplatePath() ) /> | |
<cfset this.applicationTimeout = createTimeSpan( 0, 0, 0, 30 ) /> | |
<!--- | |
Create a mapping to the virtual file system so that we | |
don't have to keep using ram:// in the relative file | |
paths. | |
NOTE: For absolute file paths, we STILL need to use the | |
full "ram://" prefix. | |
---> | |
<cfset this.mappings[ "/ram" ] = "ram://" /> | |
<!--- Define page request settings. ---> | |
<cfsetting showdebugoutput="false" /> | |
</cfcomponent> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
NOTE: Before using, you must set up a mapping from ram:// to /ram | |
USAGE: | |
cf = new Tag(); | |
result = cf.tagName( | |
parameters={ | |
paramTag={ paramTagAttribute="1" } | |
}, | |
attributes={ | |
tagAttribute = "myAttribute" | |
}, | |
returnName="variable" | |
); | |
EXAMPLE: | |
result = cf.zip( | |
parameters={ | |
zipparam={ | |
content="string", | |
entrypath="a.txt" | |
} | |
}, | |
attributes={ | |
action="read", | |
entrypath="a.txt", | |
file="a.zip" | |
}, | |
returnName="variable"); | |
Equivalent code in tag form: | |
<cfzip action="read" entrypath="a.txt" file="a.zip" variable="result"> | |
<cfzipparam content="string" entrypath="a.txt"> | |
</cfzip> | |
---> | |
<!--- tag.cfc ---> | |
<cfcomponent> | |
<cffunction access="public" name="init" returnType="component"> | |
<cfreturn this /> | |
</cffunction> | |
<cffunction access="public" name="OnMissingMethod" returnType="Any"> | |
<cfargument | |
name="MissingMethodName" | |
type="string" | |
required="true" | |
hint="The name of the missing method." | |
/> | |
<cfargument | |
name="MissingMethodArguments" | |
type="struct" | |
required="true" | |
hint="The arguments that were passed to the missing method. This might be a named argument set or a numerically indexed set." | |
/> | |
<cfparam name="arguments.MissingMethodArguments.attributes" default="#{}#" /> | |
<cfparam name="arguments.MissingMethodArguments.parameters" default="#{}#" /> | |
<cfparam name="arguments.MissingMethodArguments.return" default="" /> | |
<cfset var tagName = MissingMethodName /> | |
<cfset var attributes = arguments.MissingMethodArguments.attributes /> | |
<cfset var parameters = arguments.MissingMethodArguments.parameters /> | |
<cfset var returnName = MissingMethodArguments.returnName /> | |
<cfset var result = "" /> | |
<cfset var beginTag="<cf#tagName# " /> | |
<cfset var endTag="</cf#tagName#>" /> | |
<cfsavecontent variable="filestring"> | |
<cfoutput> | |
#beginTag# | |
<cfif returnName IS NOT "">#returnName#="result"</cfif> | |
<cfloop collection="#attributes#" item="attribute"> | |
#attribute#='#StructFind(attributes, attribute)#' | |
</cfloop> | |
> | |
<cfloop collection="#parameters#" item="parameter"> | |
<cfset var beginPtag = "<cf#parameter# " /> | |
#beginPtag# | |
<cfset paramAttributes = StructFind(parameters, parameter) /> | |
<cfloop collection="#paramAttributes#" item="attribute"> | |
#attribute#='#StructFind(paramAttributes, attribute)#' | |
</cfloop> | |
/> | |
</cfloop> | |
#endTag# | |
</cfoutput> | |
</cfsavecontent> | |
<cffile action="write" file="ram://tmp.cfm" output="#filestring#"> | |
<cfinclude template="/ram/tmp.cfm"> | |
<cffile action="delete" file="ram://tmp.cfm"> | |
<cfreturn result /> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment