wip2
This commit is contained in:
parent
1890d288f6
commit
55b2e50a81
31
bookstack.el
31
bookstack.el
@ -84,19 +84,24 @@ executing CALLBACK with the decoded result."
|
|||||||
'utf-8)))
|
'utf-8)))
|
||||||
(bookstack--retrieve (format "pages/%d" id) (lambda (_)))))
|
(bookstack--retrieve (format "pages/%d" id) (lambda (_)))))
|
||||||
|
|
||||||
(defun bookstack--read-page (pages)
|
(defun bookstack--read (prompt items)
|
||||||
"Reads a page from the user with `completing-read', returning its ID.
|
"Reads an item from the user with `completing-read', returning its ID. ITEMS
|
||||||
PAGES should be a sequence of pages (as returned by `bookstack-pages')."
|
should be a data sequence of items returned from a listing endpoint such as
|
||||||
|
`bookstack-pages'."
|
||||||
(let* ((opts (seq-reduce
|
(let* ((opts (seq-reduce
|
||||||
(lambda (acc page)
|
(lambda (acc item)
|
||||||
(push `(,(alist-get 'name page) . ,(alist-get 'id page)) acc))
|
(push `(,(alist-get 'name item) . ,(alist-get 'id item)) acc))
|
||||||
pages
|
items
|
||||||
nil))
|
nil))
|
||||||
(page-name (progn
|
(page-name (progn
|
||||||
(switch-to-minibuffer)
|
(switch-to-minibuffer)
|
||||||
(completing-read "Page: " opts))))
|
(completing-read prompt opts))))
|
||||||
(cdr (assoc page-name opts))))
|
(cdr (assoc page-name opts))))
|
||||||
|
|
||||||
|
(defun bookstack--read-book (books) (bookstack--read "Book: " books))
|
||||||
|
(defun bookstack--read-chapter (chapters) (bookstack--read "Chapter: " chapters))
|
||||||
|
(defun bookstack--read-page (pages) (bookstack--read "Page: " pages))
|
||||||
|
|
||||||
(defun bookstack--edit-page (id)
|
(defun bookstack--edit-page (id)
|
||||||
"Asynchronously loads a page by ID for editing into a new buffer."
|
"Asynchronously loads a page by ID for editing into a new buffer."
|
||||||
(bookstack-page
|
(bookstack-page
|
||||||
@ -116,6 +121,18 @@ PAGES should be a sequence of pages (as returned by `bookstack-pages')."
|
|||||||
(switch-to-buffer buffer)
|
(switch-to-buffer buffer)
|
||||||
(bookstack-mode +1))))))
|
(bookstack-mode +1))))))
|
||||||
|
|
||||||
|
(defun bookstack-books (callback)
|
||||||
|
"Retrieve all books from `bookstack-server'."
|
||||||
|
(bookstack--retrieve
|
||||||
|
"books"
|
||||||
|
(lambda (res) (apply callback (list (alist-get 'data res))))))
|
||||||
|
|
||||||
|
(defun bookstack-chapters (callback)
|
||||||
|
"Retrieve all chapters from `bookstack-server'."
|
||||||
|
(bookstack--retrieve
|
||||||
|
"chapters"
|
||||||
|
(lambda (res) (apply callback (list (alist-get 'data res))))))
|
||||||
|
|
||||||
(defun bookstack-pages (callback)
|
(defun bookstack-pages (callback)
|
||||||
"Retrieve all pages from `bookstack-server'."
|
"Retrieve all pages from `bookstack-server'."
|
||||||
(bookstack--retrieve
|
(bookstack--retrieve
|
||||||
|
Loading…
Reference in New Issue
Block a user