From 512b1413befccebce55058cc47b3b2d8e39a4fbf Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Wed, 22 May 2019 19:06:12 -0700 Subject: [PATCH] Try to fix the 'images-resize` task's handling of :out-dir. I think this makes `images-resize`'s behavior more consistent with other tasks. Fixes #233. --- src/io/perun.clj | 7 +++---- test/io/perun_test.clj | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 57ffde6b..cc593e2d 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -309,11 +309,11 @@ (defn resize-paths "Returns a map of path -> input for images-resize" - [fileset {:keys [out-dir parent-path meta resolutions] :as options} tmp-dir] + [fileset {:keys [out-dir meta resolutions] :as options} tmp-dir] (let [global-meta (pm/get-global-meta fileset) files (boot/ls fileset)] (reduce - (fn [result {:keys [slug path extension] :as entry}] + (fn [result {:keys [slug path extension parent-path] :as entry}] (reduce (fn [result* resolution] (let [new-filename (str slug "_" resolution "." extension) @@ -342,8 +342,7 @@ [image-resizer "0.1.10"]]) (def ^:private +images-resize-defaults+ - {:out-dir "public" - :resolutions #{3840 2560 1920 1280 1024 640} + {:resolutions #{3840 2560 1920 1280 1024 640} :filterer identity :extensions [".png" ".jpeg" ".jpg"]}) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 71eb03c4..10c37101 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -115,26 +115,35 @@ :msg "`images-dimensions should add `:io.perun/images-dimensions` to `:io.perun/trace`"))) (deftesttask images-resize-test [] - (comp (add-image :path "test-image.jpg" :type "JPG" :width 10 :height 10) + (comp (add-image :path "public/test-image-1.jpg" :type "JPG" :width 10 :height 10) + (add-image :path "public/images/test-image-2.jpg" :type "JPG" :width 10 :height 10) (p/images-resize :resolutions #{100 200}) - (value-check :path (perun/url-to-path "public/test-image_100.jpg") + (value-check :path (perun/url-to-path "test-image-1_100.jpg") :value-fn #(meta= %1 %2 :width 100) :msg "`images-resize resize image file and set `:width` metadata") - (value-check :path (perun/url-to-path "public/test-image_100.jpg") + (value-check :path (perun/url-to-path "test-image-1_100.jpg") :value-fn #(meta= %1 %2 :height 100) :msg "`images-resize resize image file and set `:height` metadata") - (value-check :path (perun/url-to-path "public/test-image_100.jpg") + (value-check :path (perun/url-to-path "test-image-1_100.jpg") :value-fn #(meta-contains? %1 %2 :io.perun/trace :io.perun/images-resize) :msg "`images-resize should add `:io.perun/images-resize` to `:io.perun/trace`") - (value-check :path (perun/url-to-path "public/test-image_200.jpg") + (value-check :path (perun/url-to-path "test-image-1_200.jpg") :value-fn #(meta= %1 %2 :width 200) :msg "`images-resize resize image file and set `:width` metadata") - (value-check :path (perun/url-to-path "public/test-image_200.jpg") + (value-check :path (perun/url-to-path "test-image-1_200.jpg") :value-fn #(meta= %1 %2 :height 200) :msg "`images-resize resize image file and set `:height` metadata") - (value-check :path (perun/url-to-path "public/test-image_200.jpg") + (value-check :path (perun/url-to-path "test-image-1_200.jpg") :value-fn #(meta-contains? %1 %2 :io.perun/trace :io.perun/images-resize) - :msg "`images-resize should add `:io.perun/images-resize` to `:io.perun/trace`"))) + :msg "`images-resize should add `:io.perun/images-resize` to `:io.perun/trace`") + (value-check :path (perun/url-to-path "public/images/test-image-2_100.jpg") + :value-fn #(meta= %1 %2 :width 100) + :msg "`images-resize resize image file and set `:width` metadata") + (add-image :path "public/images/test-image-3.jpg" :type "JPG" :width 10 :height 10) + (p/images-resize :resolutions #{100} :out-dir "public") + (value-check :path (perun/url-to-path "public/test-image-3_100.jpg") + :value-fn #(meta= %1 %2 :width 100) + :msg "`images-resize resize image file and set `:width` metadata"))) (deftask add-txt-file [p path PATH str "path of the file to add"