From b49ebe618676684d94398287a1b4d40d5c992eff Mon Sep 17 00:00:00 2001 From: Lukas Schondorff Date: Fri, 13 Dec 2019 11:41:16 +0100 Subject: [PATCH 1/3] renamed copy-dir --- src/cryogen_core/classpath_able_io.clj | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index fb26ed0..70f1faa 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -33,7 +33,7 @@ file-from-fs) (catch Exception e nil)))) - + (defn file-from-cp-or-filesystem [fs-prefix resource-path] (let [from-fs (file-from-fs fs-prefix resource-path)] @@ -42,12 +42,12 @@ (file-from-cp resource-path)))) (defn copy-file - [source-file ;first element of (.list source-dir) + [source-file target-file] (do (io/make-parents target-file) (io/copy source-file target-file))) -(defn copy-dir +(defn do-copy [source-dir target-dir ignore-patterns] (loop [source-list (.list source-dir) file-path-prefix [""]] @@ -70,15 +70,9 @@ (let [source-file (file-from-cp-or-filesystem fs-prefix source-path) target-file (io/file target-path source-path) is-source-dir? (.isDirectory source-file)] - (cond - (nil? source-file) + (if (nil? source-file) (throw (IllegalArgumentException. (str "resource " source-path " not found"))) - is-source-dir? - (copy-dir source-file target-file ignore-patterns) - :else (copy-file source-file target-file) - ;; TODO: Call copy-file fct. - take care on parameter. - ))) - + (do-copy source-file target-file ignore-patterns)))) (defn copy-resources-from-theme [fs-prefix theme target-path] @@ -86,4 +80,3 @@ (copy-resources fs-prefix (str theme-path "/css") target-path "") (copy-resources fs-prefix (str theme-path "/js") target-path "") (copy-resources fs-prefix (str theme-path "/html/404.html") target-path ""))) - From 88cf7dd3df5deadb4e4ca1572e23fcfda77513fc Mon Sep 17 00:00:00 2001 From: lukas Date: Fri, 13 Dec 2019 12:15:37 +0100 Subject: [PATCH 2/3] fixed target-path --- src/cryogen_core/classpath_able_io.clj | 2 +- test-resources/templates/themes/bootstrap4-test/html/403.html | 0 .../templates/themes/bootstrap4-test/js/subdir/test.js | 0 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 test-resources/templates/themes/bootstrap4-test/html/403.html create mode 100644 test-resources/templates/themes/bootstrap4-test/js/subdir/test.js diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index 70f1faa..c06982e 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -79,4 +79,4 @@ (let [theme-path (str "templates/themes/" theme)] (copy-resources fs-prefix (str theme-path "/css") target-path "") (copy-resources fs-prefix (str theme-path "/js") target-path "") - (copy-resources fs-prefix (str theme-path "/html/404.html") target-path ""))) + (copy-resources fs-prefix (str theme-path "/html/") target-path ""))) diff --git a/test-resources/templates/themes/bootstrap4-test/html/403.html b/test-resources/templates/themes/bootstrap4-test/html/403.html new file mode 100644 index 0000000..e69de29 diff --git a/test-resources/templates/themes/bootstrap4-test/js/subdir/test.js b/test-resources/templates/themes/bootstrap4-test/js/subdir/test.js new file mode 100644 index 0000000..e69de29 From ea3f6262834c2c8dd2b6f03182f6daffb4d07b29 Mon Sep 17 00:00:00 2001 From: Jan Krebs Date: Fri, 13 Dec 2019 14:18:53 +0100 Subject: [PATCH 3/3] "mob next [ci-skip]" --- src/cryogen_core/classpath_able_io.clj | 18 ++++++++++++++---- src/cryogen_core/compiler.clj | 7 +++++-- test/cryogen_core/classpath_able_io_test.clj | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/cryogen_core/classpath_able_io.clj b/src/cryogen_core/classpath_able_io.clj index c06982e..db44ea8 100644 --- a/src/cryogen_core/classpath_able_io.clj +++ b/src/cryogen_core/classpath_able_io.clj @@ -10,6 +10,16 @@ (:require [clojure.java.io :as io] [clojure.string :as s])) +(def public "resources/public") + +(defn path + "Creates path from given parts, ignore empty elements" + [& path-parts] + (->> path-parts + (remove s/blank?) + (s/join "/") + (#(s/replace % #"/+" "/")))) + (defn filter-for-ignore-patterns [ignore-patterns source-list] (filter #(not (re-matches ignore-patterns %)) source-list)) @@ -75,8 +85,8 @@ (do-copy source-file target-file ignore-patterns)))) (defn copy-resources-from-theme - [fs-prefix theme target-path] + [fs-prefix theme target-path ignore-patterns] (let [theme-path (str "templates/themes/" theme)] - (copy-resources fs-prefix (str theme-path "/css") target-path "") - (copy-resources fs-prefix (str theme-path "/js") target-path "") - (copy-resources fs-prefix (str theme-path "/html/") target-path ""))) + (copy-resources fs-prefix (str theme-path "/css") target-path ignore-patterns) + (copy-resources fs-prefix (str theme-path "/js") target-path ignore-patterns) + (copy-resources fs-prefix (str theme-path "/html/") target-path ignore-patterns))) diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index f4dc4cf..5f21eb7 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -8,6 +8,7 @@ [selmer.util :refer [set-custom-resource-path!]] [text-decoration.core :refer :all] [cryogen-core.io :as cryogen-io] + [cryogen-core.classpath-able-io :as cp-io] [cryogen-core.klipse :as klipse] [cryogen-core.markup :as m] [cryogen-core.rss :as rss] @@ -533,8 +534,10 @@ (set-custom-resource-path! (str "file:resources/templates/themes/" theme)) (cryogen-io/wipe-public-folder keep-files) (println (blue "copying theme resources")) - ;; TODO: adjust for reading from jar - (cryogen-io/copy-resources-from-theme config) + (cp-io/copy-resources-from-theme "resources/templates/themes/" + theme + (cp-io/path "resources/public" blog-prefix) + ignored-files) (println (blue "copying resources")) (cryogen-io/copy-resources config) (copy-resources-from-markup-folders config) diff --git a/test/cryogen_core/classpath_able_io_test.clj b/test/cryogen_core/classpath_able_io_test.clj index 044c2f1..62170d2 100644 --- a/test/cryogen_core/classpath_able_io_test.clj +++ b/test/cryogen_core/classpath_able_io_test.clj @@ -42,7 +42,7 @@ (deftest test-copy-resources-from-theme (is (do - (sut/copy-resources-from-theme "./" theme target) + (sut/copy-resources-from-theme "./" theme target "") (and (verify-dir-exists (str target "/templates/themes/bootstrap4-test/js")) (verify-file-exists