mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 10:40:45 -08:00
compiled-boot-html support and support for custom html from boot-function alone
This commit is contained in:
parent
a27e86a197
commit
85b006e109
2 changed files with 64 additions and 29 deletions
|
|
@ -46,6 +46,7 @@ script."
|
||||||
"CLOG system utilities"
|
"CLOG system utilities"
|
||||||
|
|
||||||
(escape-string function)
|
(escape-string function)
|
||||||
|
(compiled-boot-html function)
|
||||||
|
|
||||||
"CLOG connections"
|
"CLOG connections"
|
||||||
|
|
||||||
|
|
@ -305,6 +306,7 @@ the default answer. (Private)"
|
||||||
(port 8080)
|
(port 8080)
|
||||||
(boot-file "/boot.html")
|
(boot-file "/boot.html")
|
||||||
(boot-function nil)
|
(boot-function nil)
|
||||||
|
(static-boot-html nil)
|
||||||
(static-boot-js nil)
|
(static-boot-js nil)
|
||||||
(static-root #P"./static-files/"))
|
(static-root #P"./static-files/"))
|
||||||
"Initialize CLOG on a socket using HOST and PORT to serve BOOT-FILE
|
"Initialize CLOG on a socket using HOST and PORT to serve BOOT-FILE
|
||||||
|
|
@ -314,9 +316,10 @@ clog-path's will be setup, use clog-path to add. The
|
||||||
on-connect-handler needs to indentify the path by querying the
|
on-connect-handler needs to indentify the path by querying the
|
||||||
browser. See PATH-NAME (in CLOG-LOCATION). If static-boot-js is nil
|
browser. See PATH-NAME (in CLOG-LOCATION). If static-boot-js is nil
|
||||||
then boot.js is served from the file /js/boot.js instead of the
|
then boot.js is served from the file /js/boot.js instead of the
|
||||||
compiled version. boot-function if set is called with the url and the
|
compiled version. Is static-boot-html is t if boot.html is not present
|
||||||
contents of boot-file and its return value replaces the contents sent
|
will use compiled version. boot-function if set is called with the url
|
||||||
to the brower."
|
and the contents of boot-file and its return value replaces the
|
||||||
|
contents sent to the brower."
|
||||||
(set-on-connect on-connect-handler)
|
(set-on-connect on-connect-handler)
|
||||||
(when boot-file
|
(when boot-file
|
||||||
(set-clog-path "/" boot-file))
|
(set-clog-path "/" boot-file))
|
||||||
|
|
@ -339,9 +342,14 @@ to the brower."
|
||||||
(let ((file (uiop:subpathname static-root clog-path)))
|
(let ((file (uiop:subpathname static-root clog-path)))
|
||||||
(with-open-file (stream file :direction :input
|
(with-open-file (stream file :direction :input
|
||||||
:if-does-not-exist nil)
|
:if-does-not-exist nil)
|
||||||
(let ((page-data (make-string (file-length stream)))
|
(let ((page-data (if stream
|
||||||
|
(make-string (file-length stream))
|
||||||
|
(if static-boot-html
|
||||||
|
(compiled-boot-html nil nil)
|
||||||
|
"")))
|
||||||
(post-data))
|
(post-data))
|
||||||
(read-sequence page-data stream)
|
(when stream
|
||||||
|
(read-sequence page-data stream))
|
||||||
(when boot-function
|
(when boot-function
|
||||||
(setf page-data (funcall boot-function
|
(setf page-data (funcall boot-function
|
||||||
(getf env :path-info)
|
(getf env :path-info)
|
||||||
|
|
@ -539,6 +547,30 @@ the browser contents in case of connection loss."
|
||||||
(execute connection-id (format nil "clog['html_on_close']='~A'"
|
(execute connection-id (format nil "clog['html_on_close']='~A'"
|
||||||
(escape-string html))))
|
(escape-string html))))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; compiled-boot-html ;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defun compiled-boot-html (path content)
|
||||||
|
"Returns a compiled version of current version of boot.html"
|
||||||
|
"<!doctype HTML>
|
||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<meta http-equiv='Cache-Control' content='no-cache, no-store, must-revalidate' />
|
||||||
|
<meta http-equiv='Pragma' content='no-cache' />
|
||||||
|
<meta http-equiv='Expires' content='0' />
|
||||||
|
<meta charset='utf-8'>
|
||||||
|
<meta name='viewport' content='width=device-width, initial-scale=1'>
|
||||||
|
<script src='/js/jquery.min.js' type='text/javascript'></script>
|
||||||
|
<script src='/js/boot.js' type='text/javascript'></script>
|
||||||
|
<noscript><%= (@ meta) %></noscript>
|
||||||
|
</HEAD>
|
||||||
|
<BODY>
|
||||||
|
<noscript><%= (@ body) %></noscript>
|
||||||
|
</BODY>
|
||||||
|
<noscript>Your browser must support JavaScript and be HTML 5 compilant to see this site.</noscript>
|
||||||
|
</HTML>")
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; compiled-boot-js ;;
|
;; compiled-boot-js ;;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ the same as the clog directy this overides the relative paths used in them.")
|
||||||
(port 8080)
|
(port 8080)
|
||||||
(boot-file "/boot.html")
|
(boot-file "/boot.html")
|
||||||
(boot-function nil)
|
(boot-function nil)
|
||||||
|
(static-boot-html nil)
|
||||||
(static-boot-js nil)
|
(static-boot-js nil)
|
||||||
(static-root (merge-pathnames "./static-files/"
|
(static-root (merge-pathnames "./static-files/"
|
||||||
(asdf:system-source-directory :clog))))
|
(asdf:system-source-directory :clog))))
|
||||||
|
|
@ -60,15 +61,17 @@ as the default route to establish web-socket connections and static
|
||||||
files located at STATIC-ROOT. If CLOG was already initialized and not
|
files located at STATIC-ROOT. If CLOG was already initialized and not
|
||||||
shut down, this function does the same as set-on-new-window (does not
|
shut down, this function does the same as set-on-new-window (does not
|
||||||
change the static-root). If ON-NEW-WINDOW-HANDLER is nil no handler is
|
change the static-root). If ON-NEW-WINDOW-HANDLER is nil no handler is
|
||||||
set and none is removed. STATIC-ROOT by default is the \"directory CLOG
|
set and none is removed. STATIC-ROOT by default is the \"directory
|
||||||
is installed in ./static-files\" If the variable clog:*overide-static-root*
|
CLOG is installed in ./static-files\" If the variable
|
||||||
is set STATIC-ROOT will be ignored. If BOOT-FILE is nil no default
|
clog:*overide-static-root* is set STATIC-ROOT will be ignored. If
|
||||||
boot-file will be set for root path, i.e. /. If static-boot-js is t
|
BOOT-FILE is nil no default boot-file will be set for root path,
|
||||||
then boot.js is served from the file /js/boot.js instead of the
|
i.e. /. If static-boot-js is t then boot.js is served from the file
|
||||||
compiled version. boot-function if set is called with the url and the
|
/js/boot.js instead of the compiled version. Is static-boot-html is t
|
||||||
contents of boot-file and its return value replaces the contents sent
|
if boot.html is not present will use compiled version. boot-function
|
||||||
to the brower, this allows adding content for search engine optimization,
|
if set is called with the url and the contents of boot-file and its
|
||||||
see tutorial 12 for an example."
|
return value replaces the contents sent to the brower, this allows
|
||||||
|
adding content for search engine optimization, see tutorial 12 for an
|
||||||
|
example."
|
||||||
(when on-new-window-handler
|
(when on-new-window-handler
|
||||||
(set-on-new-window on-new-window-handler :path "/" :boot-file boot-file))
|
(set-on-new-window on-new-window-handler :path "/" :boot-file boot-file))
|
||||||
(unless *clog-running*
|
(unless *clog-running*
|
||||||
|
|
@ -81,6 +84,7 @@ see tutorial 12 for an example."
|
||||||
:port port
|
:port port
|
||||||
:boot-file boot-file
|
:boot-file boot-file
|
||||||
:boot-function boot-function
|
:boot-function boot-function
|
||||||
|
:static-boot-html static-boot-html
|
||||||
:static-boot-js static-boot-js
|
:static-boot-js static-boot-js
|
||||||
:static-root *static-root*)))
|
:static-root *static-root*)))
|
||||||
|
|
||||||
|
|
@ -129,4 +133,3 @@ for openning windows on remote machines."
|
||||||
(trivial-open-browser:open-browser url)
|
(trivial-open-browser:open-browser url)
|
||||||
(error (c)
|
(error (c)
|
||||||
(format t "Unable to open browser.~%~%~A" c))))
|
(format t "Unable to open browser.~%~%~A" c))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue