-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (63 loc) · 1.6 KB
/
index.js
File metadata and controls
70 lines (63 loc) · 1.6 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
console.log(`Tools active:`);
var underscore = require('underscore');
var fs = require('fs');
/**
* Builds an html file with the arguments passed to it inside the body
* @param {string} str the arguments to inject at the <body> tag
* @return {file} builds the HTML file
*/
var build = function(str) {
var template = underscore.template(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Toole ex.</title>
</head>
<body>
<%=text%>
</body>
</html>`);
var comp = template({
text: str,
});
return fs.writeFile('./index.html', comp);
};
/**
* Creates an <h1> tag with a string passed to the function
* @param {string} str the string arg. to inject
* @return {string} the compiled <h1> tag
*/
var head = function(str) {
var template = underscore.template('<h1><%=text%></h1>');
var comp = template({
text: str,
});
return comp;
};
/**
* Creates a <ul> tag with an <li>'s nested strings array passed to the function
* @param {array} textarray the array arg. to inject
* @return {string} the compiled <ul> tag with the nested <li>'s.
*/
var ul = function(textarray) {
var compiled = underscore.template(`<ul>
<% for(var i = 0; i< array.length; i++) { %>
<li><%=array[i]%></li>
<% } %>
</ul>`);
return compiled({
array: textarray,
});
};
module.exports = (function() {
return {
build: build,
head: head,
ul: ul,
};
})();
// var tools = require('./index.js');
// var h1 = tools.head('hello world');
// var newUl = tools.ul(['1', '2']);
// tools.build(h1 + newUl);
// console.log(h1);