feat(tutorial): add :template and :setup page prms

This commit is contained in:
TEC 2022-01-23 02:12:17 +08:00 committed by Jeetaditya Chatterjee
parent c5f9e381a5
commit 0b5532a6f0
No known key found for this signature in database
GPG key ID: 4A1E5568BA34D124

View file

@ -116,19 +116,19 @@
(defmacro doom-tutorial-page! (&rest body)
(let ((parameters (doom-tutorial-normalise-plist body)))
(dolist (strparam '(:instructions :title))
(plist-put parameters strparam
(if-let ((paramvalue (plist-get parameters strparam)))
(dolist (strparam '(:title :instructions :template))
(if-let ((paramvalue (plist-get parameters strparam)))
(plist-put parameters strparam
(if (cl-every #'stringp paramvalue)
(apply #'concat paramvalue)
`(lambda () (concat ,@paramvalue)))
"")))
(when-let ((test (plist-get parameters :test)))
(plist-put parameters :test
(cond
((functionp test) test)
((consp test) `(lambda () ,@test))
(_ (error "Test is invalid. %S" test)))))
`(lambda () (concat ,@paramvalue))))))
(dolist (funparam '(:setup :test))
(when-let ((paramvalue (plist-get parameters funparam)))
(plist-put parameters funparam
(cond
((functionp paramvalue) paramvalue)
((consp paramvalue) `(lambda () ,@paramvalue))
(_ (error "%s is invalid. %S" funparam paramvalue))))))
`(list ,@parameters)))
(defun doom-tutorial--current-page (name)
@ -171,7 +171,17 @@
(insert ?\n)
(insert
(cond ((stringp instructions) instructions)
((functionp instructions) (funcall instructions))))))))))
((functionp instructions) (funcall instructions)))))))
(let ((template (plist-get content :template))
(setup (plist-get content :setup)))
(with-current-buffer doom-tutorial--scratchpad-buffer-name
(when template
(erase-buffer)
(insert
(cond
((stringp template) template)
((functionp template) (funcall template)))))
(when setup (funcall setup)))))))
(defun doom-tutorial--complete (name)
(with-current-buffer doom-tutorial--instructions-buffer-name