forked from matthew-andrews/workshop-making-it-work-offline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.js
48 lines (44 loc) · 1.1 KB
/
templates.js
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
(function() {
var exports = {
list: list,
article: article
};
function list(data) {
var ul = '';
data.forEach(function(story) {
ul += '<li><a class="js-link" href="/article/'+story.guid+'">'+story.title+'</a></li>';
});
return shell({
main: '<h1>FT Tech Blog</h1><ul>'+ul+'</ul>'
});
}
function article(data) {
return shell({
title: data.title,
main: '<nav><a class="js-link" href="/">» Back to FT Tech Blog</a></nav><h1>'+data.title+'</h1>'+data.body
});
}
function shell(data) {
data = {
title: data && data.title || 'FT Tech News',
main: data && data.main || ''
};
return '<!DOCTYPE html>'
+ '\n<html>'
+ '\n <head>'
+ '\n <title>'+data.title+'</title>'
+ '\n <link rel="stylesheet" href="/styles.css" type="text/css" media="all" />'
+ '\n </head>'
+ '\n <body>'
+ '\n <main>'+data.main+'</main>'
+ '\n <script src="/templates.js"></script>'
+ '\n <script src="/application.js"></script>'
+ '\n </body>'
+ '\n</html>';
}
if (typeof module == 'object') {
module.exports = exports;
} else {
this.templates = exports;
}
}());