Created
September 9, 2018 18:06
-
-
Save artbikes/8d9ecdf4a06fcf55b7e51781e1a530fb to your computer and use it in GitHub Desktop.
Patching Adam Petersen's `retro-games.lisp` into `game-voter.lisp`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- old/retro-games.lisp 2011-06-14 00:08:07.000000000 -0400 | |
+++ new/retro-games.lisp 2011-06-14 00:07:33.000000000 -0400 | |
@@ -1,21 +1,24 @@ | |
(in-package :cl-user) | |
-(defpackage :retro-games | |
- (:use :cl :cl-who :hunchentoot :parenscript :elephant)) | |
+(defpackage :game-voter | |
+ (:use :cl :cl-who :hunchentoot :parenscript :elephant) | |
+ (:import-from :css-lite :css) | |
+ (:import-from :json :encode-json-to-string)) | |
-(in-package :retro-games) | |
+(in-package :game-voter) | |
;; Start our web server. | |
-(setf *web-server* (start-server :port 8080)) | |
+(setf *web-server* (start (make-instance 'hunchentoot:acceptor :port 8080))) | |
;; Publish all static content. | |
-(push (create-static-file-dispatcher-and-handler "/logo.jpg" "imgs/Commodore64.jpg") *dispatch-table*) | |
-(push (create-static-file-dispatcher-and-handler "/retro.css" "css/retro.css") *dispatch-table*) | |
+(push (create-static-file-dispatcher-and-handler "/GameVoter.png" "statics/imgs/GameVoter.png") *dispatch-table*) | |
+(push (create-static-file-dispatcher-and-handler "/site.css" "statics/css/site.css") *dispatch-table*) | |
;; Launch Elephant | |
-(open-store '(:BDB "/home/adam/temp/gamedb/")) | |
+(setf *store* (open-store '(:clsql (:sqlite3 "/tmp/game-voter.db")))) | |
-;; Represent each game as an instance of the Elephant persistant class. | |
+;; Represent each game as an instance of the Elephant persistant | |
+;; class. | |
(defpclass persistent-game () | |
((name :reader name :initarg :name :index t) | |
(votes :accessor votes :initarg :votes :initform 0 :index t))) | |
@@ -40,49 +43,50 @@ | |
(defun games () | |
(nreverse (get-instances-by-range 'persistent-game 'votes nil nil))) | |
-;; Automatically creates a Hunchentoot handler for the given URL (plus .htm) associating | |
-;; it with a function of the same name. | |
+;; Automatically creates a Hunchentoot handler for the given URL (plus | |
+;; .htm) associating it with a function of the same name. | |
(defmacro define-url-fn ((name) &body body) | |
`(progn | |
(defun ,name () | |
,@body) | |
- (push (create-prefix-dispatcher ,(format nil "/~(~a~).htm" name) ',name) *dispatch-table*))) | |
+ (push (create-prefix-dispatcher ,(format nil "/~(~a~)" name) ',name) *dispatch-table*))) | |
-;; All pages on the Retro Games site will use the following macro; less to type and | |
-;; a uniform look of the pages (defines the header and the stylesheet). | |
+;; All pages on the Game Voter site will use the following macro; less | |
+;; to type and a uniform look of the pages (defines the header and the | |
+;; stylesheet). | |
(defmacro standard-page ((&key title) &body body) | |
`(with-html-output-to-string (*standard-output* nil :prologue t :indent t) | |
(:html :xmlns "http://www.w3.org/1999/xhtml" :xml\:lang "en" :lang "en" | |
(:head | |
(:meta :http-equiv "Content-Type" :content "text/html;charset=utf-8") | |
(:title ,title) | |
- (:link :type "text/css" :rel "stylesheet" :href "/retro.css")) | |
+ (:link :type "text/css" :rel "stylesheet" :href "/site.css")) | |
(:body | |
(:div :id "header" ; Start all pages with our header. | |
- (:img :src "/logo.jpg" :alt "Commodore 64" :class "logo") | |
- (:span :class "strapline" "Vote on your favourite Retro Game")) | |
+ (:img :src "/GameVoter.png" :alt "Game Voter Logo" :class "logo") | |
+ (:span :class "strapline" "Vote for your favourite Video Game")) | |
,@body)))) | |
;; | |
;; The functions responsible for generating the HTML go here. | |
;; | |
-(define-url-fn (retro-games) | |
- (standard-page (:title "Top Retro Games") | |
- (:h1 "Vote on your all time favourite retro games!") | |
- (:p "Missing a game? Make it available for votes " (:a :href "new-game.htm" "here")) | |
+(define-url-fn (index) | |
+ (standard-page (:title "Game Voter") | |
+ (:h1 "Vote on your all time favourite games!") | |
+ (:p "Missing a game? Make it available for votes " (:a :href "new-game" "here")) | |
(:h2 "Current stand") | |
(:div :id "chart" ; Used for CSS styling of the links. | |
(:ol | |
(dolist (game (games)) | |
(htm | |
- (:li (:a :href (format nil "vote.htm?name=~a" (name game)) "Vote!") | |
+ (:li (:a :href (format nil "vote?name=~a" (name game)) "Vote!") | |
(fmt "~A with ~d votes" (name game) (votes game))))))))) | |
(define-url-fn (new-game) | |
(standard-page (:title "Add a new game") | |
(:h1 "Add a new game to the chart") | |
- (:form :action "/game-added.htm" :method "post" | |
+ (:form :action "/game-added" :method "post" | |
:onsubmit (ps-inline ; Client-side validation. | |
(when (= name.value "") | |
(alert "Please enter a name.") | |
@@ -95,10 +99,10 @@ | |
(let ((name (parameter "name"))) | |
(unless (or (null name) (zerop (length name))) ; In case JavaScript is turned off. | |
(add-game name)) | |
- (redirect "/retro-games.htm"))) ; Display the front page. | |
+ (redirect "/index"))) ; Display the front page. | |
(define-url-fn (vote) | |
(let ((game (game-from-name (parameter "name")))) | |
(if game | |
(vote-for game)) | |
- (redirect "/retro-games.htm"))) ; Back to the front page. | |
+ (redirect "/index"))) ; Back to the front page. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment