From c6559f8a3e32de7d8dc9fd6aa171a83bbef5974a Mon Sep 17 00:00:00 2001 From: lukas Date: Thu, 20 Feb 2020 16:05:12 +0100 Subject: [PATCH] removed old io --- src/cryogen_core/compiler.clj | 21 +++++------ src/cryogen_core/io.clj | 59 ----------------------------- src/cryogen_core/new_io.clj | 71 ++++++++++++++++++++++++++++++++++- src/cryogen_core/rss.clj | 5 +-- src/cryogen_core/sass.clj | 6 +-- src/cryogen_core/sitemap.clj | 1 - src/cryogen_core/watcher.clj | 4 +- 7 files changed, 86 insertions(+), 81 deletions(-) delete mode 100644 src/cryogen_core/io.clj diff --git a/src/cryogen_core/compiler.clj b/src/cryogen_core/compiler.clj index 9bb7d89..3cfe7c5 100644 --- a/src/cryogen_core/compiler.clj +++ b/src/cryogen_core/compiler.clj @@ -8,7 +8,6 @@ [selmer.util :refer [set-custom-resource-path!]] [text-decoration.core :refer :all] ; TODO: remove all cryogen-io occurance - [cryogen-core.io :as cryogen-io] [cryogen-core.new-io :as new-io] [cryogen-core.classpath-able-io :as cp-io] [cryogen-core.klipse :as klipse] @@ -227,8 +226,8 @@ "When `clean-urls?` is set, appends `/index.html` before spit; otherwise just spits." [file-uri {:keys [clean-urls?]} data] (if clean-urls? - (cryogen-io/create-file-recursive (new-io/path file-uri "index.html") data) - (cryogen-io/create-file file-uri data))) + (new-io/create-file-recursive (new-io/path file-uri "index.html") data) + (new-io/create-file file-uri data))) (defn- print-debug-info [data] (println "DEBUG:") @@ -263,7 +262,7 @@ :as params} posts] (when-not (empty? posts) (println (blue "compiling posts")) - (cryogen-io/create-folder (new-io/path "/" blog-prefix post-root-uri)) + (new-io/create-folder (new-io/path "/" blog-prefix post-root-uri)) (doseq [{:keys [uri] :as post} posts] (println "-->" (cyan uri)) @@ -285,7 +284,7 @@ :as params} posts-by-tag] (when-not (empty? posts-by-tag) (println (blue "compiling tags")) - (cryogen-io/create-folder (new-io/path "/" blog-prefix tag-root-uri)) + (new-io/create-folder (new-io/path "/" blog-prefix tag-root-uri)) (doseq [[tag posts] posts-by-tag] (let [{:keys [name uri]} (tag-info params tag)] (println "-->" (cyan uri)) @@ -362,7 +361,7 @@ previews (if (> (count previews) 1) (assoc-in previews [1 :prev] (page-uri "index.html" params)) previews)] - (cryogen-io/create-folder (new-io/path "/" blog-prefix "p")) + (new-io/create-folder (new-io/path "/" blog-prefix "p")) (doseq [{:keys [index posts prev next]} previews :let [index-page? (= 1 index)]] (write-html @@ -418,7 +417,7 @@ [{:keys [blog-prefix author-root-uri author] :as params} posts] (println (blue "compiling authors")) - (cryogen-io/create-folder (new-io/path "/" blog-prefix author-root-uri)) + (new-io/create-folder (new-io/path "/" blog-prefix author-root-uri)) ;; if the post author is empty defaults to config's :author (doseq [{:keys [author posts]} (group-for-author posts author)] (let [uri (page-uri (str author ".html") :author-root-uri params)] @@ -454,7 +453,7 @@ :as config}] (let [folders (->> (markup-entries post-root page-root) (filter template-dir?))] - (cryogen-io/copy-resources + (new-io/copy-resources (merge config {:resources folders :ignored-files (map #(re-pattern-from-ext (m/ext %)) (m/markups))})))) @@ -464,7 +463,7 @@ [] (try (let [config (-> "templates/config.edn" - cryogen-io/get-resource + new-io/get-resource slurp read-string (update-in [:blog-prefix] (fnil str "")) @@ -592,10 +591,10 @@ (compile-authors params posts)) (println (blue "generating site map")) (->> (sitemap/generate site-url ignored-files) - (cryogen-io/create-file (new-io/path "/" blog-prefix "sitemap.xml"))) + (new-io/create-file (new-io/path "/" blog-prefix "sitemap.xml"))) (println (blue "generating main rss")) (->> (rss/make-channel config posts) - (cryogen-io/create-file (new-io/path "/" blog-prefix rss-name))) + (new-io/create-file (new-io/path "/" blog-prefix rss-name))) (println (blue "generating filtered rss")) (rss/make-filtered-channels config posts-by-tag) (println (blue "compiling sass")) diff --git a/src/cryogen_core/io.clj b/src/cryogen_core/io.clj deleted file mode 100644 index aa7f3a5..0000000 --- a/src/cryogen_core/io.clj +++ /dev/null @@ -1,59 +0,0 @@ -(ns cryogen-core.io - (:require [clojure.java.io :as io] - [clojure.string :as s] - [cryogen-core.new-io :as new-io] - [me.raynes.fs :as fs])) - -(def public "resources/public") - -(defn re-filter [bool-fn re & other-res] - (let [res (conj other-res re)] - (reify java.io.FilenameFilter - (accept [this _ name] - (bool-fn (some #(re-find % name) res)))))) - -(def match-re-filter (partial re-filter some?)) -(def reject-re-filter (partial re-filter nil?)) - -(defn get-resource [resource] - (-> resource io/resource io/file)) - -(defn ignore [ignored-files] - (fn [^java.io.File file] - (let [name (.getName file) - matches (map #(re-find % name) ignored-files)] - (not (some seq matches))))) - -(defn create-folder [folder] - (let [loc (io/file (new-io/path public folder))] - (when-not (.exists loc) - (.mkdirs loc)))) - -(defn create-file [file data] - (spit (new-io/path public file) data)) - -(defn create-file-recursive [file data] - (create-folder (.getParent (io/file file))) - (create-file file data)) - -(defn copy-dir [src target ignored-files] - (fs/mkdirs target) - (let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files) - files (.listFiles (io/file src) filename-filter)] - (doseq [^java.io.File f files] - (let [out (io/file target (.getName f))] - (if (.isDirectory f) - (copy-dir f out ignored-files) - (io/copy f out)))))) - -(defn copy-resources [{:keys [blog-prefix resources ignored-files]}] - (doseq [resource resources] - (let [src (str "resources/templates/" resource) - target (new-io/path public blog-prefix (fs/base-name resource))] - (cond - (not (.exists (io/file src))) - (throw (IllegalArgumentException. (str "resource " src " not found"))) - (.isDirectory (io/file src)) - (copy-dir src target ignored-files) - :else - (fs/copy src target))))) diff --git a/src/cryogen_core/new_io.clj b/src/cryogen_core/new_io.clj index 15b131b..47df569 100644 --- a/src/cryogen_core/new_io.clj +++ b/src/cryogen_core/new_io.clj @@ -9,7 +9,8 @@ (ns cryogen-core.new-io (:require [clojure.string :as st] [clojure.java.io :as io] - [cryogen-core.classpath-able-io :as cp-io])) + [cryogen-core.classpath-able-io :as cp-io] + [me.raynes.fs :as fs])) (def delete-resources! cp-io/delete-resources!) @@ -76,4 +77,70 @@ if no, return empty vector." filter-ext (fn [xs] (filter #(= (get-file-extension-from-resource %) ext) xs))] (->> assets filter-file - filter-ext))) \ No newline at end of file + filter-ext))) + +; +; +; taken from io.clj + +(defn re-filter [bool-fn re & other-res] + (let [res (conj other-res re)] + (reify java.io.FilenameFilter + (accept [this _ name] + (bool-fn (some #(re-find % name) res)))))) + +(def match-re-filter (partial re-filter some?)) +(def reject-re-filter (partial re-filter nil?)) + +(defn copy-dir [src target ignored-files] + (fs/mkdirs target) + (let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files) + files (.listFiles (io/file src) filename-filter)] + (doseq [^java.io.File f files] + (let [out (io/file target (.getName f))] + (if (.isDirectory f) + (copy-dir f out ignored-files) + (io/copy f out)))))) + +(defn create-folder [folder] + (let [loc (io/file (path public folder))] + (when-not (.exists loc) + (.mkdirs loc)))) + +(defn create-file [file data] + (spit (path public file) data)) + +(defn create-file-recursive [file data] + (create-folder (.getParent (io/file file))) + (create-file file data)) + +(defn copy-dir [src target ignored-files] + (fs/mkdirs target) + (let [^java.io.FilenameFilter filename-filter (apply reject-re-filter ignored-files) + files (.listFiles (io/file src) filename-filter)] + (doseq [^java.io.File f files] + (let [out (io/file target (.getName f))] + (if (.isDirectory f) + (copy-dir f out ignored-files) + (io/copy f out)))))) + +(defn copy-resources [{:keys [blog-prefix resources ignored-files]}] + (doseq [resource resources] + (let [src (str "resources/templates/" resource) + target (path public blog-prefix (fs/base-name resource))] + (cond + (not (.exists (io/file src))) + (throw (IllegalArgumentException. (str "resource " src " not found"))) + (.isDirectory (io/file src)) + (copy-dir src target ignored-files) + :else + (fs/copy src target))))) + +(defn ignore [ignored-files] + (fn [^java.io.File file] + (let [name (.getName file) + matches (map #(re-find % name) ignored-files)] + (not (some seq matches))))) + +(defn get-resource [resource] + (-> resource io/resource io/file)) \ No newline at end of file diff --git a/src/cryogen_core/rss.clj b/src/cryogen_core/rss.clj index 44e74de..5ffb9e7 100644 --- a/src/cryogen_core/rss.clj +++ b/src/cryogen_core/rss.clj @@ -1,8 +1,7 @@ (ns cryogen-core.rss (:require [clj-rss.core :as rss] [cryogen-core.new-io :as new-io] - [text-decoration.core :refer :all] - [cryogen-core.io :as cryogen-io]) + [text-decoration.core :refer :all]) (:import java.util.Date)) (defn posts-to-items [^String site-url posts] @@ -33,4 +32,4 @@ (doseq [filter rss-filters] (let [uri (new-io/path "/" blog-prefix (str (name filter) ".xml"))] (println "\t-->" (cyan uri)) - (cryogen-io/create-file uri (make-channel config (get posts-by-tag filter)))))) + (new-io/create-file uri (make-channel config (get posts-by-tag filter)))))) diff --git a/src/cryogen_core/sass.clj b/src/cryogen_core/sass.clj index b164081..c5758f1 100644 --- a/src/cryogen_core/sass.clj +++ b/src/cryogen_core/sass.clj @@ -2,7 +2,7 @@ (:require [clojure.java.io :as io] [clojure.java.shell :as shell] [text-decoration.core :refer :all] - [cryogen-core.io :as cryogen-io])) + [cryogen-core.new-io :as new-io])) (defmacro sh [& args] @@ -26,10 +26,10 @@ "Given a Diretory, gets files, Filtered to those having scss or sass extention. Ignores files matching any ignored regexps." [base-dir dir ignored-files] - (let [^java.io.FilenameFilter filename-filter (cryogen-io/match-re-filter #"(?i:s[ca]ss$)")] + (let [^java.io.FilenameFilter filename-filter (new-io/match-re-filter #"(?i:s[ca]ss$)")] (->> (.listFiles (io/file base-dir dir) filename-filter) (filter #(not (.isDirectory ^java.io.File %))) - (filter (cryogen-io/ignore ignored-files)) + (filter (new-io/ignore ignored-files)) (map #(.getName ^java.io.File %))))) (defn compile-sass-file! diff --git a/src/cryogen_core/sitemap.clj b/src/cryogen_core/sitemap.clj index fca39cf..75a2868 100644 --- a/src/cryogen_core/sitemap.clj +++ b/src/cryogen_core/sitemap.clj @@ -1,6 +1,5 @@ (ns cryogen-core.sitemap (:require [clojure.xml :refer [emit]] - [cryogen-core.io :as cryogen-io] [cryogen-core.new-io :as new-io]) (:import java.util.Date)) diff --git a/src/cryogen_core/watcher.clj b/src/cryogen_core/watcher.clj index 5f0a5ae..3afce2c 100644 --- a/src/cryogen_core/watcher.clj +++ b/src/cryogen_core/watcher.clj @@ -3,14 +3,14 @@ [clojure.set :as set] [hawk.core :as hawk] [pandect.algo.md5 :as md5] - [cryogen-core.io :as cryogen-io])) + [cryogen-core.new-io :as new-io])) (defn get-assets [path ignored-files] (->> path io/file file-seq (filter #(not (.isDirectory ^java.io.File %))) - (filter (cryogen-io/ignore ignored-files)))) + (filter (new-io/ignore ignored-files)))) (defn checksums [path ignored-files] (let [files (get-assets path ignored-files)]