Last active
December 10, 2015 18:08
-
-
Save jhoff/4472665 to your computer and use it in GitHub Desktop.
freemarker vardump for javascript
This file contains hidden or 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
<#macro vardump v> | |
<script> | |
var method = function(){}, | |
transform = function(){}, | |
macro = function(){}, | |
hash_ex = function(){}, | |
hash = function(){}, | |
sequence = function(){}, | |
collection = function(){}, | |
directive = function(){}, | |
node = function(){}, | |
unknown = function(){}, | |
obj = {}; | |
<#list v?keys as prop> | |
<#if !v[prop]??> | |
obj["${prop}"] = undefined; | |
<#elseif v[prop]?is_number> | |
obj["${prop}"] = ${v[prop]}; | |
<#elseif v[prop]?is_boolean> | |
obj["${prop}"] = <#if v[prop]>true<#else>false</#if>; | |
<#elseif v[prop]?is_string || v[prop]?is_date> | |
obj["${prop}"] = decodeURIComponent("${v[prop]?url}".replace(/\+/g, ' ')); | |
<#elseif v[prop]?is_method> | |
obj["${prop}"] = new method; | |
<#elseif v[prop]?is_transform> | |
obj["${prop}"] = new transform; | |
<#elseif v[prop]?is_macro> | |
obj["${prop}"] = new macro; | |
<#elseif v[prop]?is_hash_ex> | |
obj["${prop}"] = new hash_ex; | |
<#elseif v[prop]?is_hash> | |
obj["${prop}"] = new hash; | |
<#elseif v[prop]?is_sequence> | |
obj["${prop}"] = new sequence; | |
<#elseif v[prop]?is_collection> | |
obj["${prop}"] = new collection; | |
<#elseif v[prop]?is_directive> | |
obj["${prop}"] = new directive; | |
<#elseif v[prop]?is_node> | |
obj["${prop}"] = new node; | |
<#else> | |
obj["${prop}"] = new unknown; | |
</#if> | |
</#list> | |
console.log(obj); | |
</script> | |
</#macro> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment