fix separation of new-io

This commit is contained in:
jem 2020-01-07 14:20:21 +01:00
parent a890a693b3
commit 78ff298b42
5 changed files with 102 additions and 72 deletions

View file

@ -9,6 +9,7 @@
[text-decoration.core :refer :all] [text-decoration.core :refer :all]
[cryogen-core.io :as cryogen-io] [cryogen-core.io :as cryogen-io]
[cryogen-core.new-io :as new-io] [cryogen-core.new-io :as new-io]
[cryogen-core.classpath-able-io :as cp-io]
[cryogen-core.klipse :as klipse] [cryogen-core.klipse :as klipse]
[cryogen-core.markup :as m] [cryogen-core.markup :as m]
[cryogen-core.rss :as rss] [cryogen-core.rss :as rss]
@ -541,7 +542,7 @@
file-resource-prefix "resources/" file-resource-prefix "resources/"
resource-prefix (str "templates/themes/" theme) resource-prefix (str "templates/themes/" theme)
file-uri (:uri file-uri (:uri
(new-io/resource-from-cp-or-fs (cp-io/resource-from-cp-or-fs
file-resource-prefix resource-prefix "" file-resource-prefix resource-prefix ""
:from-cp false))] :from-cp false))]
(when debug? (when debug?
@ -555,24 +556,24 @@
;; TODO: 2. use target/theme as custome-resource-path ;; TODO: 2. use target/theme as custome-resource-path
(set-custom-resource-path! (.toString file-uri)) (set-custom-resource-path! (.toString file-uri))
;(cryogen-io/wipe-public-folder keep-files) ;(cryogen-io/wipe-public-folder keep-files)
(new-io/delete-resource-recursive! (new-io/path "resources/public" blog-prefix)) (new-io/delete-resource-recursive! (cp-io/path "resources/public" blog-prefix))
(println (blue "copying theme resources")) (println (blue "copying theme resources"))
;(cryogen-io/copy-resources-from-theme config) ;(cryogen-io/copy-resources-from-theme config)
(new-io/copy-resources-from-theme! "resources/" (new-io/copy-resources-from-theme! "resources/"
theme theme
(new-io/path "resources/public" blog-prefix) (cp-io/path "resources/public" blog-prefix)
ignored-files) ignored-files)
(println (blue "copying resources")) (println (blue "copying resources"))
;(cryogen-io/copy-resources config) ;(cryogen-io/copy-resources config)
(new-io/copy-resources-from-user! "resources/" (new-io/copy-resources-from-templates! "resources/"
resources resources
(new-io/path "resources/public" blog-prefix) (cp-io/path "resources/public" blog-prefix)
ignored-files) ignored-files)
;(copy-resources-from-markup-folders config) ;(copy-resources-from-markup-folders config)
(new-io/create-dirs-from-markup-folders! "resources/" (new-io/create-dirs-from-markup-folders! "resources/"
(:posts config) (:posts config)
(:pages config) (:pages config)
(new-io/path "resources/public" blog-prefix) (cp-io/path "resources/public" blog-prefix)
ignored-files) ignored-files)
; TODO: Hier weitermachen ; TODO: Hier weitermachen
(compile-pages params modelled-pages) (compile-pages params modelled-pages)

View file

@ -11,7 +11,9 @@
[clojure.java.io :as io] [clojure.java.io :as io]
[cryogen-core.classpath-able-io :as cp-io])) [cryogen-core.classpath-able-io :as cp-io]))
(defn copy-resources-from-user! (def delete-resource-recursive! cp-io/delete-resource-recursive!)
(defn copy-resources-from-templates!
[fs-prefix resources target-path ignore-patterns] [fs-prefix resources target-path ignore-patterns]
(let [resource-path "templates"] (let [resource-path "templates"]
(cp-io/copy-resources! fs-prefix resource-path resources (cp-io/copy-resources! fs-prefix resource-path resources

View file

@ -10,6 +10,7 @@
(:require [clojure.test :refer :all] (:require [clojure.test :refer :all]
[clojure.java.io :as io] [clojure.java.io :as io]
[schema.core :as s] [schema.core :as s]
[cryogen-core.file-test-tools :as ftt]
[cryogen-core.classpath-able-io :as sut])) [cryogen-core.classpath-able-io :as sut]))
(s/set-fn-validation! true) (s/set-fn-validation! true)
@ -18,23 +19,6 @@
(def target "target/tmp") (def target "target/tmp")
(defn verify-file-exists [path]
(.exists (io/file path)))
(defn verify-dir-exists [path]
(and (verify-file-exists path)
(.isDirectory (io/file path))))
(defn filter-object
[e]
{:path (:path e)
:source-type (:source-type e)
:resource-type (:resource-type e)})
(deftest test-uri-from-cp
(is
(sut/file-from-cp ".gitkeep")))
(deftest test-resource-from-cp-or-fs (deftest test-resource-from-cp-or-fs
(is (is
(.exists (.exists
@ -60,7 +44,7 @@
{:path "js/subdir" {:path "js/subdir"
:source-type :classpath :source-type :classpath
:resource-type :dir} :resource-type :dir}
(filter-object (ftt/filter-object
(sut/resource-from-cp-or-fs (sut/resource-from-cp-or-fs
"./not-existing-so-load-from-cp" "./not-existing-so-load-from-cp"
"templates/themes/bootstrap4-test" "templates/themes/bootstrap4-test"
@ -74,7 +58,7 @@
[{:path "js/dummy.js" [{:path "js/dummy.js"
:source-type :classpath :source-type :classpath
:resource-type :file}] :resource-type :file}]
(map filter-object (map ftt/filter-object
(sut/get-resources-recursive (sut/get-resources-recursive
"" "templates/themes/bootstrap4-test" ["js/dummy.js"])))) "" "templates/themes/bootstrap4-test" ["js/dummy.js"]))))
(is (= (is (=
@ -104,18 +88,6 @@
(sut/get-resources-recursive (sut/get-resources-recursive
"" "templates/themes/bootstrap4-test" ["."])))))) "" "templates/themes/bootstrap4-test" ["."]))))))
(deftest test-get-distinct-markup-dirs
(is (=
["test_pages"
"test_pages/home"
"test_posts"
"test_posts/home"]
(sort (map :path
(sut/get-distinct-markup-dirs
"not-existing-get-from-cp"
"test_posts" "test_pages"
""))))))
(deftest test-distinct-resources-by-path (deftest test-distinct-resources-by-path
(is (= [{:path "pages/test"} (is (= [{:path "pages/test"}
{:path "pages/test1"} {:path "pages/test1"}
@ -125,43 +97,14 @@
{:path "pages/test2"} {:path "pages/test2"}
{:path "pages/test1"}])))) {:path "pages/test1"}]))))
(deftest test-create-dirs-from-markup-folders! (deftest test-filter-for-ignore-patterns
(is (do (is (=
(sut/delete-resource-recursive! (str target "2")) ["file.js"]
(sut/create-dirs-from-markup-folders! (sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
"not-existing-get-from-cp" "test_posts" "test_pages"
(str target "2") "")
(and (verify-dir-exists
(str (str target "2") "/test_pages"))
(verify-dir-exists
(str (str target "2") "/test_posts"))
(verify-dir-exists
(str (str target "2") "/test_pages/home"))))))
(deftest test-delete-resource-recursive! (deftest test-delete-resource-recursive!
(is (is
(do (do
(.mkdir (io/file target)) (.mkdir (io/file target))
(sut/delete-resource-recursive! target) (sut/delete-resource-recursive! target)
(not (verify-dir-exists target))))) (not (ftt/verify-dir-exists target)))))
(deftest test-filter-for-ignore-patterns
(is (=
["file.js"]
(sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
(deftest test-copy-resources-from-theme! (is (do
(sut/delete-resource-recursive! target)
(sut/copy-resources-from-theme! "./" theme target "")
(and (verify-dir-exists
(str target "/js"))
(verify-file-exists
(str target "/js/dummy.js"))
(verify-dir-exists
(str target "/js/subdir"))
(verify-file-exists
(str target "/js/subdir/subdummy.js"))
(verify-file-exists
(str target "/css/dummy.css"))
(verify-file-exists
(str target "/404.html"))))))

View file

@ -0,0 +1,24 @@
; Copyright (c) meissa. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns cryogen-core.file-test-tools
(:require [clojure.java.io :as io]
[schema.core :as s]))
(defn verify-file-exists [path]
(.exists (io/file path)))
(defn verify-dir-exists [path]
(and (verify-file-exists path)
(.isDirectory (io/file path))))
(defn filter-object
[e]
{:path (:path e)
:source-type (:source-type e)
:resource-type (:resource-type e)})

View file

@ -0,0 +1,60 @@
; Copyright (c) meissa. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns cryogen-core.new-io-test
(:require [clojure.test :refer :all]
[schema.core :as s]
[cryogen-core.file-test-tools :as ftt]
[cryogen-core.new-io :as sut]))
(s/set-fn-validation! true)
(def theme "bootstrap4-test")
(def target "target/tmp")
(deftest test-get-distinct-markup-dirs
(is (=
["test_pages"
"test_pages/home"
"test_posts"
"test_posts/home"]
(sort (map :path
(sut/get-distinct-markup-dirs
"not-existing-get-from-cp"
"test_posts" "test_pages"
""))))))
(deftest test-create-dirs-from-markup-folders!
(is (do
(sut/delete-resource-recursive! (str target "2"))
(sut/create-dirs-from-markup-folders!
"not-existing-get-from-cp" "test_posts" "test_pages"
(str target "2") "")
(and (ftt/verify-dir-exists
(str (str target "2") "/test_pages"))
(ftt/verify-dir-exists
(str (str target "2") "/test_posts"))
(ftt/verify-dir-exists
(str (str target "2") "/test_pages/home"))))))
(deftest test-copy-resources-from-theme! (is (do
(sut/delete-resource-recursive! target)
(sut/copy-resources-from-theme! "./" theme target "")
(and (ftt/verify-dir-exists
(str target "/js"))
(ftt/verify-file-exists
(str target "/js/dummy.js"))
(ftt/verify-dir-exists
(str target "/js/subdir"))
(ftt/verify-file-exists
(str target "/js/subdir/subdummy.js"))
(ftt/verify-file-exists
(str target "/css/dummy.css"))
(ftt/verify-file-exists
(str target "/404.html"))))))