Last active
March 6, 2016 08:38
-
-
Save DominicWatson/d6ce9527fa3294b286cc to your computer and use it in GitHub Desktop.
Example for code review: http://codereview.stackexchange.com/questions/121963/filtering-the-attributes-for-a-custom-tag/121969#121969
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
<cfscript> | |
struct function stripNonDataNgAndJsAttributes( required struct attributes ) { | |
var patternToKeep = "^((data|ng)\-|on)\S"; | |
return attributes.filter( function( key, value ){ | |
return key.reFindNoCase( patternToKeep ); | |
} ); | |
} | |
string function structToQueryString( required struct input ) { | |
return input.reduce( function( result, key, value ){ | |
return result & ' #key.lCase()#="#value.encodeForHTMLAttribute()#"'; | |
}, "" ); | |
} | |
attributes = { | |
"data-test" = "test" | |
, "ng-dang" = "fubar" | |
, "onSubmit" = "yes" | |
, test = 0 | |
}; | |
filtered = stripNonDataNgAndJsAttributes( attributes ); | |
qs = structToQueryString( filtered ); | |
WriteOutput( qs ); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment