Skip to content

Instantly share code, notes, and snippets.

@laispace
Created May 16, 2014 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laispace/f970f5ff8e22488c73cf to your computer and use it in GitHub Desktop.
Save laispace/f970f5ff8e22488c73cf to your computer and use it in GitHub Desktop.
void function() {
function format(template, json) {
return template.replace(/#\{(.*?)\}/g, function(all, key) {
return json && (key in json) ? json[key] : "";
});
}
document.getElementById('panel').innerHTML = format(
String(function(){/*!
<ul>
<li>#{title} -- #{date}</li>
<li>把模板放在注释里</li>
<li>这样就可以写多行了。。。</li>
</ul>
*/}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, ''),
{
title: "代码里的模板",
date: "2014-05-16"
}
);
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment