-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
88 lines (72 loc) · 2.06 KB
/
example.js
File metadata and controls
88 lines (72 loc) · 2.06 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function testUsingText() {
/*
* Some DOM Element on your web page is to be the recipient
* of the processed EJS fragment. This element is assigned
* to *output*.
*/
var output = $('output_results');
/* Create some fragment of EJS code. Variables from the
* current scope can be used inside the current EJS code.
*/
var animals = ['sloth', 'bear', 'monkey'];
var ejs = "<ul>[% animals.each(function(animal){%]" +
"<li>[%= animal %]</li>" +
"[%});%]</ul>";
/*
* Create a new compiler and pass it a reference to the DOM
* node containing the source.
*/
var compiler = new EjsCompiler(ejs);
/*
* Call the compile() function
*/
compiler.compile();
/*
* View the compiled results
*/
$('output_code').innerHTML = compiler.out.escapeHTML();
/*
* Evaluate the compiled EJS code and save the output as
* the string *compiled*. This string contains the result.
*/
var compiled = eval(compiler.out);
/*
* Set the inner HTML of the output node to the result.
*/
output.innerHTML = compiled;
}
function testUsingDOM() {
/*
* Some DOM Element on your web page has EJS source code
* within it. This element is assigned to *source*
*
* Some DOM Element on your web page is to be the recipient
* of the processed EJS fragment. This element is assigned
* to *output*.
*
*/
var source = $('source_code');
var output = $('output_results');
/*
* Create a new compiler and pass it a reference to the DOM
* node containing the source
*/
var compiler = new EjsCompiler(source);
/*
* Call the compile() function
*/
compiler.compile();
/*
* View the compiled results
*/
$('output_code').innerHTML = compiler.out.escapeHTML();
/*
* Evaluate the compiled EJS code and save the output as
* the string *compiled*. This string contains the result.
*/
var compiled = eval(compiler.out);
/*
* Set the inner HTML of the output node to the result.
*/
output.innerHTML = compiled;
}