Skip to content

Commit d1915e6

Browse files
committed
Merge branch 'develop'
2 parents e00af59 + 7b8e5b4 commit d1915e6

File tree

5 files changed

+57
-40
lines changed

5 files changed

+57
-40
lines changed

.travis.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ matrix:
77
include:
88
- os: Linux
99
dist: trusty
10-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0.2-release/ubuntu1404/swift-5.0.2-RELEASE/swift-5.0.2-RELEASE-ubuntu14.04.tar.gz"
10+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0.3-release/ubuntu1404/swift-5.0.3-RELEASE/swift-5.0.3-RELEASE-ubuntu14.04.tar.gz"
1111
sudo: required
1212
- os: Linux
1313
dist: trusty
14-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.1.3-release/ubuntu1404/swift-5.1.3-RELEASE/swift-5.1.3-RELEASE-ubuntu14.04.tar.gz"
14+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.1.5-release/ubuntu1404/swift-5.1.5-RELEASE/swift-5.1.5-RELEASE-ubuntu14.04.tar.gz"
15+
sudo: required
16+
- os: Linux
17+
dist: xenial
18+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.2.4-release/ubuntu1604/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-ubuntu16.04.tar.gz"
1519
sudo: required
1620
- os: osx
1721
osx_image: xcode11
22+
- os: osx
23+
osx_image: xcode11.4
1824

1925
before_install:
2026
- ./.travis.d/before-install.sh

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ This repository contains examples for
1313

1414
### Running Examples as Scripts
1515

16-
Single file examples can be run as scripts using [swift-sh](https://github.com/mxcl/swift-sh),
17-
which can be installed using a simple `brew install mxcl/made/swift-sh`.
16+
Examples can be run as scripts using [swift-sh](https://github.com/mxcl/swift-sh)
17+
(can be installed using a simple `brew install mxcl/made/swift-sh`).
1818

1919
Example:
2020
```
2121
$ Sources/httpd-helloworld/main.swift
2222
2020-01-07T17:14:35+0100 notice: Server listening on http://localhost:1337/
23+
24+
$ Sources/express-simple/main.swift
25+
2020-06-03T14:58:59+0200 notice: Server listening on http://localhost:1337
2326
```
2427

28+
Looks like this:
29+
![MacroExpress Simple Screenshot](https://zeezide.de/img/macro/MacroExpressSimple.png)
30+
31+
2532
### Who
2633

2734
**Macro** is brought to you by

Sources/connect-static/main.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/swift sh
22

33
import Foundation
4-
import MacroExpress // @Macro-swift ~> 0.0.3
4+
import MacroExpress // @Macro-swift ~> 0.0.4
55

66
let dirname = __dirname()
77

@@ -11,8 +11,8 @@ app.use(logger("dev"))
1111
app.use(serveStatic(__dirname() + "/public"))
1212

1313
app.use { req, res, next in
14-
guard req.url == "/" else { return next() }
15-
res.redirect("/index.html")
14+
guard req.url == "/" else { return next() }
15+
res.redirect("/index.html")
1616
}
1717

1818
app.listen(1337) {

Sources/express-simple/main.swift

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/swift sh
22

3-
import MacroExpress // @Macro-swift ~> 0.0.3
3+
import MacroExpress // @Macro-swift ~> 0.0.4
44
import cows // @AlwaysRightInstitute ~> 1.0.0
55

66
let app = express()
@@ -20,77 +20,77 @@ app.set("views", __dirname() + "/views")
2020
// MARK: - Session View Counter
2121

2222
app.use { req, _, next in
23-
req.session["viewCount"] = req.session[int: "viewCount"] + 1
24-
next()
23+
req.session["viewCount"] = req.session[int: "viewCount"] + 1
24+
next()
2525
}
2626

2727

2828
// MARK: - Routes
2929

3030
let taglines = [
31-
"Less than Perfect.",
32-
"Das Haus das Verrückte macht.",
33-
"Rechargeables included",
34-
"Sensible Server Side Swift aS a Successful Software Service Solution"
31+
"Less than Perfect.",
32+
"Das Haus das Verrückte macht.",
33+
"Rechargeables included",
34+
"Sensible Server Side Swift aS a Successful Software Service Solution"
3535
]
3636

3737

3838
// MARK: - Form Handling
3939

4040
app.get("/form") { _, res, _ in
41-
res.render("form")
41+
res.render("form")
4242
}
4343
app.post("/form") { req, res, _ in
44-
let user = req.body[string: "u"]
45-
console.log("USER IS: \(user)")
44+
let user = req.body[string: "u"]
45+
console.log("USER IS: \(user)")
4646

47-
let options : [ String : Any ] = [
48-
"user" : user,
49-
"nouser" : user.isEmpty,
50-
"viewCount" : req.session["viewCount"] ?? 0
51-
]
52-
res.render("form", options)
47+
let options : [ String : Any ] = [
48+
"user" : user,
49+
"nouser" : user.isEmpty,
50+
"viewCount" : req.session["viewCount"] ?? 0
51+
]
52+
res.render("form", options)
5353
}
5454

5555

5656
// MARK: - JSON & Cookies
5757

5858
app.get("/json") { _, res, _ in
59-
res.json([
60-
[ "firstname": "Donald", "lastname": "Duck" ],
61-
[ "firstname": "Dagobert", "lastname": "Duck" ]
62-
])
59+
res.json([
60+
[ "firstname": "Donald", "lastname": "Duck" ],
61+
[ "firstname": "Dagobert", "lastname": "Duck" ]
62+
])
6363
}
6464

6565
app.get("/cookies") { req, res, _ in
66-
// returns all cookies as JSON
67-
res.json(req.cookies)
66+
// returns all cookies as JSON
67+
res.json(req.cookies)
6868
}
6969

7070

7171
// MARK: - Cows
7272

7373
app.get("/cows") { _, res, _ in
74-
res.send("<html><body><pre>\(cows.vaca())</pre></body></html>")
74+
res.send("<html><body><pre>\(cows.vaca())</pre></body></html>")
7575
}
7676

7777

7878
// MARK: - Main page
7979

8080
app.get("/") { req, res, _ in
81-
let tagline = taglines.randomElement()!
81+
let tagline = taglines.randomElement()!
8282

83-
let values : [ String : Any ] = [
84-
"tagline" : tagline,
85-
"viewCount" : req.session["viewCount"] ?? 0,
86-
"cowOfTheDay" : cows.vaca()
87-
]
88-
res.render("index", values)
83+
let values : [ String : Any ] = [
84+
"tagline" : tagline,
85+
"viewCount" : req.session["viewCount"] ?? 0,
86+
"cowOfTheDay" : cows.vaca()
87+
]
88+
res.render("index", values)
8989
}
9090

9191

9292
// MARK: - Start Server
9393

9494
app.listen(1337) {
95-
console.log("Server listening: \($0)")
95+
console.log("Server listening on http://localhost:1337")
9696
}

Sources/express-simple/views/index.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{{> header}}
22

3+
<p>
4+
Reload page for a new cow and tagline!
5+
</p>
6+
37
<pre style="border: 1px solid #DEDEDE; margin: 1em; padding: 0.5em;"
48
>{{cowOfTheDay}}</pre>
59

610
<div class="menu-centered">
711
<ul class="menu">
8-
<li><a href="/form">Form</a></li>
9-
<li><a href="https://github.com/Macro-swift">Macro</a></li>
12+
<li><a href="/form">Form Demo</a></li>
13+
<li><a href="https://github.com/Macro-swift">Macro.swift</a></li>
1014
</ul>
1115
</div>
1216

0 commit comments

Comments
 (0)