-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
110 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# logue | ||
Command tools for Prologue in Nim. | ||
|
||
## Usage | ||
Use `logue init yourprojectname` to initialize your project. |
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 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "flywind" | ||
description = "Command line tools for Prologue." | ||
license = "Apache-2.0" | ||
srcDir = "src" | ||
bin = @["logue"] | ||
|
||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 1.2.0" | ||
requires "cligen >= 1.1.0" |
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,10 @@ | ||
import cligen | ||
|
||
import loguepkg/create | ||
|
||
|
||
proc main*() = | ||
dispatchMulti([init]) | ||
|
||
when isMainModule: | ||
main() |
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,42 @@ | ||
import os, strformat | ||
|
||
|
||
proc getEnvContent(appName: string): string = | ||
result = fmt"""# Don't commit this to source control. | ||
# Eg. Make sure ".env" in your ".gitignore" file. | ||
# If you want to release you programs, make sure debug=false. | ||
debug=true | ||
port=8080 | ||
appName={appName} | ||
staticDir=/static | ||
secretKey=Pr435ol67ogue | ||
""" | ||
|
||
|
||
proc initProject(projName: string) = | ||
createDir(projName) | ||
let | ||
appFile = projName / "app.nim" | ||
urlsFile = projName / "urls.nim" | ||
viewsFile = projName / "views.nim" | ||
envFile = projName / ".env" | ||
|
||
let path = currentSourcePath().splitPath.head | ||
|
||
copyFile(path / "tml" / "app.nim", appFile) | ||
copyFile(path / "tml" / "urls.nim", urlsFile) | ||
copyFile(path / "tml" / "views.nim", viewsFile) | ||
writeFile(envFile, getEnvContent(projName)) | ||
|
||
|
||
|
||
proc init*(name: seq[string]) = | ||
if name.len == 0: | ||
echo "Please give the name of your project!" | ||
else: | ||
let projName = name[0] | ||
if dirExists(projName): | ||
echo fmt"{projName} already exists!" | ||
else: | ||
createDir(projName) | ||
initProject(projName) |
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,9 @@ | ||
# Don't commit this to source control. | ||
# Eg. Make sure ".env" in your ".gitignore" file. | ||
# If you want to release you programs, make sure debug=false. | ||
debug=true | ||
address=127.0.0.2 | ||
port=8787 | ||
appName=HelloWorld | ||
staticDir=/static | ||
secretKey=Pr435ol67ogue |
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,17 @@ | ||
import prologue | ||
|
||
import ./urls | ||
|
||
let | ||
env = loadPrologueEnv(".env") | ||
settings = newSettings(appName = env.getOrDefault("appName", "Prologue"), | ||
debug = env.getOrDefault("debug", true), | ||
port = Port(env.getOrDefault("port", 8080)), | ||
staticDirs = [env.get("staticDir")], | ||
secretKey = env.getOrDefault("secretKey", "") | ||
) | ||
|
||
|
||
var app = newApp(settings = settings) | ||
app.addRoute(urls.urlPatterns, "/") | ||
app.run() |
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,9 @@ | ||
import prologue | ||
|
||
import ./views | ||
|
||
|
||
let urlPatterns* = @[ | ||
# strip latter | ||
pattern("/", hello) | ||
] |
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 @@ | ||
import prologue | ||
|
||
|
||
proc hello*(ctx: Context) {.async.} = | ||
resp "<h1>Hello, Prologue!</h1>" |