Skip to content

Instantly share code, notes, and snippets.

@JamoCA
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamoCA/8938465 to your computer and use it in GitHub Desktop.
Save JamoCA/8938465 to your computer and use it in GitHub Desktop.
ColdFusion Custom Tag to allow all params to be safely passed regardless of ColdFusion version. Also removes comments & compresses whitespace.
<cfif thisTag.executionMode neq "start"><cfexit method="exitTag"></cfif><cfsetting enablecfoutputonly="YES">
<!--- Server-based optimization technologies (like Google PageSpeed) may minify
or rewrite the HTML/JS/CSS and break CFDump's output.
Defaults for optional attributes, taken from the docs
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_d-e_08.html --->
<cfparam name="attributes.var" default="">
<cfparam name="attributes.output" default="browser">
<cfparam name="attributes.format" default="html">
<cfparam name="attributes.abort" default="false">
<cfparam name="attributes.label" default="">
<cfparam name="attributes.metainfo" default="yes">
<cfparam name="attributes.top" default="9999">
<cfparam name="attributes.show" default="all">
<cfparam name="attributes.hide" default="all">
<cfparam name="attributes.keys" default="9999">
<cfparam name="attributes.expand" default="yes">
<cfparam name="attributes.showUDFs" default="yes">
<!--- Call the original cfdump. (Which attributes you pass depends on CF version.) --->
<cfsavecontent variable="DumpResults">
<cfswitch expression="#listFirst(server.coldfusion.productVersion)#">
<cfcase value="6">
<cfdump var="#attributes.var#" expand="#attributes.expand#" hide="#attributes.hide#" label="#attributes.label#">
</cfcase>
<cfcase value="7">
<cfdump var="#attributes.var#" expand="#attributes.expand#" hide="#attributes.hide#" label="#attributes.label#" top="#attributes.top#">
</cfcase>
<cfdefaultcase>
<cfdump var="#attributes.var#" expand="#attributes.expand#" format="#attributes.format#" hide="#attributes.hide#" keys="#attributes.keys#" label="#attributes.label#" metainfo="#attributes.metainfo#" output="#attributes.output#" show="#attributes.show#" showUDFs="#attributes.showUDFs#" top="#attributes.top#">
</cfdefaultcase>
</cfswitch>
</cfsavecontent>
<cfif attributes.format neq "text" and attributes.output is "browser">
<cfset DumpResults = rereplace(DumpResults, "[[:space:]]{2,}", " ", "all")>
<cfset DumpResults = replace(DumpResults, "> <", "><", "all")>
<cfset DumpResults = rereplace(DumpResults, "<!--[^>]+>", "", "all")>
</cfif>
<cfsetting enablecfoutputonly="No">
<cfoutput>#DumpResults#</cfoutput>
<cfif yesnoformat(attributes.abort)>
<cfabort>
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment