forked from 340CT-1819SEPJAN/TEACHING-MATERIALS
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
node_modules/ | ||
coverage/ | ||
public/ | ||
views/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const Koa = require('koa') | ||
const Router = require('koa-router') | ||
const bodyParser = require('koa-bodyparser') | ||
const views = require('koa-views') | ||
|
||
const app = new Koa() | ||
app.use(bodyParser()) | ||
app.use(require('koa-static')('public')) | ||
|
||
app.use(views(`${__dirname}/views`, { extension: 'handlebars' }, { | ||
map: { | ||
handlebars: 'handlebars' | ||
} | ||
})) | ||
|
||
const router = new Router() | ||
|
||
const port = 8080 | ||
|
||
router.get('/', async ctx => { | ||
await ctx.render('home') | ||
}) | ||
|
||
router.get('/date', async ctx => { | ||
const d = new Date() | ||
const date = `${d.getDate()}/${d.getMonth()+1}/${d.getFullYear()}` | ||
const data = { | ||
title: 'My First Template', | ||
today: date | ||
} | ||
await ctx.render('date', data) | ||
}) | ||
|
||
router.get('/food', async ctx => { | ||
const food = [ | ||
{name: 'bread', qty: 5}, | ||
{name: 'butter', qty: 2}, | ||
{name: 'jam', qty: 1}, | ||
{name: 'cheese', qty: 4} | ||
] | ||
await ctx.render('food', {myFood: food}) | ||
}) | ||
|
||
app.use(router.routes()) | ||
app.use(router.allowedMethods()) | ||
const server = app.listen(port) | ||
|
||
module.exports = server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
p, h2 { | ||
font-family: verdana, sans-serif; | ||
} | ||
|
||
h2 { | ||
color: #666; | ||
} | ||
|
||
img { | ||
float: right; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<h1>{{title}}</h1> | ||
<p>This server date is {{today}}</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<h2>My Favourite Food</h2> | ||
<ol> | ||
{{#each myFood}} | ||
<li>{{this.name}}</li> | ||
{{/each}} | ||
</ol> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{{name}}</title> | ||
</head> | ||
<body> | ||
<h2>Handlebars</h2> | ||
<p><img src="images/clock_small.png" /></p> | ||
<p>This page has been generated by the <strong>Handlebars</strong> template engine.</p> | ||
</body> | ||
</html> |