Skip to content

Instantly share code, notes, and snippets.

@juner
Created December 13, 2012 13:50
Show Gist options
  • Save juner/4276478 to your computer and use it in GitHub Desktop.
Save juner/4276478 to your computer and use it in GitHub Desktop.
Hello RND templateEngine
RND templateEngineの Hello Worldでも。
元ネタ的には
http://amix.dk/blog/viewEntry/163
なのだけれど、使ってる人って居るんかな。
test1
$(X)で囲った箇所を指定した変数によって置き換えてます。
test2
$(X|func)の形式でfunc(X)を実現してます。
以上!
body { background-color: #DDDDDD; font: 30px sans-serif; }
<div id="test1"><span>%(H)%(W)</span><span>%(RND)</span></div>
<div id="test2"><span>%(value)*2=%(value|timesTwo)</span></div>
{//test1
var test1 = jQuery("#test1");
var template = test1.html();
var values ={
"H":"Hello ",
"W":"World ",
"RND":"RND Template Engine"
};
var output = RND(template,values);
test1.html(output);
}{//test2
var test2 = jQuery("#test2");
var template = test2.html();
var values = {
"value":5.5
};
var funcs = {
"timesTwo":function(v){
return v*2;
}
};
var output = RND(template,values,funcs);
test2.html(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment