Django like templates in Javascript
Here's a quick ‘n’ dirty Javascript function I hacked together that provides Django-like template substitution.
function sformat(template, data) { return template.replace(/{{(.*?)}}/g, function(m, n) { return eval('data.'+n); }); }
Used something like this:
sformat("Hello, {{ name }}!", {name:"World"});
Which returns the following string:
Hello, World!
Alas, it doesn't support anything other than substitution. If you need anything more advanced (loops etc), you should investigate Javascript template engines.
There's always a way
Spotted in a deli in Oxford. It says ‘Where there is a Will, there is always a way’.
Thats right – always a way!
Just saying.
Fuzzy Thinking
I have an idea germinating that involves using fuzzy logic, something I only had a passing knowledge of. After reading the Wikipedia articles and Googling for it I'm more informed but still haven't found a perfect resource.
The only Python code I have found was informative, but it was from way back in 1990. If there are any Pythonistas who know of a more up-to-date fuzzy logic module, or fuzzy logic resource in general, please let me know!
-
4 posts
-
2 posts
-
2 posts
-
1 post
-
6 posts
-
1 post
-
1 post
-
3 posts
-
11 posts
-
6 posts
-
4 posts
-
1 post
-
1 post
-
1 post
-
5 posts
-
5 posts
-
1 post
-
6 posts
-
1 post
-
9 posts
-
2 posts
-
4 posts
-
3 posts
-
14 posts
-
3 posts
-
7 posts
-
7 posts
-
16 posts
-
8 posts
-
2 posts
-
1 post