summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-12-29 21:48:02 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-12-29 21:48:02 +0100
commitccf2b988af90878115aabd100bc62a5d6d2eefff (patch)
tree1b2174804da6859b51c15461a183966817eb2134
parent2c6a4bec7371c122f31eb077319f032fa8fcf75c (diff)
downloadorg-mode-ccf2b988af90878115aabd100bc62a5d6d2eefff.tar.gz
ox-publish: Fix :base-extension (part 2)
* lisp/ox-publish.el (org-publish-get-base-files): Make sure to remove directories. * testing/examples/pub/file.txt: * testing/examples/pub/noextension: New files. * testing/lisp/test-ox-publish.el (test-org-publish/base-extension): New test.
-rw-r--r--lisp/ox-publish.el11
-rw-r--r--testing/examples/pub/file.txt1
-rw-r--r--testing/examples/pub/noextension1
-rw-r--r--testing/lisp/test-ox-publish.el306
4 files changed, 182 insertions, 137 deletions
diff --git a/lisp/ox-publish.el b/lisp/ox-publish.el
index 8cea7e8..f4943c5 100644
--- a/lisp/ox-publish.el
+++ b/lisp/ox-publish.el
@@ -429,12 +429,13 @@ This splices all the components into the list."
(let* ((base-dir (file-name-as-directory
(org-publish-property :base-directory project)))
(extension (or (org-publish-property :base-extension project) "org"))
- (match (if (eq extension 'any) "^[^\\.]"
- (concat "^[^\\.].*\\.\\(" extension "\\)$")))
+ (match (and (not (eq extension 'any))
+ (concat "^[^\\.].*\\.\\(" extension "\\)$")))
(base-files
- (if (org-publish-property :recursive project)
- (directory-files-recursively base-dir match)
- (directory-files base-dir t match t))))
+ (cl-remove-if #'file-directory-p
+ (if (org-publish-property :recursive project)
+ (directory-files-recursively base-dir match)
+ (directory-files base-dir t match t)))))
(org-uniquify
(append
;; Files from BASE-DIR. Apply exclusion filter before adding
diff --git a/testing/examples/pub/file.txt b/testing/examples/pub/file.txt
new file mode 100644
index 0000000..3de705a
--- /dev/null
+++ b/testing/examples/pub/file.txt
@@ -0,0 +1 @@
+Text
diff --git a/testing/examples/pub/noextension b/testing/examples/pub/noextension
new file mode 100644
index 0000000..45c6427
--- /dev/null
+++ b/testing/examples/pub/noextension
@@ -0,0 +1 @@
+No extension \ No newline at end of file
diff --git a/testing/lisp/test-ox-publish.el b/testing/lisp/test-ox-publish.el
index 34edc9e..ab2e729 100644
--- a/testing/lisp/test-ox-publish.el
+++ b/testing/lisp/test-ox-publish.el
@@ -19,12 +19,16 @@
;;; Code:
+
+;;; Helper functions
+
(defun org-test-publish (properties handler)
"Publish a project defined by PROPERTIES.
Call HANDLER with the publishing directory as its sole argument.
Unless set otherwise in PROPERTIES, `:base-directory' is set to
\"examples/pub/\" sub-directory from test directory and
`:publishing-function' is set to `org-publish-attachment'."
+ (declare (indent 1))
(let* ((org-publish-use-timestamps-flag nil)
(org-publish-cache nil)
(base-dir (expand-file-name "examples/pub/" org-test-dir))
@@ -53,6 +57,43 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
(when (and site-map (file-exists-p site-map))
(delete-file site-map))))))
+
+;;; Mandatory properties
+
+(ert-deftest test-org-publish/base-extension ()
+ "Test `:base-extension' specifications"
+ ;; Regular tests.
+ (should
+ (equal '("a.org" "b.org")
+ (org-test-publish '(:base-extension "org")
+ (lambda (dir)
+ (remove ".org-timestamps"
+ (cl-remove-if #'file-directory-p
+ (directory-files dir)))))))
+ (should
+ (equal '("file.txt")
+ (org-test-publish '(:base-extension "txt")
+ (lambda (dir)
+ (remove ".org-timestamps"
+ (cl-remove-if #'file-directory-p
+ (directory-files dir)))))))
+ ;; A nil value is equivalent to ".org".
+ (should
+ (equal '("a.org" "b.org")
+ (org-test-publish '(:base-extension nil)
+ (lambda (dir)
+ (remove ".org-timestamps"
+ (cl-remove-if #'file-directory-p
+ (directory-files dir)))))))
+ ;; Symbol `any' includes all files, even those without extension.
+ (should
+ (equal '("a.org" "b.org" "file.txt" "noextension")
+ (org-test-publish '(:base-extension any)
+ (lambda (dir)
+ (remove ".org-timestamps"
+ (cl-remove-if #'file-directory-p
+ (directory-files dir))))))))
+
;;; Site-map
@@ -63,35 +104,35 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
;; defaults to "sitemap.org".
(should
(org-test-publish
- '(:auto-sitemap t)
- (lambda (dir) (file-exists-p (expand-file-name "sitemap.org" dir)))))
+ '(:auto-sitemap t)
+ (lambda (dir) (file-exists-p (expand-file-name "sitemap.org" dir)))))
(should-not
(org-test-publish
- '(:auto-sitemap nil)
- (lambda (dir) (file-exists-p (expand-file-name "sitemap.org" dir)))))
+ '(:auto-sitemap nil)
+ (lambda (dir) (file-exists-p (expand-file-name "sitemap.org" dir)))))
;; Site-map file name is controlled with `:sitemap-filename'.
(should
(org-test-publish
- '(:auto-sitemap t :sitemap-filename "mysitemap.org")
- (lambda (dir) (file-exists-p (expand-file-name "mysitemap.org" dir)))))
+ '(:auto-sitemap t :sitemap-filename "mysitemap.org")
+ (lambda (dir) (file-exists-p (expand-file-name "mysitemap.org" dir)))))
;; Site-map title is controlled with `:sitemap-title'. It defaults
;; to the project name.
(should
(equal "#+TITLE: Sitemap for project test"
(org-test-publish
- '(:auto-sitemap t)
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (point) (line-end-position)))))))
+ '(:auto-sitemap t)
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (point) (line-end-position)))))))
(should
(equal "#+TITLE: My title"
(org-test-publish
- '(:auto-sitemap t :sitemap-title "My title")
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (point) (line-end-position)))))))
+ '(:auto-sitemap t :sitemap-title "My title")
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (point) (line-end-position)))))))
;; Allowed site-map styles: `list' and `tree'.
(should
(equal "
@@ -99,15 +140,15 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:b.org][b]]
- [[file:sub/c.org][C]]"
(org-test-publish
- '(:auto-sitemap t
- :sitemap-sort-folders ignore
- :sitemap-style list
- :exclude "."
- :include ("a.org" "b.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :sitemap-sort-folders ignore
+ :sitemap-style list
+ :exclude "."
+ :include ("a.org" "b.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
(should
(equal "
- [[file:a.org][A]]
@@ -115,14 +156,14 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- sub
- [[file:sub/c.org][C]]"
(org-test-publish
- '(:auto-sitemap t
- :sitemap-style tree
- :exclude "."
- :include ("a.org" "b.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :sitemap-style tree
+ :exclude "."
+ :include ("a.org" "b.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
;; When style is `list', `:sitemap-sort-folders' controls the order
;; of appearance of directories among published files.
(should
@@ -132,16 +173,16 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:a.org][A]]
- [[file:sub/c.org][C]]"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders first
- :exclude "."
- :include ("a.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders first
+ :exclude "."
+ :include ("a.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
(should
(equal
"
@@ -149,16 +190,16 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:sub/c.org][C]]
- sub/"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders last
- :exclude "."
- :include ("a.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders last
+ :exclude "."
+ :include ("a.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
;; When style is `list', `:sitemap-sort-folders' can be used to
;; toggle visibility of directories in the site-map.
(should
@@ -166,30 +207,30 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
(string-match-p
"- sub/$"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders t
- :exclude "."
- :include ("a.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max))))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders t
+ :exclude "."
+ :include ("a.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max))))))))
(should-not
(string-match-p
"- sub/$"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders ignore
- :exclude "."
- :include ("a.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders ignore
+ :exclude "."
+ :include ("a.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
;; Using `:sitemap-sort-files', files can be sorted alphabetically
;; (according to their title, or file name when there is none),
;; chronologically a anti-chronologically.
@@ -200,17 +241,17 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:b.org][b]]
- [[file:sub/c.org][C]]"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders ignore
- :sitemap-sort-files alphabetically
- :exclude "."
- :include ("a.org" "b.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders ignore
+ :sitemap-sort-files alphabetically
+ :exclude "."
+ :include ("a.org" "b.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
(should
(equal
"
@@ -218,17 +259,17 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:sub/c.org][C]]
- [[file:a.org][A]]"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders ignore
- :sitemap-sort-files chronologically
- :exclude "."
- :include ("a.org" "b.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders ignore
+ :sitemap-sort-files chronologically
+ :exclude "."
+ :include ("a.org" "b.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
(should
(equal
"
@@ -236,55 +277,56 @@ Unless set otherwise in PROPERTIES, `:base-directory' is set to
- [[file:sub/c.org][C]]
- [[file:b.org][b]]"
(org-test-publish
- '(:auto-sitemap t
- :recursive t
- :sitemap-style list
- :sitemap-sort-folders ignore
- :sitemap-sort-files anti-chronologically
- :exclude "."
- :include ("a.org" "b.org" "sub/c.org"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :recursive t
+ :sitemap-style list
+ :sitemap-sort-folders ignore
+ :sitemap-sort-files anti-chronologically
+ :exclude "."
+ :include ("a.org" "b.org" "sub/c.org"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
;; `:sitemap-format-entry' formats entries in the site-map whereas
;; `:sitemap-function' controls the full site-map.
(should
(equal "
- a.org"
(org-test-publish
- '(:auto-sitemap t
- :exclude "."
- :include ("a.org")
- :sitemap-format-entry
- (lambda (f _s _p) f))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-substring (line-beginning-position 2) (point-max)))))))
+ '(:auto-sitemap t
+ :exclude "."
+ :include ("a.org")
+ :sitemap-format-entry
+ (lambda (f _s _p) f))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-substring (line-beginning-position 2) (point-max)))))))
(should
(equal "Custom!"
(org-test-publish
- '(:auto-sitemap t
- :exclude "."
- :include ("a.org")
- :sitemap-function (lambda (title _files) "Custom!"))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-string))))))
+ '(:auto-sitemap t
+ :exclude "."
+ :include ("a.org")
+ :sitemap-function (lambda (_title _f) "Custom!"))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-string))))))
(should
(equal "[[file:a.org][A]]"
(org-test-publish
- '(:auto-sitemap t
- :exclude "."
- :include ("a.org")
- :sitemap-function
- (lambda (title files) (org-list-to-generic files nil)))
- (lambda (dir)
- (with-temp-buffer
- (insert-file-contents (expand-file-name "sitemap.org" dir))
- (buffer-string)))))))
+ '(:auto-sitemap t
+ :exclude "."
+ :include ("a.org")
+ :sitemap-function
+ (lambda (_title f) (org-list-to-generic f nil)))
+ (lambda (dir)
+ (with-temp-buffer
+ (insert-file-contents (expand-file-name "sitemap.org" dir))
+ (buffer-string)))))))
+
(provide 'test-ox-publish)
;;; test-ox-publish.el ends here