This commit is contained in:
jem 2020-02-18 19:40:37 +01:00
parent 5ac6cfbcf3
commit f72d97e7d1
3 changed files with 13 additions and 13 deletions

View file

@ -69,7 +69,7 @@
; TODO: rename? Allow base-path to be ""? ; TODO: rename? Allow base-path to be ""?
; base-path must not be "" ; base-path must not be ""
(defn get-resources-recursive ;:- [Resource] (defn get-resources ;:- [Resource]
[fs-prefix ;:- Prefix [fs-prefix ;:- Prefix
base-path ;:- VirtualPath base-path ;:- VirtualPath
paths ;:- [VirtualPath] paths ;:- [VirtualPath]
@ -96,7 +96,7 @@
:or {from-cp true :or {from-cp true
from-fs true}}] from-fs true}}]
(map #(:virtual-path %) (map #(:virtual-path %)
(get-resources-recursive (get-resources
fs-prefix base-path paths fs-prefix base-path paths
:from-cp from-cp :from-cp from-cp
:from-fs from-fs))) :from-fs from-fs)))
@ -127,7 +127,7 @@
(let [resources (let [resources
(sort (sort
this/compare-resource this/compare-resource
(get-resources-recursive fs-prefix base-path source-paths))] (get-resources fs-prefix base-path source-paths))]
(if (empty? resources) (if (empty? resources)
(throw (IllegalArgumentException. (str "resource " base-path ", " (throw (IllegalArgumentException. (str "resource " base-path ", "
source-paths " not found"))) source-paths " not found")))

View file

@ -38,7 +38,7 @@
(defn get-distinct-markup-dirs (defn get-distinct-markup-dirs
[fs-prefix posts pages ignore-patterns] [fs-prefix posts pages ignore-patterns]
(let [base-path "templates/md" (let [base-path "templates/md"
resources (cp-io/get-resources-recursive resources (cp-io/get-resources
fs-prefix base-path [pages posts]) fs-prefix base-path [pages posts])
filtered-resources (->> (filter #(= (:resource-type %) :dir) resources) filtered-resources (->> (filter #(= (:resource-type %) :dir) resources)
(cp-io/distinct-resources-by-path))] (cp-io/distinct-resources-by-path))]

View file

@ -23,41 +23,41 @@
"folder21/file212"] "folder21/file212"]
(sort (sort
(map ftt/filter-path (map ftt/filter-path
(sut/get-resources-recursive (sut/get-resources
"fs_root" "fs_root"
"base2" ["folder21" "file22"])))))) "base2" ["folder21" "file22"]))))))
(deftest test-get-resources-recursive (deftest test-get-resources
(is (= (is (=
[] []
(sut/get-resources-recursive "" "templates/themes/bootstrap4-test" ["not-existing"]))) (sut/get-resources "" "templates/themes/bootstrap4-test" ["not-existing"])))
(is (= (is (=
[{:virtual-path "dummy_from_jar", :source-type :java-classpath-jar, :resource-type :file}] [{:virtual-path "dummy_from_jar", :source-type :java-classpath-jar, :resource-type :file}]
(map ftt/filter-object (map ftt/filter-object
(sut/get-resources-recursive "not-existing" "dummy" ["dummy_from_jar"])))) (sut/get-resources "not-existing" "dummy" ["dummy_from_jar"]))))
(is (= (is (=
(sort ["dummy2/dummy2_from_jar" "dummy2/dummy_common" "dummy2" "dummy_from_jar" "dummy_from_fs" (sort ["dummy2/dummy2_from_jar" "dummy2/dummy_common" "dummy2" "dummy_from_jar" "dummy_from_fs"
"dummy2/dummy2_from_fs"]) "dummy2/dummy2_from_fs"])
(sort (map ftt/filter-path (sort (map ftt/filter-path
(sut/get-resources-recursive "fs_root" "dummy" (sut/get-resources "fs_root" "dummy"
["dummy_from_jar" "dummy_from_fs" "dummy2"]))))) ["dummy_from_jar" "dummy_from_fs" "dummy2"])))))
(is (= (is (=
[{:virtual-path "js/dummy.js" [{:virtual-path "js/dummy.js"
:source-type :java-classpath-filesystem :source-type :java-classpath-filesystem
:resource-type :file}] :resource-type :file}]
(map ftt/filter-object (map ftt/filter-object
(sut/get-resources-recursive (sut/get-resources
"" "templates/themes/bootstrap4-test" ["js/dummy.js"])))) "" "templates/themes/bootstrap4-test" ["js/dummy.js"]))))
(is (= (is (=
[] []
(sut/get-resources-recursive (sut/get-resources
"" "templates/themes/bootstrap4-test" ["js/dummy.js"] :from-cp false))) "" "templates/themes/bootstrap4-test" ["js/dummy.js"] :from-cp false)))
(is (= (is (=
["js/subdir" ["js/subdir"
"js/subdir/subdummy.js" "js/subdir/subdummy.js"
"js/subdir/test.js"] "js/subdir/test.js"]
(sort (map :virtual-path (sort (map :virtual-path
(sut/get-resources-recursive (sut/get-resources
"" "templates/themes/bootstrap4-test" ["js/subdir"]))))) "" "templates/themes/bootstrap4-test" ["js/subdir"])))))
(is (= (is (=
["." ["."
@ -72,7 +72,7 @@
"./js/subdir/subdummy.js" "./js/subdir/subdummy.js"
"./js/subdir/test.js"] "./js/subdir/test.js"]
(sort (map :virtual-path (sort (map :virtual-path
(sut/get-resources-recursive (sut/get-resources
"test-resources" "templates/themes/bootstrap4-test" ["."])))))) "test-resources" "templates/themes/bootstrap4-test" ["."]))))))
(deftest test-distinct-resources-by-path (deftest test-distinct-resources-by-path