diff --git a/source/clog-presentations.lisp b/source/clog-presentations.lisp index fb205dc..17cf6a2 100644 --- a/source/clog-presentations.lisp +++ b/source/clog-presentations.lisp @@ -18,17 +18,44 @@ ;; link-form-element-to-slot ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro link-form-element-to-slot (clog-obj object accessor &key transform) - "Link changes to (value CLOG-OBJ) to (ACESSOR OBJECT)" - `(link-form-element-to-object ,clog-obj (,accessor ,object) :transform ,transform)) +(defmacro link-form-element-to-slot (clog-obj object accessor + &key (set-event #'set-on-change) + transform) + "Link changes to (value CLOG-OBJ) to (ACESSOR OBJECT) +on SET-EVENT with TRANSFORM" + `(link-element-to-place ,clog-obj value (,accessor ,object) + :set-event ,set-event + :transform ,transform)) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; link-element-to-slot ;; ;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro link-element-to-slot (clog-obj object accessor &key transform) - "Link changes to (text CLOG-OBJ) to (ACESSOR OBJECT)" - `(link-element-to-object ,clog-obj (,accessor ,object) :transform ,transform)) +(defmacro link-element-to-slot (clog-obj object accessor + &key (set-event #'set-on-change) + transform) + "Link changes to (text CLOG-OBJ) to (ACESSOR OBJECT) +on SET-EVENT with TRANSFORM" + `(link-element-to-place ,clog-obj text (,accessor ,object) + :set-event ,set-event + :transform ,transform)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; link-element-to-place ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defmacro link-element-to-place (clog-obj property place + &key (set-event #'set-on-change) + transform) + "Link changes to (PROPERTY CLOG-OBJ) to any lisp PLACE +on SET-EVENT with TRANSFORM" + `(funcall ,set-event ,clog-obj + (lambda (obj) + (declare (ignore obj)) + (let ((v (if ,transform + (funcall ,transform (,property ,clog-obj)) + (,property ,clog-obj)))) + (setf ,place v))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; link-slot-to-form-element ;; @@ -37,10 +64,7 @@ (defmacro link-slot-to-form-element (object accessor clog-obj &key transform) "Link changes to lisp (ACCESSOR OBJECT) to (value CLOG-OBJ). Only one element can be bound at a time to a list object." - `(defmethod (setf ,accessor) :after (new-value (obj (eql ,object))) - (setf (value ,clog-obj) (if ,transform - (funcall ,transform new-value) - new-value)))) + `(link-slot-to-place ,object ,accessor (value ,clog-obj) :transform ,transform)) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; link-slot-to-element ;; @@ -49,35 +73,16 @@ element can be bound at a time to a list object." (defmacro link-slot-to-element (object accessor clog-obj &key transform) "Link changes to lisp (ACCESSOR OBJECT) to (text CLOG-OBJ). Only one element can be bound at a time to a list object." + `(link-slot-to-place ,object ,accessor (text ,clog-obj) :transform ,transform)) + +;;;;;;;;;;;;;;;;;;;;;;;; +;; link-slot-to-place ;; +;;;;;;;;;;;;;;;;;;;;;;;; + +(defmacro link-slot-to-place (object accessor place &key transform) + "Link changes to lisp (ACCESSOR OBJECT) to PLACE. Only one +PLACE can be bound at a time to a list object." `(defmethod (setf ,accessor) :after (new-value (obj (eql ,object))) - (setf (text ,clog-obj) (if ,transform - (funcall ,transform new-value) - new-value)))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; link-form-element-to-object ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defmacro link-form-element-to-object (clog-obj object &key transform) - "Link changes to (value CLOG-OBJ) to any lisp OBJECT" - `(set-on-change ,clog-obj - (lambda (obj) - (declare (ignore obj)) - (let ((v (if ,transform - (funcall ,transform (value ,clog-obj)) - (value ,clog-obj)))) - (setf ,object v))))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; link-element-to-object ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defmacro link-element-to-object (clog-obj object &key transform) - "Link changes to (text CLOG-OBJ) to any lisp OBJECT" - `(set-on-change ,clog-obj - (lambda (obj) - (declare (ignore obj)) - (let ((v (if ,transform - (funcall ,transform (text ,clog-obj)) - (text ,clog-obj)))) - (setf ,object v))))) + (setf ,place (if ,transform + (funcall ,transform new-value) + new-value)))) diff --git a/source/clog.lisp b/source/clog.lisp index a70f50f..7ee23f4 100644 --- a/source/clog.lisp +++ b/source/clog.lisp @@ -65,7 +65,7 @@ embedded in a native template application.)" (defsection @clog-utilities (:title "CLOG Utilities") "Concurrent Hash Tables" (make-hash-table* function) - + "CLOG-Group - Utility Class for CLOG-Obj storage" (clog-group class) (create-group function) @@ -385,7 +385,7 @@ embedded in a native template application.)" "CLOG-Summary - Class for CLOG Summary Blocks" (clog-summary class) (create-summary generic-function) - + "CLOG-HR - Class for CLOG Hortizontal Rules" (clog-HR class) (create-HR generic-function) @@ -495,12 +495,12 @@ embedded in a native template application.)" (defsection @clog-presentations (:title "CLOG Presentations") "CLOG-Presentations - CLOG Presentations" - (link-form-element-to-slot macro) - (link-element-to-slot macro) - (link-slot-to-form-element macro) - (link-slot-to-element macro) - (link-form-element-to-object macro) - (link-element-to-object macro)) + (link-form-element-to-slot macro) + (link-element-to-slot macro) + (link-element-to-place macro) + (link-slot-to-form-element macro) + (link-slot-to-element macro) + (link-slot-to-place macro)) (defsection @clog-panels (:title "CLOG Panels") "CLOG-Panel - CLOG Panels" diff --git a/tutorial/29-tutorial.lisp b/tutorial/29-tutorial.lisp index 1dd3b0a..a17aeae 100644 --- a/tutorial/29-tutorial.lisp +++ b/tutorial/29-tutorial.lisp @@ -23,7 +23,8 @@ (t1 (create-div body :content "[counter]")) (i3 (create-form-element body :text :label (create-label body :content "Change my-count:")))) - ;; We set up direct relationships between lisp obj and clog objects + (declare (ignore tmp)) + ;; We set up direct relationships between lisp objects and clog objects ;; any change to i1 will change my-slot (link-form-element-to-slot i1 lisp-obj my-slot) ;; any change to my-slot will change i1 after transforming @@ -34,8 +35,8 @@ (link-slot-to-element lisp-obj my-count t1) ;; any change to i3 will change my-count ;; and i3's value will be transformed to an integer - (link-form-element-to-object - i3 (my-count lisp-obj) :transform #'parse-integer) + (link-form-element-to-slot i3 lisp-obj my-count + :transform #'parse-integer) ;; This change of my-slot will immediately change in the web page (setf (my-slot lisp-obj) "First Value") (set-on-click b1