diff --git a/src/utils/list.lisp b/src/utils/list.lisp index 3bc3cc4c..fcfc4d47 100644 --- a/src/utils/list.lisp +++ b/src/utils/list.lisp @@ -16,9 +16,7 @@ #:ninsert #:find-all #:remove-keyword-parameter - #:remove-keyword-parameters - #:safe-first - #:safe-rest)) + #:remove-keyword-parameters)) (in-package #:reblocks/utils/list) @@ -31,26 +29,6 @@ (setf end length)) (subseq sequence start end))) -(defun safe-first (item) - "Returns first element of ITEM. -There are two cases: -- ITEM is a list, in which case it returns (first ITEM) -- ITEM is not a list, in which case it retuns ITEM. -The effect is the same as (first (alexandria:ensure-list item))" - (typecase item - (list (first item)) - (t item))) - -(defun safe-rest (item) - "Returns rest of ITEM -There are two cases: -- ITEM is a list, in which case it returns (rest ITEM) -- ITEM is not a list, in whch case it returns nil. -The effect is the same as (rest (alexandria:ensure-list item))" - (typecase item - (list (rest item)) - (t nil))) - ;; TODO: replace with alexandria:alist-plist (defun alist->plist (alist) "Converts an alist to plist." diff --git a/src/widget.lisp b/src/widget.lisp index 184556a7..9636dba8 100644 --- a/src/widget.lisp +++ b/src/widget.lisp @@ -73,26 +73,29 @@ inherits from REBLOCKS/WIDGET:WIDGET if no DIRECT-SUPERCLASSES are provided." You can use any other templating engine, just ensure it writes output to REBLOCKS/HTML:*STREAM* - Outer DIV wrapper will be added automaticall. It will - have CSS tags returned by GET-CSS-CLASSES.")) + Outer DIV wrapper will be added automaticall, see GET-HTML-TAG. + It will have CSS tags returned by GET-CSS-CLASSES.")) (defgeneric get-html-tag (widget) (:documentation "This method determines the enclosing tag of the widget. -The return value should either be a keyword like :div, which will be the enclosing tag, -or a list of the form (:tag . attributes), where :tag is the enclosing tag (like :div) -and attributes is a property list, where the keys are keywords, corresponding to the attribute name -and the values are the values of the attribute. + +The return value should either be a keyword like :div, +which will be the enclosing tag, or a list of the form (:tag . attributes), +where :tag is the enclosing tag (like :div) and attributes is a property list. + +The attributes property list has keywords for keys, corresponding to +the attribute name and the values are the values of the attribute. For example: -- :div -- generates a
WIDGET CONTENT
-- (:div :display \"flex\") -- generates (
WIDGET CONTENT
+- :div -- generates
widget content
+- (:div :display \"flex\") -- generates (
widget content
NOTE on attributes, in the attribute list the following attributes can not be specified, they will be ignored: -- :class -- Use the get-css-classes method to specify these +- :class -- Use the GET-CSS-CLASSES method to specify these - :id -- This is the value of the dom-id slot of the widget, normally automatically managed by reblocks. diff --git a/src/widgets/render-methods.lisp b/src/widgets/render-methods.lisp index b0a17ee5..f4c812f7 100644 --- a/src/widgets/render-methods.lisp +++ b/src/widgets/render-methods.lisp @@ -15,9 +15,8 @@ #:with-html) (:import-from #:reblocks/widgets/dom #:dom-id) - (:import-from #:reblocks/utils/list - #:safe-first - #:safe-rest)) + (:import-from #:uiop + #:ensure-list)) (in-package #:reblocks/widgets/render-methods) @@ -44,13 +43,15 @@ (push-dependencies widget-dependencies)) (register-widget widget) - - (with-html - (:tag - :name (safe-first (get-html-tag widget)) - :class (get-css-classes-as-string widget) - :id (dom-id widget) - :attrs (safe-rest (get-html-tag widget)) - (call-next-method)))) + + (destructuring-bind (tag-name . attributes) + (ensure-list (get-html-tag widget)) + (with-html + (:tag + :name tag-name + :class (get-css-classes-as-string widget) + :id (dom-id widget) + :attrs attributes + (call-next-method)))))