Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.16 KB | None | 0 0
  1. #----------------------------------------------------------------------
  2. # Project creation output
  3. #----------------------------------------------------------------------
  4.  
  5. > sbcl
  6. This is SBCL 2.1.2-1.1-suse, an implementation of ANSI Common Lisp.
  7. More information about SBCL is available at <http://www.sbcl.org/>.
  8.  
  9. SBCL is free software, provided as is, with absolutely no warranty.
  10. It is mostly in the public domain; some portions are provided under
  11. BSD-style licenses. See the CREDITS and COPYING files in the
  12. distribution for more information.
  13. * (ql:quickload :caveman2)
  14. To load "caveman2":
  15. Load 1 ASDF system:
  16. caveman2
  17. ; Loading "caveman2"
  18. ......
  19. (:CAVEMAN2)
  20. * (caveman2:make-project #P"tacos" :author "John Doe")
  21. writing tacos/tacos.asd
  22. writing tacos/tacos-test.asd
  23. writing tacos/app.lisp
  24. writing tacos/README.markdown
  25. writing tacos/.gitignore
  26. writing tacos/db/schema.sql
  27. writing tacos/src/config.lisp
  28. writing tacos/src/db.lisp
  29. writing tacos/src/main.lisp
  30. writing tacos/src/view.lisp
  31. writing tacos/src/web.lisp
  32. writing tacos/static/css/main.css
  33. writing tacos/templates/index.html
  34. writing tacos/templates/_errors/404.html
  35. writing tacos/templates/layouts/default.html
  36. writing tacos/tests/tacos.lisp
  37. T
  38.  
  39. #----------------------------------------------------------------------
  40. # Tree project structure
  41. #----------------------------------------------------------------------
  42.  
  43. tacos/
  44. ├── app.lisp
  45. ├── db
  46. │   └── schema.sql
  47. ├── README.markdown
  48. ├── src
  49. │   ├── config.lisp
  50. │   ├── db.lisp
  51. │   ├── main.lisp
  52. │   ├── view.lisp
  53. │   └── web.lisp
  54. ├── static
  55. │   └── css
  56. │   └── main.css
  57. ├── tacos.asd
  58. ├── tacos-test.asd
  59. ├── templates
  60. │   ├── _errors
  61. │   │   └── 404.html
  62. │   ├── index.html
  63. │   └── layouts
  64. │   └── default.html
  65. └── tests
  66. └── tacos.lisp
  67.  
  68. 8 directories, 15 files
  69.  
  70. #----------------------------------------------------------------------
  71. # Files contents
  72. #----------------------------------------------------------------------
  73.  
  74. .:
  75.  
  76. ./README.markdown:
  77. # tacos
  78.  
  79.  
  80.  
  81. ## Usage
  82.  
  83. ## Installation
  84.  
  85. ## Author
  86.  
  87. * John Doe
  88.  
  89. ## Copyright
  90.  
  91. Copyright (c) 2021 John Doe
  92.  
  93.  
  94. ./src:
  95.  
  96. ./src/main.lisp:
  97. (in-package :cl-user)
  98. (defpackage tacos
  99. (:use :cl)
  100. (:import-from :tacos.config
  101. :config)
  102. (:import-from :clack
  103. :clackup)
  104. (:export :start
  105. :stop))
  106. (in-package :tacos)
  107.  
  108. (defvar *appfile-path*
  109. (asdf:system-relative-pathname :tacos #P"app.lisp"))
  110.  
  111. (defvar *handler* nil)
  112.  
  113. (defun start (&rest args &key server port debug &allow-other-keys)
  114. (declare (ignore server port debug))
  115. (when *handler*
  116. (restart-case (error "Server is already running.")
  117. (restart-server ()
  118. :report "Restart the server"
  119. (stop))))
  120. (setf *handler*
  121. (apply #'clackup *appfile-path* args)))
  122.  
  123. (defun stop ()
  124. (prog1
  125. (clack:stop *handler*)
  126. (setf *handler* nil)))
  127.  
  128. ./src/web.lisp:
  129. (in-package :cl-user)
  130. (defpackage tacos.web
  131. (:use :cl
  132. :caveman2
  133. :tacos.config
  134. :tacos.view
  135. :tacos.db
  136. :datafly
  137. :sxql)
  138. (:export :*web*))
  139. (in-package :tacos.web)
  140.  
  141. ;; for @route annotation
  142. (syntax:use-syntax :annot)
  143.  
  144. ;;
  145. ;; Application
  146.  
  147. (defclass <web> (<app>) ())
  148. (defvar *web* (make-instance '<web>))
  149. (clear-routing-rules *web*)
  150.  
  151. ;;
  152. ;; Routing rules
  153.  
  154. (defroute "/" ()
  155. (render #P"index.html"))
  156.  
  157. ;;
  158. ;; Error pages
  159.  
  160. (defmethod on-exception ((app <web>) (code (eql 404)))
  161. (declare (ignore app))
  162. (merge-pathnames #P"_errors/404.html"
  163. *template-directory*))
  164.  
  165. ./src/config.lisp:
  166. (in-package :cl-user)
  167. (defpackage tacos.config
  168. (:use :cl)
  169. (:import-from :envy
  170. :config-env-var
  171. :defconfig)
  172. (:export :config
  173. :*application-root*
  174. :*static-directory*
  175. :*template-directory*
  176. :appenv
  177. :developmentp
  178. :productionp))
  179. (in-package :tacos.config)
  180.  
  181. (setf (config-env-var) "APP_ENV")
  182.  
  183. (defparameter *application-root* (asdf:system-source-directory :tacos))
  184. (defparameter *static-directory* (merge-pathnames #P"static/" *application-root*))
  185. (defparameter *template-directory* (merge-pathnames #P"templates/" *application-root*))
  186.  
  187. (defconfig :common
  188. `(:databases ((:maindb :sqlite3 :database-name ":memory:"))))
  189.  
  190. (defconfig |development|
  191. '())
  192.  
  193. (defconfig |production|
  194. '())
  195.  
  196. (defconfig |test|
  197. '())
  198.  
  199. (defun config (&optional key)
  200. (envy:config #.(package-name *package*) key))
  201.  
  202. (defun appenv ()
  203. (uiop:getenv (config-env-var #.(package-name *package*))))
  204.  
  205. (defun developmentp ()
  206. (string= (appenv) "development"))
  207.  
  208. (defun productionp ()
  209. (string= (appenv) "production"))
  210.  
  211. ./src/view.lisp:
  212. (in-package :cl-user)
  213. (defpackage tacos.view
  214. (:use :cl)
  215. (:import-from :tacos.config
  216. :*template-directory*)
  217. (:import-from :caveman2
  218. :*response*
  219. :response-headers)
  220. (:import-from :djula
  221. :add-template-directory
  222. :compile-template*
  223. :render-template*
  224. :*djula-execute-package*)
  225. (:import-from :datafly
  226. :encode-json)
  227. (:export :render
  228. :render-json))
  229. (in-package :tacos.view)
  230.  
  231. (djula:add-template-directory *template-directory*)
  232.  
  233. (defparameter *template-registry* (make-hash-table :test 'equal))
  234.  
  235. (defun render (template-path &optional env)
  236. (let ((template (gethash template-path *template-registry*)))
  237. (unless template
  238. (setf template (djula:compile-template* (princ-to-string template-path)))
  239. (setf (gethash template-path *template-registry*) template))
  240. (apply #'djula:render-template*
  241. template nil
  242. env)))
  243.  
  244. (defun render-json (object)
  245. (setf (getf (response-headers *response*) :content-type) "application/json")
  246. (encode-json object))
  247.  
  248.  
  249. ;;
  250. ;; Execute package definition
  251.  
  252. (defpackage tacos.djula
  253. (:use :cl)
  254. (:import-from :tacos.config
  255. :config
  256. :appenv
  257. :developmentp
  258. :productionp)
  259. (:import-from :caveman2
  260. :url-for))
  261.  
  262. (setf djula:*djula-execute-package* (find-package :tacos.djula))
  263.  
  264. ./src/db.lisp:
  265. (in-package :cl-user)
  266. (defpackage tacos.db
  267. (:use :cl)
  268. (:import-from :tacos.config
  269. :config)
  270. (:import-from :datafly
  271. :*connection*)
  272. (:import-from :cl-dbi
  273. :connect-cached)
  274. (:export :connection-settings
  275. :db
  276. :with-connection))
  277. (in-package :tacos.db)
  278.  
  279. (defun connection-settings (&optional (db :maindb))
  280. (cdr (assoc db (config :databases))))
  281.  
  282. (defun db (&optional (db :maindb))
  283. (apply #'connect-cached (connection-settings db)))
  284.  
  285. (defmacro with-connection (conn &body body)
  286. `(let ((*connection* ,conn))
  287. ,@body))
  288.  
  289. ./app.lisp:
  290. (ql:quickload :tacos)
  291.  
  292. (defpackage tacos.app
  293. (:use :cl)
  294. (:import-from :lack.builder
  295. :builder)
  296. (:import-from :ppcre
  297. :scan
  298. :regex-replace)
  299. (:import-from :tacos.web
  300. :*web*)
  301. (:import-from :tacos.config
  302. :config
  303. :productionp
  304. :*static-directory*))
  305. (in-package :tacos.app)
  306.  
  307. (builder
  308. (:static
  309. :path (lambda (path)
  310. (if (ppcre:scan "^(?:/images/|/css/|/js/|/robot\\.txt$|/favicon\\.ico$)" path)
  311. path
  312. nil))
  313. :root *static-directory*)
  314. (if (productionp)
  315. nil
  316. :accesslog)
  317. (if (getf (config) :error-log)
  318. `(:backtrace
  319. :output ,(getf (config) :error-log))
  320. nil)
  321. :session
  322. (if (productionp)
  323. nil
  324. (lambda (app)
  325. (lambda (env)
  326. (let ((datafly:*trace-sql* t))
  327. (funcall app env)))))
  328. *web*)
  329.  
  330. ./tacos-test.asd:
  331. (defsystem "tacos-test"
  332. :defsystem-depends-on ("prove-asdf")
  333. :author "John Doe"
  334. :license ""
  335. :depends-on ("tacos"
  336. "prove")
  337. :components ((:module "tests"
  338. :components
  339. ((:test-file "tacos"))))
  340. :description "Test system for tacos"
  341. :perform (test-op (op c) (symbol-call :prove-asdf :run-test-system c)))
  342.  
  343. ./tests:
  344.  
  345. ./tests/tacos.lisp:
  346. (in-package :cl-user)
  347. (defpackage tacos-test
  348. (:use :cl
  349. :tacos
  350. :prove))
  351. (in-package :tacos-test)
  352.  
  353. (plan nil)
  354.  
  355. ;; blah blah blah.
  356.  
  357. (finalize)
  358.  
  359. ./db:
  360.  
  361. ./db/schema.sql:
  362.  
  363. ./.gitignore:
  364. *.fasl
  365. *.dx32fsl
  366. *.dx64fsl
  367. *.lx32fsl
  368. *.lx64fsl
  369. *.x86f
  370. *~
  371. .#*
  372. ./templates:
  373.  
  374. ./templates/_errors:
  375.  
  376. ./templates/_errors/404.html:
  377. <!DOCTYPE html>
  378. <html>
  379. <head>
  380. <meta charset="utf-8">
  381. <title>404 NOT FOUND</title>
  382. <style type="text/css">
  383. html {
  384. height: 100%;
  385. }
  386.  
  387. body {
  388. height: 100%;
  389. font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
  390. background-color: #DFDFDF;
  391. }
  392.  
  393. #main {
  394. display: table;
  395. width: 100%;
  396. height: 100%;
  397. }
  398.  
  399. .error {
  400. display: table-cell;
  401. text-align: center;
  402. vertical-align: middle;
  403. }
  404.  
  405. .error .code {
  406. font-size: 1600%;
  407. font-weight: bold;
  408. }
  409.  
  410. .error .message {
  411. font-size: 400%;
  412. }
  413. </style>
  414. </head>
  415. <body>
  416. <div id="main">
  417. <div class="error">
  418. <div class="code">404</div>
  419. <div class="message">NOT FOUND</div>
  420. </div>
  421. </div>
  422. </body>
  423. </html>
  424.  
  425. ./templates/index.html:
  426. {% extends "layouts/default.html" %}
  427. {% block title %}Welcome to Caveman2{% endblock %}
  428. {% block content %}
  429. <div id="main">
  430. Welcome to <a href="http://8arrow.org/caveman/">Caveman2</a>!
  431. </div>
  432. {% endblock %}
  433.  
  434. ./templates/layouts:
  435.  
  436. ./templates/layouts/default.html:
  437. <!DOCTYPE html>
  438. <html>
  439. <head>
  440. <meta charset="utf-8">
  441. <title>{% block title %}{% endblock %}</title>
  442. <link rel="stylesheet" type="text/css" media="screen" href="/css/main.css">
  443. </head>
  444. <body>
  445. {% block content %}{% endblock %}
  446. </body>
  447. </html>
  448.  
  449. ./static:
  450.  
  451. ./static/css:
  452.  
  453. ./static/css/main.css:
  454. @charset "UTF-8";
  455.  
  456. body {
  457. font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
  458. }
  459.  
  460. a:link {
  461. color: #005585;
  462. text-decoration: none;
  463. }
  464. a:visited {
  465. color: #485270;
  466. }
  467. a:hover {
  468. color: #b83800;
  469. text-decoration: underline;
  470. }
  471.  
  472. #main {
  473. text-align: center;
  474. }
  475.  
  476. ./show_file.sh:
  477. #!/bin/sh
  478.  
  479. echo "$1:"
  480. cat "$1"
  481. echo
  482.  
  483. ./tacos.asd:
  484. (defsystem "tacos"
  485. :version "0.1.0"
  486. :author "John Doe"
  487. :license ""
  488. :depends-on ("clack"
  489. "lack"
  490. "caveman2"
  491. "envy"
  492. "cl-ppcre"
  493. "uiop"
  494.  
  495. ;; for @route annotation
  496. "cl-syntax-annot"
  497.  
  498. ;; HTML Template
  499. "djula"
  500.  
  501. ;; for DB
  502. "datafly"
  503. "sxql")
  504. :components ((:module "src"
  505. :components
  506. ((:file "main" :depends-on ("config" "view" "db"))
  507. (:file "web" :depends-on ("view"))
  508. (:file "view" :depends-on ("config"))
  509. (:file "db" :depends-on ("config"))
  510. (:file "config"))))
  511. :description ""
  512. :in-order-to ((test-op (test-op "tacos-test"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement