Created
January 3, 2012 22:25
-
-
Save phated/1557270 to your computer and use it in GitHub Desktop.
Extremely basic concept for a templating engine
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
<html> | |
<head> | |
</head> | |
<body> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var template = { | |
div : 'test' | |
} | |
function html(key, value) { | |
if (key !== '') { | |
var element = ['<',key,'>',value,'</',key,'>'].join(''); | |
return element; | |
} | |
return value; | |
} | |
var jsonString = JSON.stringify(template, html); | |
var parsed = JSON.parse(jsonString); | |
for(element in parsed) { | |
$('body').prepend(parsed[element]); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment