nerack repo

This commit is contained in:
2026-09-13 15:31:00 -05:00
committed by nightshade
commit abac587d14
99 changed files with 4772 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
{{< layout}}
{{$body}}
<p>not found</p>
{{/body}}
{{/layout}}
+5
View File
@@ -0,0 +1,5 @@
{{< layout}}
{{$body}}
<p>error</p>
{{/body}}
{{/layout}}
+5
View File
@@ -0,0 +1,5 @@
{{< layout}}
{{$body}}
<p>about us</p>
{{/body}}
{{/layout}}
+5
View File
@@ -0,0 +1,5 @@
{{< layout}}
{{$body}}
<p>contact us</p>
{{/body}}
{{/layout}}
+2
View File
@@ -0,0 +1,2 @@
insert into todos(title)
values({{title}});
+5
View File
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
finished INTEGER CHECK(finished IN (1))
);
+2
View File
@@ -0,0 +1,2 @@
delete from todos
where id = {{id}};
+2
View File
@@ -0,0 +1,2 @@
select id, title, finished
from todos;
+5
View File
@@ -0,0 +1,5 @@
{{< layout}}
{{$body}}
<p>home</p>
{{/body}}
{{/layout}}
+23
View File
@@ -0,0 +1,23 @@
<html>
<head>
<link rel='icon' href='{{asset:favicon.png}}'>
</head>
<body>
<p>
{{^user}}
<a href='{{url:get:login}}'>sign in</a>
{{/user}}
{{#user}}
welcome, {{short_name}}
{{/user}}
</p>
<nav>
<a href='{{url:get:home}}'>home</a>
<a href='{{url:get:about}}'>about us</a>
<a href='{{url:get:contact}}'>contact us</a>
<a href='{{url:get:todos}}'>todos</a>
</nav>
{{$body}}
{{/body}}
</body>
</html>
View File
+70
View File
@@ -0,0 +1,70 @@
#include <nerack.h>
#include <http.h>
#include <sqlite.h>
#include <cookie_auth.h>
module(todo){
sqlite(
"todos_db",
"file:{{user_id}}_todo.db?mode=rwc",
{"create_todos_table"}
);
http("home", "/",
.get = {
cookie_session(),
html("home", "home_s"),
http_response("home_s")
}
);
http("about", "/about",
.get = {
cookie_session(),
html("about", "about_s"),
http_response("about_s")
}
);
http("contact", "/contact",
.get = {
cookie_session(),
html("contact", "contact_s"),
http_response("contact_s")
}
);
http("todos", "/todos",
.all = {
cookie_logged_in(),
cookie_session()
},
.get = {
sqlite_query({"todos_db", "get_todos", "todos_data"}),
html("todos", "todos_s"),
http_response("todos_s")
},
.post = {
input({"title", not_empty_input}),
sqlite_query({"todos_db", "create_todo"}),
http_redirect("todos")
}
);
http("todo", "/todos/:id",
.all = {
cookie_logged_in(),
cookie_session(),
input({"id", positive_integer_input})
},
.patch = {
input({"finished", "^1$", "must be 1", .optional = true}),
sqlite_query({"todos_db", "update_todo"}),
http_redirect("todos")
},
.delete = {
sqlite_query({"todos_db", "delete_todo"}),
http_redirect("todos")
}
);
}
+28
View File
@@ -0,0 +1,28 @@
{{< layout}}
{{$body}}
<form action="{{url:post:todos}}" method="post">
<input type="text" name="title" placeholder="new todo" required>
<button type="submit">add</button>
</form>
{{^todos_data}}
<p>no todos</p>
{{/todos_data}}
{{#todos_data}}
<div>
<form action="{{url:patch:todo}}" method="post" style="display:inline">
{{^finished}}
<input type="checkbox" name="finished" value="1">
{{/finished}}
{{#finished}}
<input type="checkbox" name="finished" value="1" checked>
{{/finished}}
{{title}}
<button type="submit">save</button>
</form>
<form action="{{url:delete:todo}}" method="post" style="display:inline">
<button type="submit">delete</button>
</form>
</div>
{{/todos_data}}
{{/body}}
{{/layout}}
+3
View File
@@ -0,0 +1,3 @@
update todos
set finished = {{finished}}
where id = {{id}};