;; Schematra - a very simple web framework for scheme inspired in ;; Sinatra ;; Copyright (c) 2025 Rolando Abarca ;; ;; This program is free software: you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation, either version 3 of the ;; License, or (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see ;; . (import chicken.port chicken.string chicken.pretty-print chicken.process-context srfi-13 schematra schematra-session schematra-csrf schematra-body-parser chiccup) (use-middleware! (body-parser-middleware)) (use-middleware! (session-middleware "secret")) (use-middleware! (csrf-middleware)) (define (add-google-font name #!optional (weight 400)) `[link ((rel . "stylesheet") (href . ,(conc "https://fonts.googleapis.com/css2?family=" name "&display=swap")))]) (define (add-style) `[style ".cookie-regular { font-family: "Cookie", cursive; font-weight: 400; font-style: normal; }"]) (define ex1 '(#<alist users)) (count . ,(length users)))))) EXAMPLE )) (define ex5 '(#< { res.send(` Dashboard

Welcome back, ${req.session.username}!

Logout `); }); app.get('/login', (req, res) => { res.send(` Login
`); }); app.post('/login', (req, res) => { const username = req.body.username; if (username) { req.session.username = username; res.redirect('/'); } else { res.status(400).send('Username required'); } }); app.get('/logout', (req, res) => { req.session.destroy(); res.redirect('/login'); }); app.listen(8080, () => { console.log('Server running on http://localhost:8080'); }); EXPRESS )) (define schematra-comparison '(#<symbol example-name) playground-examples))) (ccup/html (if example-code `[textarea.w-full.h-80.p-3.border.rounded.font-mono.text-sm.resize-none.focus:outline-none.focus:ring-2.focus:ring-teal-500#chiccup-input ((name . "chiccup") (placeholder . "Try editing the Chiccup code...")) ,example-code] `[div#chiccup-input.w-full.h-80.p-3.border.rounded.bg-red-50.text-red-600.flex.items-center.justify-center "Example not found"])))) (post ("/playground/render") ;; got the 'chiccup param from the body, using the body-parser middleware (let ((chiccup-code (alist-ref 'chiccup (current-params)))) (if chiccup-code (let ((cleaned-code (string-trim chiccup-code))) (condition-case (ccup/html (with-input-from-string cleaned-code read)) (e () (ccup/html `[.text-red-600.p-4.bg-red-50.rounded.border.border-red-200 [h4.font-bold "Syntax Error"] [p "Invalid Chiccup syntax. Please check your brackets and formatting."]])))) (ccup/html `[p "No code provided"])))) (get ("/") (ccup/html (layout (landing-page)))) (get ("/api") (redirect "https://github.com/schematra/schematra")) (schematra-install) (let* ((environment (or (get-environment-variable "SCHEMATRA_ENV") "production")) (dev-env? (string=? environment "development"))) (schematra-start development?: dev-env? nrepl?: #f))