diff --git a/README.md b/README.md index bd8bed5..1f3d368 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,22 @@ It's ``` - Improved: - - Element functions are wrapped in macros for natural indentation. + - Element functions are wrapped in macros for natural indentation. To manipulate them as function objects, prefix '%' to the element name, or use `get-element` function. - Bugfix. https://github.com/ailisp/flute/issues/5, https://github.com/ailisp/flute/issues/7 + +```lisp +(define-element dynamic-1 (as) + (funcall as props children)) + +(define-element dynamic-2 (as) + (funcall (get-element as) props children)) + +(dynamic-1 :as #'%span :class "bold" "child") +(dynamic-2 :as "span" :class "bold" "child") + +; child +``` + - Removed: - Attributes like CSS selectors (e.g. `div#id.class`) - ASCII-based escaping. Piccolo only supports UTF-8. @@ -367,4 +381,4 @@ Licensed under MIT License.  Copyright (c) 2024, skyizwhite. -Copyright (c) 2018, Bo Yao. All rights reserved. +Copyright (c) 2018, Bo Yao. \ No newline at end of file diff --git a/src/elements.lisp b/src/elements.lisp index 786d99f..d86be08 100644 --- a/src/elements.lisp +++ b/src/elements.lisp @@ -37,7 +37,8 @@ #:element-prefix #:element-children #:user-element-expand-to - #:h)) + #:h + #:get-element)) (in-package #:piccolo/elements) ;;; classes @@ -279,3 +280,8 @@ (or (html-element-p node) (fragment-p node))) (lambda (node) (find-symbol (string node) :piccolo))))) + +;;; Utility + +(defun get-element (name) + (find-symbol (concatenate 'string "%" (string-upcase name)) :piccolo))