diff --git a/source/clog-presentations.lisp b/source/clog-presentations.lisp index cb7d147..fb205dc 100644 --- a/source/clog-presentations.lisp +++ b/source/clog-presentations.lisp @@ -34,21 +34,25 @@ ;; link-slot-to-form-element ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro link-slot-to-form-element (object accessor clog-obj) +(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) new-value))) + (setf (value ,clog-obj) (if ,transform + (funcall ,transform new-value) + new-value)))) ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; link-slot-to-element ;; ;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro link-slot-to-element (object accessor clog-obj) +(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." `(defmethod (setf ,accessor) :after (new-value (obj (eql ,object))) - (setf (text ,clog-obj) new-value))) + (setf (text ,clog-obj) (if ,transform + (funcall ,transform new-value) + new-value)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; link-form-element-to-object ;; diff --git a/tutorial/29-tutorial.lisp b/tutorial/29-tutorial.lisp index 04395d6..b5cc3d0 100644 --- a/tutorial/29-tutorial.lisp +++ b/tutorial/29-tutorial.lisp @@ -24,11 +24,18 @@ (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 - (link-form-element-to-slot i1 lisp-obj my-slot) ;; any change to i1 will change my-slot - (link-slot-to-form-element lisp-obj my-slot i1) ;; any change to my-slot will change i1 - (link-slot-to-element lisp-obj my-count t1) ;; any change to my-count will change h1 + ;; 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 + ;; my-slot to upercase + (link-slot-to-form-element lisp-obj my-slot i1 + :transform #'string-upcase) + ;; any change to my-count will change t1 + (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) ;; any change to i3 will change my-count + i3 (my-count lisp-obj) :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