This repository was archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin1.html
More file actions
48 lines (42 loc) · 1.34 KB
/
Copy pathplugin1.html
File metadata and controls
48 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Plugin #01</title>
<link rel='stylesheet' href='css/estilo.css'>
<script src='js/jquery.js'></script>
</head>
<body class='conteudo exercicio'>
<h1>Plugin #01</h1>
<div>
{{ 1 + 2 }}
Texto 1
{{ 3 ** 3 }}
Texto 2
{{ console.log('Funcionou!') }}
Texto 3
{{ (function() { return 'Legal!!!' })() }}
Texto Final
</div>
<script>
// const $ = { nome: 'Não é o jQuery' }
(function ($) {
$.fn.interpretar = function () {
const retirarChaves = s => s.substring(2, s.length - 2)
const conteudo = $(this).html()
const expressoesComChaves = conteudo.match(/\{\{.+\}\}/g)
const expressoes = expressoesComChaves.map(retirarChaves)
const resultados = expressoes.map(e => eval(e))
let conteudoFinal = conteudo
for (let i = 0; i < expressoesComChaves.length; i++) {
conteudoFinal = conteudoFinal.replace(
expressoesComChaves[i], resultados[i]
)
}
$(this).html(conteudoFinal)
return this
}
})(jQuery)
$('div').interpretar()
</script>
</body>