Skip to content

Instantly share code, notes, and snippets.

@pbuzdin
Created August 14, 2018 22:40
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 pbuzdin/6082ef00dc0126dfc43c3a6bff18ff1a to your computer and use it in GitHub Desktop.
Save pbuzdin/6082ef00dc0126dfc43c3a6bff18ff1a to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/giridihoti
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<p>hui</p>
<script>
var templite = function (str, mix) {
return str.replace(RGX, function (x, key, y) {
x = 0;
y = mix;
key = key.trim().split('.');
while (y && x < key.length) {
y = y[key[x++]];
}
return y != null ? y : '';
});
};
var RGX = /{{(.*?)}}/g;
document.querySelector('p').innerText = templite('Hello {{name}}!', { name: 'world' })
//document.write(templite('ты {{name}}!', { name: 'пидор' }))
document.write(templite(`
<b>Ты {{name}}!</b>
<h1>alert('hui')</h1>
`, { name: 'пидорjr' }))
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment