Skip to content

Commit

Permalink
sync with restas
Browse files Browse the repository at this point in the history
  • Loading branch information
archimag committed Jan 21, 2011
1 parent c2c59b0 commit 02f4dad
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
5 changes: 5 additions & 0 deletions resources/rulisp.tmpl
Expand Up @@ -66,6 +66,11 @@
</html>
{/template}

{template notFoundContent}
<h1>Not Found</h1>
Страница по адрессу {$href} не обнаруженна.
{/template}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Tools
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
40 changes: 20 additions & 20 deletions src/pcl.lisp
Expand Up @@ -137,13 +137,13 @@
;; contents
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-route pcl-main ("")
(restas:define-route pcl-main ("")
(finalize-page (rulisp.view:pcl-main (list :pdf-href (restas:genurl 'pcl-pdf)
:jpg-href "/image/pcl.jpg"
:chapters (iter (for chapter in-vector *pcl-files-map*)
(collect (list :href (genurl 'pcl-chapter-view
:chapter (first chapter))
:title (second chapter))))))
:jpg-href "/image/pcl.jpg"
:chapters (iter (for chapter in-vector *pcl-files-map*)
(collect (list :href (restas:genurl 'pcl-chapter-view
:chapter (first chapter))
:title (second chapter))))))
"Перевод Practical Common Lisp"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand All @@ -154,29 +154,29 @@
(defun chapter-url (number)
(if (and (> number -1)
(< number (1- (length *pcl-files-map*))))
(genurl 'pcl-chapter-view
:chapter (first (aref *pcl-files-map*
number)))))
(restas:genurl 'pcl-chapter-view
:chapter (first (aref *pcl-files-map*
number)))))

(define-route pcl-chapter-view (":(chapter)")
(restas:define-route pcl-chapter-view (":(chapter)")
(let* ((number (position chapter
*pcl-files-map*
:key #'first
:test #'string=))
(path (pcl-source-path (third (aref *pcl-files-map* number)))))
(if (fad:file-exists-p path)
(finalize-page (rulisp.view:pcl-chapter-view (list :prev (chapter-url (1- number))
:menu (genurl 'pcl-main)
:next (chapter-url (1+ number))
:content (xtree:with-object (el (rulisp::render-wiki-page
(wiki-parser:parse :dokuwiki path)))
(xtree:serialize el :to-string))))
:menu (restas:genurl 'pcl-main)
:next (chapter-url (1+ number))
:content (xtree:with-object (el (rulisp::render-wiki-page
(wiki-parser:parse :dokuwiki path)))
(xtree:serialize el :to-string))))
(second (aref *pcl-files-map* number)))
hunchentoot:+HTTP-NOT-FOUND+)))


(define-route pcl-chapter-pdf ("pdf/:(chapter)"
:content-type "application/pdf")
(restas:define-route pcl-chapter-pdf ("pdf/:(chapter)"
:content-type "application/pdf")
(let* ((number (position chapter
*pcl-files-map*
:key #'first
Expand All @@ -185,8 +185,8 @@
(flexi-streams:with-output-to-sequence (out)
(let ((out* (flexi-streams:make-flexi-stream out)))
(rulisp::pdf-render-wiki-page (wiki-parser:parse :dokuwiki
path)
out*))
path)
out*))
out)))


Expand Down Expand Up @@ -235,7 +235,7 @@
10))))
(pdf:write-document out))))))

(define-route pcl-pdf ("pcl.pdf")
(restas:define-route pcl-pdf ("pcl.pdf")
(merge-pathnames "pcl.pdf"
*pcl-snapshot-dir*))

Expand Down
68 changes: 32 additions & 36 deletions src/rulisp.lisp
Expand Up @@ -12,13 +12,9 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun compute-user-login-name ()
(labels ((rulisp (submodule)
(if (eql (restas:submodule-module submodule)
#.*package*)
submodule
(rulisp (restas:submodule-parent submodule)))))
(restas:with-submodule-context (restas:find-submodule 'rulisp-auth (rulisp restas:*submodule*))
(restas.simple-auth::compute-user-login-name))))
(restas:with-submodule (restas:find-submodule 'rulisp-auth
(restas:find-upper-submodule #.*package*))
(restas.simple-auth::compute-user-login-name)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; rulisp templates
Expand All @@ -44,48 +40,40 @@
("Поиск" nil google-search)))

(defun rulisp-finalize-page (&key title css js content)
(labels ((rulisp (&optional (submodule restas:*submodule*))
(if (eql (restas:submodule-module submodule)
#.*package*)
submodule
(rulisp (restas:submodule-parent submodule))))
(main-menu-data ()
(iter (for item in *mainmenu*)
(collect (list :href (apply #'restas:genurl-submodule
(second item)
(if (cdddr item)
(cddr item)
(last item)))
:name (first item)))))
(css-urls (items)
(iter (for item in items)
(collect (format nil "/css/~A" item)))))
(let ((restas::*submodule* (rulisp)))
(rulisp.view:main-frame (list :title title
:css (css-urls css)
:js js
:gecko-png "/image/gecko.png"
:user (compute-user-login-name)
:main-menu (main-menu-data)
:content content
:callback (hunchentoot:request-uri*))))))
(rulisp.view:main-frame
(list :title title
:css (iter (for item in css)
(collect (format nil "/css/~A" item)))
:js js
:gecko-png "/image/gecko.png"
:user (compute-user-login-name)
:main-menu (restas:with-submodule (restas:find-upper-submodule #.*package*)
(iter (for item in *mainmenu*)
(collect (list :href (apply #'restas:genurl-submodule
(second item)
(if (cdddr item)
(cddr item)
(last item)))
:name (first item)))))
:content content
:callback (hunchentoot:request-uri*))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; routes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-route main ("")
(restas:define-route main ("")
(rulisp-finalize-page :title "Русскоязычное сообщество Common Lisp разработчиков"
:css '("style.css")
:content (alexandria:read-file-into-string (merge-pathnames "index.html"
*resources-dir*))))

(define-route tools-list ("apps/")
(restas:define-route tools-list ("apps/")
(rulisp-finalize-page :title "Инструменты"
:css '("style.css")
:content (rulisp.view:tools)))

(define-route google-search ("search")
(restas:define-route google-search ("search")
(rulisp-finalize-page :title "Поиск по сайту Lisper.ru"
:css '("style.css")
:content (rulisp.view:google-search)))
Expand All @@ -94,11 +82,19 @@
;; submodules
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defclass rulisp-drawer () ())

(defmethod restas:render-object ((designer rulisp-drawer) (code (eql hunchentoot:+http-not-found+)))
(rulisp-finalize-page :title "Not Found"
:css '("style.css")
:content (rulisp.view:not-found-content (list :href (hunchentoot:request-uri*)))))

;;;; static files

(restas:mount-submodule rulisp-static (#:restas.directory-publisher)
(restas.directory-publisher:*directory* (merge-pathnames "static/" *resources-dir*))
(restas.directory-publisher:*autoindex* nil))
(restas.directory-publisher:*autoindex* nil)
(restas.directory-publisher:*default-render-method* (make-instance 'rulisp-drawer)))

;;;; pcl

Expand Down

0 comments on commit 02f4dad

Please sign in to comment.