-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3-Website.coffee
More file actions
67 lines (59 loc) · 1.62 KB
/
3-Website.coffee
File metadata and controls
67 lines (59 loc) · 1.62 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
###
This is a module:
###
express = require 'express'
###
modules hold a bunch of related functions.
###
###
For Example the express module creates a web server:
###
WebServer = express()
port=3456
WebServer.listen port, ->
console.log "listening at #{port}"
WebServer.get '/' , (req,res)->
res.send index
WebServer.get '/' , (req,res)->
res.send index
###
This is as simpe as a webserver gets. Listen on a local port, return a string
when there is a get request.
Websites are served in another programming language called HTML.
Coffeekup is a module that turns coffeescript into a templating language
It converts (renders) HTML from a coffeescript function.
Lets try and serve some HTML instead of a string:
###
ck = require 'coffeekup'
# Coffeekup converts coffeescript to HTML
html = ->
link
rel:'stylesheet'
href:"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"
div ".container", ->
h1 "Hello World in a BROWSER"
form ->
label "Name"
input type:'text', class:"form-control"
label 'Birthdate'
input type:'date', class:"form-control"
label 'Seeking'
select class:"form-control" , ->
option 'Male'
option 'Female'
option 'Cats'
input type:"submit"
i = 0
while i<10000
span "#{i} "
i++
script src:'bundle.js', type:'text/javascript'
style """
html div {color:yellow;background:green;}
span {color:white; background:black;}
input {color:black;}
"""
### to server the script file we need to tell our
WebServer where to look: ###
WebServer.use(express.static 'public')
index = ck.render html