Skip to content

Commit

Permalink
* op-template.el: Fix checkdoc warnings
Browse files Browse the repository at this point in the history
(op/get-file-category):
(op/get-template-dir):
(op/get-cache-item):
(op/update-cache-item):
(op/get-cache-create):
(op/render-header):
(op/render-navigation-bar):
(op/render-content):
(op/render-footer):
(op/update-default-template-parameters): Ensure single sentence at the
first line of the docstrings.
(op/compose-template-parameters): Document CONTENT argument in the
docstring.
  • Loading branch information
yantar92 committed Aug 27, 2023
1 parent 0b22908 commit a1f2c9d
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions op-template.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ will return \"this is title\" if OPTION is \"TITLE\""
(concat "/tags/" (encode-string-to-url tag-name) "/"))

(defun op/get-file-category (org-file)
"Get org file category presented by ORG-FILE, return all categories if
ORG-FILE is nil. This is the default function used to get a file's category,
see `op/retrieve-category-function'. How to judge a file's category is based on
its name and its root folder name under `op/repository-directory'."
"Get org file category presented by ORG-FILE.
When ORG-FILE is nil, return all the categories.
This is the default function used to get a file's category, see
`op/retrieve-category-function'. How to judge a file's category is
based on its name and its root folder name under
`op/repository-directory'."
(cond ((not org-file)
(let ((cat-list '("index" "about" "blog"))) ;; 3 default categories
(dolist (f (directory-files op/repository-directory))
Expand All @@ -76,31 +79,34 @@ its name and its root folder name under `op/repository-directory'."
"[/\\\\]+")))))

(defun op/get-template-dir ()
"Return the template directory, it is determined by variable
`op/theme-root-directory' with `op/theme' or `op/template-directory'."
"Return the template directory.
It is determined by variable `op/theme-root-directory' with `op/theme'
or `op/template-directory'."
(or op/template-directory
(file-name-as-directory
(expand-file-name
(format "%s/templates" (symbol-name op/theme))
op/theme-root-directory))))

(defun op/get-cache-item (key)
"Get the item associated with KEY in `op/item-cache', if `op/item-cache' is
nil or there is no item associated with KEY in it, return nil."
"Get the item associated with KEY in `op/item-cache'.
If `op/item-cache' is nil or there is no item associated with KEY in it,
return nil."
(and op/item-cache
(plist-get op/item-cache key)))

(defun op/update-cache-item (key value)
"Update the item associated with KEY in `op/item-cache', if `op/item-cache' is
nil, initialize it."
"Update the item associated with KEY in `op/item-cache' to VALUE.
If `op/item-cache' is nil, initialize it."
(if op/item-cache
(plist-put op/item-cache key value)
(setq op/item-cache `(,key ,value)))
value)

(defmacro op/get-cache-create (key &rest body)
"Firstly get item from `op/item-cache' with KEY, if item not found, evaluate
BODY and push the result into cache and return it."
"Get item from `op/item-cache' with KEY.
If item is not found, evaluate BODY and push the result into cache and
return it."
`(or (op/get-cache-item ,key)
(op/update-cache-item ,key (funcall (lambda () ,@body)))))

Expand All @@ -114,9 +120,10 @@ Default to capitalized CATEGORY name if no :label property found."
(capitalize category))))

(defun op/render-header (&optional param-table)
"Render the header on each page. PARAM-TABLE is the hash table from mustache
to render the template. If it is not set or nil, this function will try to build
a hash table accordint to current buffer."
"Render the header on each page.
PARAM-TABLE is the hash table from mustache to render the template. If
it is not set or nil, this function will try to build a hash table
accordint to current buffer."
(mustache-render
(op/get-cache-create
:header-template
Expand All @@ -131,11 +138,12 @@ a hash table accordint to current buffer."
("keywords" (op/read-org-option "KEYWORDS"))))))

(defun op/render-navigation-bar (&optional param-table)
"Render the navigation bar on each page. it will be read firstly from
`op/item-cache', if there is no cached content, it will be rendered
and pushed into cache from template. PARAM-TABLE is the hash table for mustache
to render the template. If it is not set or nil, this function will try to
render from a default hash table."
"Render the navigation bar on each page.
It will be read firstly from `op/item-cache', if there is no cached
content, it will be rendered and pushed into cache from template.
PARAM-TABLE is the hash table for mustache to render the template. If
it is not set or nil, this function will try to render from a default
hash table."
(op/get-cache-create
:nav-bar-html
(message "Render navigation bar from template")
Expand Down Expand Up @@ -169,9 +177,10 @@ render from a default hash table."
(if op/organization (ht ("authors-li" t)) (ht ("avatar" op/personal-avatar))))))))

(defun op/render-content (&optional template param-table)
"Render the content on each page. TEMPLATE is the template name for rendering,
if it is not set of nil, will use default post.mustache instead. PARAM-TABLE is
similar to `op/render-header'. `op/highlight-render' is `js' or `htmlize'."
"Render the content on each page.
TEMPLATE is the template name for rendering, if it is not set of nil,
will use default post.mustache instead. PARAM-TABLE is similar to
`op/render-header'. `op/highlight-render' is `js' or `htmlize'."
(mustache-render
(op/get-cache-create
(if template
Expand All @@ -194,8 +203,8 @@ similar to `op/render-header'. `op/highlight-render' is `js' or `htmlize'."
(org-export-as op/export-backend nil nil t nil))))))))

(defun op/render-footer (&optional param-table)
"Render the footer on each page. PARAM-TABLE is similar to
`op/render-header'."
"Render the footer on each page.
PARAM-TABLE is similar to `op/render-header'."
(mustache-render
(op/get-cache-create
:footer-template
Expand Down Expand Up @@ -264,8 +273,9 @@ similar to `op/render-header'. `op/highlight-render' is `js' or `htmlize'."

;;; this function is deprecated
(defun op/update-default-template-parameters ()
"Update the default template parameters. It is only needed when user did some
customization to relevant variables."
"Update the default template parameters.
It is only needed when user did some customization to relevant
variables."
(ht-update
op/default-template-parameters
(ht ("site-main-title" op/site-main-title)
Expand All @@ -287,7 +297,10 @@ customization to relevant variables."
(defun op/compose-template-parameters (attr-plist content)
"Compose parameters for org file represented in current buffer.
ATTR-PLIST is the attribute plist of the buffer, retrieved by the combination of
`org-export--get-inbuffer-options' and `op/get-inbuffer-extra-options'."
`org-export--get-inbuffer-options' and `op/get-inbuffer-extra-options'.
The return value is a hash table mapping attributes from ATTR-PLIST to
their values. In addition, \"content\" attribute will be set to CONTENT."
(let* ((info
(org-combine-plists
(org-export--get-global-options 'html)
Expand Down

0 comments on commit a1f2c9d

Please sign in to comment.