Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes in the examples.

  • Loading branch information...
commit c988dcb54581842851424822d99ad9f3c55d784a 1 parent d72d3ce
@archimag authored
View
2  COPYING
@@ -1,6 +1,6 @@
RESTAS - Common Lisp application server (web framework)
-Copyright (c) 2009-2011 Moskvitin Andrey
+Copyright (c) 2009-2013 Moskvitin Andrey
Preamble to the Gnu Lesser General Public License
View
2  example/custom-acceptor.lisp
@@ -5,7 +5,7 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-(asdf:operate 'asdf:load-op '#:restas)
+(ql:quickload "restas")
(restas:define-module #:restas.custom-acceptor.example
(:use #:cl))
View
4 example/example-1.lisp
@@ -5,8 +5,8 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-(asdf:operate 'asdf:load-op '#:cl-who)
-(asdf:operate 'asdf:load-op '#:restas)
+(ql:quickload "cl-who")
+(ql:quickload "restas")
(restas:define-module #:restas.example-1
(:use #:cl))
View
5 example/example-2.lisp
@@ -5,9 +5,8 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-
-(asdf:operate 'asdf:load-op '#:cl-who)
-(asdf:operate 'asdf:load-op '#:restas)
+(ql:quickload "cl-who")
+(ql:quickload "restas")
(restas:define-module #:restas.example-2
(:use #:cl #:iter))
View
4 example/example-3.lisp
@@ -5,8 +5,8 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-(asdf:operate 'asdf:load-op '#:cl-who)
-(asdf:operate 'asdf:load-op '#:restas)
+(ql:quickload "cl-who")
+(ql:quickload "restas")
(restas:define-module #:restas.example-3
(:use #:cl))
View
54 example/example-4.lisp
@@ -1,54 +0,0 @@
-;;;; example-4.lisp
-;;;;
-;;;; This file is part of the RESTAS library, released under Lisp-LGPL.
-;;;; See file COPYING for details.
-;;;;
-;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-
-(asdf:operate 'asdf:load-op '#:closure-template)
-(asdf:operate 'asdf:load-op '#:restas)
-
-(restas:define-module #:restas.example-4
- (:use #:cl))
-
-(in-package #:restas.example-4)
-
-;;;; view with templates
-
-(closure-template:compile-cl-templates
- (asdf:system-relative-pathname '#:restas "example/example-4.tmpl"))
-
-(defclass template-drawer ()
- ((template-package :initarg :template-package)))
-
-(defmethod restas:render-object ((drawer template-drawer) obj)
- (restas:render-object (symbol-function (find-symbol (symbol-name (restas:route-symbol restas:*route*))
- (slot-value drawer 'template-package)))
- obj))
-
-;;;; view with context processor
-
-(defclass context-template-drawer (template-drawer) ())
-
-(defmethod restas:render-object ((drawer context-template-drawer) obj)
- (call-next-method drawer
- (list* :info (list :foo (list :href (restas:genurl 'foo))
- :bar (list :href (restas:genurl 'bar)))
- obj)))
-
-
-;;;; routes
-
-(restas:define-route foo ("foo")
- (list :foo "Foo"))
-
-(restas:define-route bar ("bar")
- (list :bar "Bar"))
-
-;;;; init
-
-(defmethod restas:initialize-module-instance ((module (eql #.*package*)) context)
- (unless (restas:context-symbol-value context '*default-render-method*)
- (restas:context-add-variable context
- '*default-render-method*
- (make-instance 'context-template-drawer :template-package '#:restas.example-4.view))))
View
30 example/example-4.tmpl
@@ -1,30 +0,0 @@
-// -*- mode: closure-template-html -*-
-
-{namespace restas.example-4.view}
-
-{template frame}
- <a href="{$info.foo.href}">Foo</a>
- <a href="{$info.bar.href}">Bar</a>
-
- <hr />
-
- {$content |noAutoescape}
-{/template}
-
-{template foo}
- {call frame}
- {param info: $info /}
- {param content}
- <h1>{$foo}</h1>
- {/param}
- {/call}
-{/template}
-
-{template bar}
- {call frame}
- {param info: $info /}
- {param content}
- <h1>{$bar}</h1>
- {/param}
- {/call}
-{/template}
View
6 example/hello-world.lisp
@@ -5,14 +5,14 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-(asdf:operate 'asdf:load-op '#:restas)
+(ql:quickload "restas")
(restas:define-module #:restas.hello-world
- (:use :cl))
+ (:use #:cl))
(in-package #:restas.hello-world)
-(define-route main ("")
+(restas:define-route main ("")
"<h1>Hello world!</h1>")
(restas:start '#:restas.hello-world :port 8080)
View
85 example/publish-rst.lisp
@@ -5,13 +5,13 @@
;;;;
;;;; Author: Moskvitin Andrey <archimag@gmail.com>
-(asdf:operate 'asdf:load-op '#:cl-who)
+(ql:quickload "cl-who")
;; http://www.cliki.net/CL-DOCUTILS
-(asdf:operate 'asdf:load-op '#:docutils)
+(ql:quickload "docutils")
-;;https://github.com/archimag/restas-directory-publisher
-(asdf:operate 'asdf:load-op '#:restas-directory-publisher)
+;; https://github.com/archimag/restas-directory-publisher
+(ql:quickload "restas-directory-publisher")
(restas:define-module #:restas.publish-rst
(:use #:cl))
@@ -19,87 +19,60 @@
(in-package #:restas.publish-rst)
(defparameter *rstdir*
- (merge-pathnames "example/rst/"
- (make-pathname :directory (pathname-directory
- (asdf:component-pathname (asdf:find-system '#:restas))))))
+ (merge-pathnames "../example/rst/" (asdf:component-pathname (asdf:find-system '#:restas))))
+
(restas:define-route entry ("")
- (flet ((durl (submodule-symbol)
- (restas:genurl-submodule submodule-symbol
- 'restas.directory-publisher:route
- :path '(""))))
- (who:with-html-output-to-string (out)
- (:html
- (:body
- (:ul
- (:li
- (:a :href (durl '-raw-) "Raw reStructuredText"))
- (:li
- (:a :href (durl '-fine-) "reStructuredText as HTML"))
- (:li
- (:a :href (durl '-safe-) "reStructuredText as HTML in safe mode"))))))))
+ (who:with-html-output-to-string (out)
+ (:html
+ (:body
+ (:ul
+ (:li (:a :href (restas:genurl '-raw-.route :path "") "Raw reStructuredText"))
+ (:li (:a :href (restas:genurl '-fine-.route :path "") "reStructuredText as HTML"))
+ (:li (:a :href (restas:genurl '-safe-.route :path "") "reStructuredText as HTML in safe mode")))))))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; publish raw files
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(restas:mount-submodule -raw- (#:restas.directory-publisher)
- (restas.directory-publisher:*baseurl* '("raw"))
+(restas:mount-module -raw- (#:restas.directory-publisher)
+ (:url "raw")
(restas.directory-publisher:*directory* *rstdir*)
(restas.directory-publisher:*autoindex* t))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; publish reStructuredText files as HTML
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defclass drawer () ())
+(defclass renderer () ())
-(defmethod restas:render-object ((drawer drawer) (file pathname))
- (restas:render-object drawer (docutils:read-rst file)))
+(defmethod restas:render-object ((renderer renderer) (file pathname))
+ (restas:render-object renderer (docutils:read-rst file)))
-(defmethod restas:render-object ((drawer drawer) (rst docutils.nodes:document))
+(defmethod restas:render-object ((renderer renderer) (rst docutils.nodes:document))
(with-output-to-string (out)
(docutils:write-html out rst)))
-(restas:mount-submodule -fine- (#:restas.directory-publisher)
- (restas.directory-publisher:*default-render-method* (make-instance 'drawer)) ;;; Set custom drawer!!!
- (restas.directory-publisher:*baseurl* '("fine"))
+(restas:mount-module -fine- (#:restas.directory-publisher)
+ (:url "fine")
+ (:render-method (make-instance 'renderer)) ;; Set custom renderer!!!
(restas.directory-publisher:*directory* *rstdir*)
(restas.directory-publisher:*directory-index-files* '("index.txt"))
(restas.directory-publisher:*autoindex* t))
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Publish reStructuredText files as HTML with HTTP authorization
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-;;; http auth decorator
(defclass http-auth-route (routes:proxy-route) () )
(defmethod routes:route-check-conditions ((route http-auth-route) bindings)
(if (call-next-method)
(multiple-value-bind (user password) (hunchentoot:authorization)
- (or (and (string= user "hello")
- (string= password "world"))
+ (or (and (string= user "admin")
+ (string= password "default"))
(hunchentoot:require-authorization)))))
(defun http-auth-decorator (route)
(make-instance 'http-auth-route :target route))
-;;; render reStructuredText decorator
-
-(defclass render-rst-route (routes:proxy-route) ())
-
-(defmethod restas:process-route :around ((route render-rst-route) bindings)
- (let ((restas.directory-publisher:*default-render-method* (make-instance 'drawer)))
- (call-next-method)))
-
-(defun render-rst-decorator (route)
- (make-instance 'render-rst-route :target route))
-
-;;; mount module
-
-(restas:mount-submodule -safe- (#:restas.directory-publisher http-auth-decorator render-rst-decorator)
- (restas.directory-publisher:*baseurl* '("safe"))
+(restas:mount-module -safe- (#:restas.directory-publisher)
+ (:url "safe")
+ (:render-method (make-instance 'renderer))
+ (:decorators #'http-auth-decorator)
(restas.directory-publisher:*directory* *rstdir*)
(restas.directory-publisher:*directory-index-files* '("index.txt"))
(restas.directory-publisher:*autoindex* t))
@@ -108,4 +81,4 @@
;; start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(restas:start '#:restas.publish-rst :port 8080)
+(restas:start '#:restas.publish-rst :port 8080)

0 comments on commit c988dcb

Please sign in to comment.
Something went wrong with that request. Please try again.