Skip to content

Commit 16893d8

Browse files
committed
Merge branch 'develop'
2 parents 181568e + fd81ba9 commit 16893d8

File tree

5 files changed

+142
-18
lines changed

5 files changed

+142
-18
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*]
2+
indent_style = space
3+
indent_size = 2
4+
tab_width = 8
5+
max_line_length = 80
6+
trim_trailing_whitespace = false
7+
end_of_line = lf
8+
insert_final_newline = true

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ declarative DSL to setup MacroExpress routes.
2828

2929
The Macro [Examples](https://github.com/Macro-swift/Examples) package
3030
contains a few examples which all can run straight from the source as
31-
swift-sh scripts.
31+
[swift-sh](https://github.com/mxcl/swift-sh) scripts.
3232

3333
```swift
3434
#!/usr/bin/swift sh
@@ -80,5 +80,10 @@ app.listen(1337)
8080
We like feedback, GitHub stars, cool contract work,
8181
presumably any form of praise you can think of.
8282

83-
There is a `#microexpress` channel on the
84-
[Noze.io Slack](http://slack.noze.io/). Feel free to join!
83+
**Want to support my work**?
84+
Buy an app:
85+
[Code for SQLite3](https://apps.apple.com/us/app/code-for-sqlite3/id1638111010),
86+
[Past for iChat](https://apps.apple.com/us/app/past-for-ichat/id1554897185),
87+
[SVG Shaper](https://apps.apple.com/us/app/svg-shaper-for-swiftui/id1566140414),
88+
[HMScriptEditor](https://apps.apple.com/us/app/hmscripteditor/id1483239744).
89+
You don't have to use it! 😀

Sources/dotenv/dotenv.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// MacroExpress
44
//
55
// Created by Helge Heß on 02.07.20.
6-
// Copyright © 2020 ZeeZide GmbH. All rights reserved.
6+
// Copyright © 2020-2024 ZeeZide GmbH. All rights reserved.
77
//
88

99
#if os(Linux)
@@ -17,13 +17,25 @@ import func MacroCore.__dirname
1717
import func fs.accessSync
1818
import let fs.R_OK
1919

20+
/**
21+
* How to use:
22+
*
23+
* ```swift
24+
* import dotenv
25+
*
26+
* dotenv.config()
27+
* ```
28+
*
29+
* This reads the `.env` file (located using `__dirname`),
30+
* and adds the contents to the environment of the running process.
31+
*/
2032
public enum dotenv {}
2133

2234
public extension dotenv {
2335

2436
#if swift(>=5.3) // oh this mess
2537
/**
26-
* Read the .env config file, apply it to the environment, and return the
38+
* Read the .env config file, apply it on the environment, and return the
2739
* parsed values.
2840
*
2941
* Important: Remember to call this as early as possible, otherwise Foundation

Sources/express/Express.swift

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,61 @@ open class Express: SettingsHolder, MountableMiddlewareObject, MiddlewareObject,
149149

150150
// MARK: - SettingsHolder
151151

152-
public func set(_ key: String, _ value: Any?) {
152+
/**
153+
* Sets or removes a configuration key in the settings store.
154+
*
155+
* Example:
156+
* ```swift
157+
* app.set("view engine", "html")
158+
* .set("views", __dirname() + "/views")
159+
* ```
160+
*
161+
* - Parameters:
162+
* - key: The name of the key, e.g. "view engine"
163+
* - value: The associated value, if `nil` is passed in, the value is
164+
* removed from the store.
165+
* - Returns: `self` for chaining.
166+
*/
167+
@discardableResult
168+
public func set(_ key: String, _ value: Any?) -> Self {
153169
if let v = value { settingsStore[key] = v }
154170
else { settingsStore.removeValue(forKey: key) }
171+
return self
155172
}
173+
174+
/**
175+
* Returns the value of a configuration key from the settings store.
176+
*
177+
* Example:
178+
* ```swift
179+
* let engine = app.get("view engine")
180+
* ```
181+
*
182+
* - Parameters:
183+
* - key: The name of the key, e.g. "view engine"
184+
* - Returns: The value in the store, or `nil` if missing.
185+
*/
156186
public func get(_ key: String) -> Any? {
157187
return settingsStore[key]
158188
}
159189

190+
160191
// MARK: - Engines
161192

162-
var engines = [ String : ExpressEngine]()
193+
var engines = [ String : ExpressEngine ]()
163194

164-
public func engine(_ key: String, _ engine: @escaping ExpressEngine) {
195+
/**
196+
* Sets an engine implementation.
197+
*
198+
* Example:
199+
* ```swift
200+
* app.engine("mustache", mustacheExpress)
201+
* ```
202+
*/
203+
@discardableResult
204+
public func engine(_ key: String, _ engine: @escaping ExpressEngine) -> Self {
165205
engines[key] = engine
206+
return self
166207
}
167208

168209

Sources/express/Settings.swift

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,89 @@
77
//
88

99
/**
10-
* Just a special kind of dictionary. The `Express` application class is
10+
* Just a special kind of dictionary. The ``Express`` application class is
1111
* currently the sole example.
1212
*
1313
* Examples:
14+
* ```swift
15+
* app.set("env", "production")
16+
* app.enable("x-powered-by")
1417
*
15-
* app.set("env", "production")
16-
* app.enable("x-powered-by")
17-
*
18-
* let env = app.settings.env
18+
* let env = app.settings.env
19+
* ```
1920
*/
2021
public protocol SettingsHolder {
2122

22-
func set(_ key: String, _ value: Any?)
23+
/**
24+
* Sets or removes a configuration key in the settings store.
25+
*
26+
* Example:
27+
* ```swift
28+
* app.set("view engine", "html")
29+
* .set("views", __dirname() + "/views")
30+
* .enable("x-powered-by")
31+
* ```
32+
*
33+
* - Parameters:
34+
* - key: The name of the key, e.g. "view engine"
35+
* - value: The associated value, if `nil` is passed in, the value is
36+
* removed from the store.
37+
* - Returns: `self` for chaining.
38+
*/
39+
@discardableResult
40+
func set(_ key: String, _ value: Any?) -> Self
41+
42+
/**
43+
* Returns the value of a configuration key from the settings store.
44+
*
45+
* Example:
46+
* ```swift
47+
* let engine = app.get("view engine")
48+
* ```
49+
*
50+
* - Parameters:
51+
* - key: The name of the key, e.g. "view engine"
52+
* - Returns: The value in the store, or `nil` if missing.
53+
*/
2354
func get(_ key: String) -> Any?
2455
}
2556

2657
public extension SettingsHolder {
2758

59+
/**
60+
* Set configuration key in the settings store to `true`.
61+
*
62+
* Example:
63+
* ```swift
64+
* app.enable("x-powered-by")
65+
* ```
66+
*
67+
* - Parameters:
68+
* - key: The name of the bool key, e.g. "view engine"
69+
* - Returns: `self` for chaining.
70+
*/
2871
@inlinable
29-
func enable(_ key: String) {
30-
set(key, true)
72+
@discardableResult
73+
func enable(_ key: String) -> Self {
74+
return set(key, true)
3175
}
76+
77+
/**
78+
* Set configuration key in the settings store to `false`.
79+
*
80+
* Example:
81+
* ```swift
82+
* app.disable("x-powered-by")
83+
* ```
84+
*
85+
* - Parameters:
86+
* - key: The name of the bool key, e.g. "view engine"
87+
* - Returns: `self` for chaining.
88+
*/
3289
@inlinable
33-
func disable(_ key: String) {
34-
set(key, false)
90+
@discardableResult
91+
func disable(_ key: String) -> Self {
92+
return set(key, false)
3593
}
3694

3795
@inlinable

0 commit comments

Comments
 (0)