Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #----------------------------------------------------------------------
- # Project creation output
- #----------------------------------------------------------------------
- > sbcl
- This is SBCL 2.1.2-1.1-suse, an implementation of ANSI Common Lisp.
- More information about SBCL is available at <http://www.sbcl.org/>.
- SBCL is free software, provided as is, with absolutely no warranty.
- It is mostly in the public domain; some portions are provided under
- BSD-style licenses. See the CREDITS and COPYING files in the
- distribution for more information.
- * (ql:quickload :caveman2)
- To load "caveman2":
- Load 1 ASDF system:
- caveman2
- ; Loading "caveman2"
- ......
- (:CAVEMAN2)
- * (caveman2:make-project #P"tacos" :author "John Doe")
- writing tacos/tacos.asd
- writing tacos/tacos-test.asd
- writing tacos/app.lisp
- writing tacos/README.markdown
- writing tacos/.gitignore
- writing tacos/db/schema.sql
- writing tacos/src/config.lisp
- writing tacos/src/db.lisp
- writing tacos/src/main.lisp
- writing tacos/src/view.lisp
- writing tacos/src/web.lisp
- writing tacos/static/css/main.css
- writing tacos/templates/index.html
- writing tacos/templates/_errors/404.html
- writing tacos/templates/layouts/default.html
- writing tacos/tests/tacos.lisp
- T
- #----------------------------------------------------------------------
- # Tree project structure
- #----------------------------------------------------------------------
- tacos/
- ├── app.lisp
- ├── db
- │ └── schema.sql
- ├── README.markdown
- ├── src
- │ ├── config.lisp
- │ ├── db.lisp
- │ ├── main.lisp
- │ ├── view.lisp
- │ └── web.lisp
- ├── static
- │ └── css
- │ └── main.css
- ├── tacos.asd
- ├── tacos-test.asd
- ├── templates
- │ ├── _errors
- │ │ └── 404.html
- │ ├── index.html
- │ └── layouts
- │ └── default.html
- └── tests
- └── tacos.lisp
- 8 directories, 15 files
- #----------------------------------------------------------------------
- # Files contents
- #----------------------------------------------------------------------
- .:
- ./README.markdown:
- # tacos
- ## Usage
- ## Installation
- ## Author
- * John Doe
- ## Copyright
- Copyright (c) 2021 John Doe
- ./src:
- ./src/main.lisp:
- (in-package :cl-user)
- (defpackage tacos
- (:use :cl)
- (:import-from :tacos.config
- :config)
- (:import-from :clack
- :clackup)
- (:export :start
- :stop))
- (in-package :tacos)
- (defvar *appfile-path*
- (asdf:system-relative-pathname :tacos #P"app.lisp"))
- (defvar *handler* nil)
- (defun start (&rest args &key server port debug &allow-other-keys)
- (declare (ignore server port debug))
- (when *handler*
- (restart-case (error "Server is already running.")
- (restart-server ()
- :report "Restart the server"
- (stop))))
- (setf *handler*
- (apply #'clackup *appfile-path* args)))
- (defun stop ()
- (prog1
- (clack:stop *handler*)
- (setf *handler* nil)))
- ./src/web.lisp:
- (in-package :cl-user)
- (defpackage tacos.web
- (:use :cl
- :caveman2
- :tacos.config
- :tacos.view
- :tacos.db
- :datafly
- :sxql)
- (:export :*web*))
- (in-package :tacos.web)
- ;; for @route annotation
- (syntax:use-syntax :annot)
- ;;
- ;; Application
- (defclass <web> (<app>) ())
- (defvar *web* (make-instance '<web>))
- (clear-routing-rules *web*)
- ;;
- ;; Routing rules
- (defroute "/" ()
- (render #P"index.html"))
- ;;
- ;; Error pages
- (defmethod on-exception ((app <web>) (code (eql 404)))
- (declare (ignore app))
- (merge-pathnames #P"_errors/404.html"
- *template-directory*))
- ./src/config.lisp:
- (in-package :cl-user)
- (defpackage tacos.config
- (:use :cl)
- (:import-from :envy
- :config-env-var
- :defconfig)
- (:export :config
- :*application-root*
- :*static-directory*
- :*template-directory*
- :appenv
- :developmentp
- :productionp))
- (in-package :tacos.config)
- (setf (config-env-var) "APP_ENV")
- (defparameter *application-root* (asdf:system-source-directory :tacos))
- (defparameter *static-directory* (merge-pathnames #P"static/" *application-root*))
- (defparameter *template-directory* (merge-pathnames #P"templates/" *application-root*))
- (defconfig :common
- `(:databases ((:maindb :sqlite3 :database-name ":memory:"))))
- (defconfig |development|
- '())
- (defconfig |production|
- '())
- (defconfig |test|
- '())
- (defun config (&optional key)
- (envy:config #.(package-name *package*) key))
- (defun appenv ()
- (uiop:getenv (config-env-var #.(package-name *package*))))
- (defun developmentp ()
- (string= (appenv) "development"))
- (defun productionp ()
- (string= (appenv) "production"))
- ./src/view.lisp:
- (in-package :cl-user)
- (defpackage tacos.view
- (:use :cl)
- (:import-from :tacos.config
- :*template-directory*)
- (:import-from :caveman2
- :*response*
- :response-headers)
- (:import-from :djula
- :add-template-directory
- :compile-template*
- :render-template*
- :*djula-execute-package*)
- (:import-from :datafly
- :encode-json)
- (:export :render
- :render-json))
- (in-package :tacos.view)
- (djula:add-template-directory *template-directory*)
- (defparameter *template-registry* (make-hash-table :test 'equal))
- (defun render (template-path &optional env)
- (let ((template (gethash template-path *template-registry*)))
- (unless template
- (setf template (djula:compile-template* (princ-to-string template-path)))
- (setf (gethash template-path *template-registry*) template))
- (apply #'djula:render-template*
- template nil
- env)))
- (defun render-json (object)
- (setf (getf (response-headers *response*) :content-type) "application/json")
- (encode-json object))
- ;;
- ;; Execute package definition
- (defpackage tacos.djula
- (:use :cl)
- (:import-from :tacos.config
- :config
- :appenv
- :developmentp
- :productionp)
- (:import-from :caveman2
- :url-for))
- (setf djula:*djula-execute-package* (find-package :tacos.djula))
- ./src/db.lisp:
- (in-package :cl-user)
- (defpackage tacos.db
- (:use :cl)
- (:import-from :tacos.config
- :config)
- (:import-from :datafly
- :*connection*)
- (:import-from :cl-dbi
- :connect-cached)
- (:export :connection-settings
- :db
- :with-connection))
- (in-package :tacos.db)
- (defun connection-settings (&optional (db :maindb))
- (cdr (assoc db (config :databases))))
- (defun db (&optional (db :maindb))
- (apply #'connect-cached (connection-settings db)))
- (defmacro with-connection (conn &body body)
- `(let ((*connection* ,conn))
- ,@body))
- ./app.lisp:
- (ql:quickload :tacos)
- (defpackage tacos.app
- (:use :cl)
- (:import-from :lack.builder
- :builder)
- (:import-from :ppcre
- :scan
- :regex-replace)
- (:import-from :tacos.web
- :*web*)
- (:import-from :tacos.config
- :config
- :productionp
- :*static-directory*))
- (in-package :tacos.app)
- (builder
- (:static
- :path (lambda (path)
- (if (ppcre:scan "^(?:/images/|/css/|/js/|/robot\\.txt$|/favicon\\.ico$)" path)
- path
- nil))
- :root *static-directory*)
- (if (productionp)
- nil
- :accesslog)
- (if (getf (config) :error-log)
- `(:backtrace
- :output ,(getf (config) :error-log))
- nil)
- :session
- (if (productionp)
- nil
- (lambda (app)
- (lambda (env)
- (let ((datafly:*trace-sql* t))
- (funcall app env)))))
- *web*)
- ./tacos-test.asd:
- (defsystem "tacos-test"
- :defsystem-depends-on ("prove-asdf")
- :author "John Doe"
- :license ""
- :depends-on ("tacos"
- "prove")
- :components ((:module "tests"
- :components
- ((:test-file "tacos"))))
- :description "Test system for tacos"
- :perform (test-op (op c) (symbol-call :prove-asdf :run-test-system c)))
- ./tests:
- ./tests/tacos.lisp:
- (in-package :cl-user)
- (defpackage tacos-test
- (:use :cl
- :tacos
- :prove))
- (in-package :tacos-test)
- (plan nil)
- ;; blah blah blah.
- (finalize)
- ./db:
- ./db/schema.sql:
- ./.gitignore:
- *.fasl
- *.dx32fsl
- *.dx64fsl
- *.lx32fsl
- *.lx64fsl
- *.x86f
- *~
- .#*
- ./templates:
- ./templates/_errors:
- ./templates/_errors/404.html:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>404 NOT FOUND</title>
- <style type="text/css">
- html {
- height: 100%;
- }
- body {
- height: 100%;
- font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
- background-color: #DFDFDF;
- }
- #main {
- display: table;
- width: 100%;
- height: 100%;
- }
- .error {
- display: table-cell;
- text-align: center;
- vertical-align: middle;
- }
- .error .code {
- font-size: 1600%;
- font-weight: bold;
- }
- .error .message {
- font-size: 400%;
- }
- </style>
- </head>
- <body>
- <div id="main">
- <div class="error">
- <div class="code">404</div>
- <div class="message">NOT FOUND</div>
- </div>
- </div>
- </body>
- </html>
- ./templates/index.html:
- {% extends "layouts/default.html" %}
- {% block title %}Welcome to Caveman2{% endblock %}
- {% block content %}
- <div id="main">
- Welcome to <a href="http://8arrow.org/caveman/">Caveman2</a>!
- </div>
- {% endblock %}
- ./templates/layouts:
- ./templates/layouts/default.html:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>{% block title %}{% endblock %}</title>
- <link rel="stylesheet" type="text/css" media="screen" href="/css/main.css">
- </head>
- <body>
- {% block content %}{% endblock %}
- </body>
- </html>
- ./static:
- ./static/css:
- ./static/css/main.css:
- @charset "UTF-8";
- body {
- font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
- }
- a:link {
- color: #005585;
- text-decoration: none;
- }
- a:visited {
- color: #485270;
- }
- a:hover {
- color: #b83800;
- text-decoration: underline;
- }
- #main {
- text-align: center;
- }
- ./show_file.sh:
- #!/bin/sh
- echo "$1:"
- cat "$1"
- echo
- ./tacos.asd:
- (defsystem "tacos"
- :version "0.1.0"
- :author "John Doe"
- :license ""
- :depends-on ("clack"
- "lack"
- "caveman2"
- "envy"
- "cl-ppcre"
- "uiop"
- ;; for @route annotation
- "cl-syntax-annot"
- ;; HTML Template
- "djula"
- ;; for DB
- "datafly"
- "sxql")
- :components ((:module "src"
- :components
- ((:file "main" :depends-on ("config" "view" "db"))
- (:file "web" :depends-on ("view"))
- (:file "view" :depends-on ("config"))
- (:file "db" :depends-on ("config"))
- (:file "config"))))
- :description ""
- :in-order-to ((test-op (test-op "tacos-test"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement