Skip to content

Instantly share code, notes, and snippets.

@northofnormal
Created January 8, 2020 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save northofnormal/23adf9442f279db5fd5df97975ddaad3 to your computer and use it in GitHub Desktop.
Save northofnormal/23adf9442f279db5fd5df97975ddaad3 to your computer and use it in GitHub Desktop.
Server Side Swift JSON, HTML, and other copyables
// sample JSON post
{
"title": "Server Side Swift Saves CodeMash",
"presenter": "Anne Cahalan",
"notes": "This is the superbest session I am learning so much!!!",
"rating": 10
}
// that gnarly Docker command
docker run --name notes -e MYSQL_USER=vapor -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=vapor -p 3306:3306 -d mysql/mysql-server:5.7
// Index1
<h1>Hello CodeMash!</h1>
#if(notes) {
<table>
<thead>
<tr>
<th>Session title></th>
<th>Presenter</th>
</tr>
</thead>
<tbody>
#for(note in notes) {
<tr>
<td>#(note.title)</td>
<td>#(note.presenter)</td>
<tr>
}
</tbody>
</table>
} else {
<h2>You don't have any notes yet!</h2>
}
// Display Note html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>#(title) | Notes</title>
</head>
<body>
<h1>#(title)</h1>
<h2>#(presenter)</h2>
<p>#(notes)</p>
<p>Rating: #(rating)</p>
</body>
</html>
// base.leaf boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hello CodeMash!</title>
</head>
<body>
</body>
</html>
// base div
<div class="container mt-3">
#get(content)
</div>
// Create Note HTML
#set("content") {
<h1>#(title)</h1>
<form method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" class="form-control" id="title"/>
</div>
<div class="form-group">
<label for="presenter">Presenter</label>
<input type="text" name="presenter" class="form-control" id="presenter"/>
</div>
<div class="form-group">
<label for="notes">Notes</label>
<input type="text" name="notes" class="form-control" id="notes"/>
</div>
<div class="form-group">
<label for="rating">Rating</label>
<input type="text" name="rating" class="form-control" id="rating"/>
</div>
<button type="submit" class="btn btn-primary">
Submit
</button>
</form>
}
#embed("base")
// Create Nav Link
<li class="nav-itetm #if(title != "Create A Note"){active}">
<a href="/notes/create" class="nav-link">Create a Note</a>
</li>
// Create With Edit Button
#set("content") {
<h1>#(title)</h1>
<form method="post">
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" class="form-control" id="title" #if(editing){value="#(title)"}/>
</div>
<div class="form-group">
<label for="presenter">Presenter</label>
<input type="text" name="presenter" class="form-control" id="presenter" #if(editing){value="#(presenter)"}/>
</div>
<div class="form-group">
<label for="notes">Notes</label>
<input type="text" name="notes" class="form-control" id="notes" #if(editing){value="#(notes)"}/>
</div>
<div class="form-group">
<label for="rating">Rating</label>
<input type="text" name="rating" class="form-control" id="rating" #if(editing){value="#(rating)"}/>
</div>
<button type="submit" class="btn btn-primary">
#if(editing){Save} else{Submit}
</button>
</form>
}
#embed("base")
// Edit Button
<a class="btn btn-primary" href="/notes/#(id)/edit" role="button">Edit</a>
// Delete Button
<form method="post" action="/notes/#(id)/delete">
<a class="btn btn-primary" href="/notes/#(id)/edit" role="button">Edit</a>
<input class="btn btn-danger" type="submit" value="Delete" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment