Skip to content

Commit

Permalink
Throw a user-error on finding an empty string element in a fm list
Browse files Browse the repository at this point in the history
Fixes #221.
  • Loading branch information
kaushalmodi committed Oct 8, 2018
1 parent 9f35082 commit 8e5b85d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
20 changes: 12 additions & 8 deletions ox-hugo.el
Expand Up @@ -1212,10 +1212,11 @@ or \"name\" are packed into an alist with `car' as \"params\"."
all-src)))

;;;; List to YAML/TOML list string
(defun org-hugo--get-yaml-toml-list-string (list)
"Return LIST as a YAML/TOML list represented as a string.
(defun org-hugo--get-yaml-toml-list-string (key list)
"Return KEY's LIST value as a YAML/TOML list, represented as a string.
Examples:
KEY is a string and LIST is a list where an element can be a
symbol, number or a non-empty string. Examples:
\(\"abc\" \"def\") -> \"[\\\"abc\\\", \\\"def\\\"]\"."
(concat "["
Expand All @@ -1227,8 +1228,10 @@ Examples:
(symbol-name v))
((numberp v)
(number-to-string v))
((org-string-nw-p v)
v)
(t
v))))
(user-error "Invalid element %S in %S value %S" v key list)))))
list)
", ")
"]"))
Expand Down Expand Up @@ -2939,7 +2942,7 @@ Return nil if STR is not a string."
(str-list (split-string str org-hugo--internal-list-separator))
ret)
(dolist (str-elem str-list)
(let* ((format-str ":dummy '(%s)") ;The :dummy key is later discarded
(let* ((format-str ":dummy '(%s)") ;The :dummy key is discarded in the `lst' var below.
(alist (org-babel-parse-header-arguments (format format-str str-elem)))
(lst (cdr (car alist)))
(str-list2 (mapcar (lambda (elem)
Expand Down Expand Up @@ -3309,7 +3312,7 @@ are \"toml\" and \"yaml\"."
;; (message "[resources DBG] param-key: %S" param-key)
;; (message "[resources DBG] param-value: %S" param-value)
(setq param-value-str (if (listp param-value)
(org-hugo--get-yaml-toml-list-string param-value)
(org-hugo--get-yaml-toml-list-string param-key param-value)
(org-hugo--quote-string param-value)))
(setq res-param-str
(concat res-param-str
Expand Down Expand Up @@ -3368,9 +3371,10 @@ are \"toml\" and \"yaml\"."
(or (string= nested-key "extensions")
(string= nested-key "extensionsmask")))
(org-hugo--get-yaml-toml-list-string
nested-key
(mapcar #'org-hugo--return-valid-blackfriday-extension
nested-value))
(org-hugo--get-yaml-toml-list-string nested-value)))
(org-hugo--get-yaml-toml-list-string nested-key nested-value)))
((null nested-value)
"false")
((equal nested-value 't)
Expand All @@ -3397,7 +3401,7 @@ are \"toml\" and \"yaml\"."
(cond (;; Tags, categories, keywords, aliases,
;; custom front-matter which are lists.
(listp value)
(org-hugo--get-yaml-toml-list-string value))
(org-hugo--get-yaml-toml-list-string key value))
(t
(org-hugo--quote-string value nil format)))))))))))
(concat sep front-matter nested-string menu-string res-string sep)))
Expand Down
11 changes: 3 additions & 8 deletions test/site/content-org/single-posts/empty_tag.org
Expand Up @@ -4,17 +4,12 @@
#+hugo_base_dir: ../../

#+hugo_section: singles
#+hugo_tags: "" "empty-tag" "tag"
#+hugo_tags: "" "empty-tag" "tag" "dont_export_during_make_test"

#+begin_description
Ensure that empty tag in Org file gets ignored.
Ensure that empty tag in Org file throws a ~user-error~.
#+end_description

[[https://github.com/kaushalmodi/ox-hugo/issues/221][~ox-hugo~ issue #221]]

The Org source of this post has:
#+begin_src org
,#+hugo_tags: "" "empty-tag"
#+end_src

This test ensures that the ~""~ tag gets ignored.
The Org source of this post has ~""~ in the ~#+hugo_tags:~.
12 changes: 3 additions & 9 deletions test/site/content/singles/empty_tag.md
@@ -1,16 +1,10 @@
+++
title = "Post with an empty tag"
description = "Ensure that empty tag in Org file gets ignored."
tags = ["empty-tag", "tag"]
description = "Ensure that empty tag in Org file throws a `user-error`."
tags = ["", "empty-tag", "tag", "dont_export_during_make_test"]
draft = false
+++

[`ox-hugo` issue #221](https://github.com/kaushalmodi/ox-hugo/issues/221)

The Org source of this post has:

```org
#+hugo_tags: "" "empty-tag"
```

This test ensures that the `""` tag gets ignored.
The Org source of this post has `""` in the `#+hugo_tags:`.

0 comments on commit 8e5b85d

Please sign in to comment.