mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 02:30:42 -08:00
Start of work on supporting creating HTML elements.
This commit is contained in:
parent
82b1b7b84d
commit
d2186397c1
4 changed files with 64 additions and 29 deletions
|
|
@ -57,7 +57,7 @@ script."
|
||||||
(defvar *client-handler* nil "Clack 'handler' for socket traffic")
|
(defvar *client-handler* nil "Clack 'handler' for socket traffic")
|
||||||
(defvar *on-connect-handler* nil "New connection event handler.")
|
(defvar *on-connect-handler* nil "New connection event handler.")
|
||||||
|
|
||||||
(defvar *new-id* 0 "Connection IDs")
|
(defvar *new-id* 0 "Last issued connection or script IDs")
|
||||||
|
|
||||||
(defvar *connections* (make-hash-table) "Connections to IDs")
|
(defvar *connections* (make-hash-table) "Connections to IDs")
|
||||||
(defvar *connection-ids* (make-hash-table) "IDs to connections")
|
(defvar *connection-ids* (make-hash-table) "IDs to connections")
|
||||||
|
|
@ -77,6 +77,7 @@ script."
|
||||||
|
|
||||||
(defun generate-id ()
|
(defun generate-id ()
|
||||||
"Generate unique ids for use in connections and sripts."
|
"Generate unique ids for use in connections and sripts."
|
||||||
|
;; needs mutex or atomic
|
||||||
(incf *new-id*))
|
(incf *new-id*))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
|
||||||
73
clog.lisp
73
clog.lisp
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
(mgl-pax:define-package :clog
|
(mgl-pax:define-package :clog
|
||||||
(:documentation "The Common List Omnificent GUI - Parent package")
|
(:documentation "The Common List Omnificent GUI - Parent package")
|
||||||
|
(:local-nicknames (:cc :clog-connection))
|
||||||
(:use #:cl #:mgl-pax))
|
(:use #:cl #:mgl-pax))
|
||||||
|
|
||||||
(in-package :clog)
|
(in-package :clog)
|
||||||
|
|
@ -36,9 +37,13 @@ application."
|
||||||
(shutdown function)
|
(shutdown function)
|
||||||
(set-on-connect function)
|
(set-on-connect function)
|
||||||
|
|
||||||
"CLOG base class"
|
(clog class)
|
||||||
|
|
||||||
(attach function)
|
"CLOG Low Level bindings"
|
||||||
|
|
||||||
|
(attach function)
|
||||||
|
(create-with-html function)
|
||||||
|
(place-after function)
|
||||||
|
|
||||||
"CLOG utilities"
|
"CLOG utilities"
|
||||||
|
|
||||||
|
|
@ -48,23 +53,18 @@ application."
|
||||||
(open-browser function))
|
(open-browser function))
|
||||||
|
|
||||||
|
|
||||||
(defclass base ()
|
(defclass clog ()
|
||||||
((connection-id
|
((connection-id
|
||||||
:accessor connection-id
|
:accessor connection-id
|
||||||
:initarg :connection-id)
|
:initarg :connection-id)
|
||||||
(web-id
|
(html-id
|
||||||
:accessor web-id
|
:accessor html-id
|
||||||
:initarg :web-id)))
|
:initarg :html-id)))
|
||||||
|
|
||||||
(defun attach (connection-id web-id)
|
|
||||||
(make-instance 'base :connection-id connection-id :web-id web-id))
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Implementation - clog
|
;; Implementation - clog
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
;; initialize ;;
|
;; initialize ;;
|
||||||
;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;
|
||||||
|
|
@ -78,26 +78,61 @@ application."
|
||||||
"Inititalze CLOG on a socket using HOST and PORT to serve BOOT-FILE as
|
"Inititalze CLOG on a socket using HOST and PORT to serve BOOT-FILE as
|
||||||
the default route to establish web-socket connections and static files
|
the default route to establish web-socket connections and static files
|
||||||
located at STATIC-ROOT."
|
located at STATIC-ROOT."
|
||||||
(clog-connection:initialize on-connect-handler
|
(cc:initialize on-connect-handler
|
||||||
:host host
|
:host host
|
||||||
:port port
|
:port port
|
||||||
:boot-file boot-file
|
:boot-file boot-file
|
||||||
:static-root static-root))
|
:static-root static-root))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;
|
||||||
;; shutdown ;;
|
;; shutdown ;;
|
||||||
;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun shutdown ()
|
(defun shutdown ()
|
||||||
(clog-connection:shutdown))
|
"Shutdown CLOG."
|
||||||
|
(cc:shutdown))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;
|
||||||
|
;; attach ;;
|
||||||
|
;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defun attach (connection-id id)
|
||||||
|
"Create a new clog object and attach an existing element with HTML-ID on
|
||||||
|
CONNECTION-ID to it. The HTML-ID must be unique."
|
||||||
|
(make-instance 'clog :connection-id connection-id :html-id id))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; create-with-html ;;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defun create-with-html (connection-id html)
|
||||||
|
"Create a new clog object and attach it to HTML on CONNECTION-ID. There must be
|
||||||
|
a single outer block that will be set to an internal id"
|
||||||
|
(let ((web-id (cc:generate-id)))
|
||||||
|
(cc:execute
|
||||||
|
connection-id (format nil "clog['~A']=$(\"~A\"); clog['~A'].first().prop('id','~A');"
|
||||||
|
web-id html web-id web-id))
|
||||||
|
(attach connection-id web-id)))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;
|
||||||
|
;; place-after ;;
|
||||||
|
;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defun place-after (parent child)
|
||||||
|
(let ((jq (if parent
|
||||||
|
(format nil "$(clog['~A'])" (html-id parent))
|
||||||
|
(format nil "$('body')"))))
|
||||||
|
(cc:execute (connection-id child)
|
||||||
|
(format nil "~A.after(clog['~A'])" jq (html-id child))))
|
||||||
|
child)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;
|
||||||
;; alert-box ;;
|
;; alert-box ;;
|
||||||
;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(defun alert-box (id message)
|
(defun alert-box (id message)
|
||||||
(clog-connection:execute
|
(cc:execute
|
||||||
id (format nil "alert('~A');" (clog-connection:escape-string message))))
|
id (format nil "alert('~A');" (cc:escape-string message))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;
|
||||||
;; open-browser ;;
|
;; open-browser ;;
|
||||||
|
|
|
||||||
6
static-files/js/jquery.min.js
vendored
6
static-files/js/jquery.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -5,11 +5,12 @@
|
||||||
(in-package :test-clog)
|
(in-package :test-clog)
|
||||||
|
|
||||||
(defun on-connect (id)
|
(defun on-connect (id)
|
||||||
(alert-box id "We are here"))
|
(place-after
|
||||||
|
(place-after nil (create-with-html id "<button>test</botton>"))
|
||||||
|
(create-with-html id "<H2>Cool!</H2>")))
|
||||||
|
|
||||||
(defun test ()
|
(defun test ()
|
||||||
(print "Init connection")
|
(print "Init connection")
|
||||||
(initialize #'on-connect :boot-file "/debug.html")
|
(initialize #'on-connect :boot-file "/debug.html")
|
||||||
(print "Open browser")
|
(print "Open browser")
|
||||||
(open-browser)
|
(open-browser))
|
||||||
)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue