added layouts, db support

This commit is contained in:
Jonathan 2024-03-17 16:03:28 -05:00
parent bb7c69e749
commit dd40016775
6 changed files with 42 additions and 21 deletions

0
.help Normal file
View File

24
app.lua
View File

@ -1,17 +1,24 @@
local lapis = require("lapis") local lapis = require("lapis")
local app = lapis.Application() local app = lapis.Application()
local say = require('lua_scripts/main') local say = require('lua_scripts/main')
local player = require('player')
local db = require("lapis.db")
local Model = require("lapis.db.model").Model
app:enable("etlua") app:enable("etlua")
app.layout = require "views.layout"
app:post("/clickme", function(self) app:post("/clickme", function(self)
self.plane = "P-38L" self.plane = "P-38L"
return self.plane return {self.plane, layout = false}
end) end)
app:get("/", function(self) app:get("/", function(self)
self.text = say.hello() self.text = say.hello()
return {render = "index"} return {render = "index",
}
end) end)
return app return app
@ -33,6 +40,19 @@ return app

View File

@ -3,5 +3,9 @@ local config = require("lapis.config")
config("development", { config("development", {
server = "nginx", server = "nginx",
code_cache = "off", code_cache = "off",
num_workers = "1" num_workers = "1",
sqlite = {
database = "my_database.sqlite",
-- open_flags = ...
}
}) })

0
player.lua Normal file
View File

View File

@ -1,29 +1,14 @@
<!-- views/index.etlua --> <!-- views/index.etlua -->
<script src="/static/htmx.min.js"></script> <script src="/static/htmx.min.js"></script>
<h1>Hello world</h1> <button hx-post="/clickme" hx-target="#clickable">Start</button>
<p>Welcome to my page</p>
<p>The missile guidance system works as follows</p>
<form>
<fieldset>
<legend>Give Us Money</legend>
<input type="file"></input>
<input type="text"></input>
</fieldset>
<fieldset>
<label>Do it</label>
<input type="number"></input>
</fieldset>
</form>
<br>
<button hx-post="/clickme" hx-target="#clickable">Click me</button>
<p id="clickable"></p> <p id="clickable"></p>
<ol> <ol>
<!--
<p><% for i, thing in pairs(text) do %> <p><% for i, thing in pairs(text) do %>
<li><%= thing %></li> <li><%= thing %></li>
<% end %> <% end %>
</p> </p>
</ol> </ol>
-->

12
views/layout.etlua Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%= page_title or "My Page" %></title>
</head>
<body>
<h1>Peradventure</h1>
<% content_for("inner") %>
</body>
</html>