Fix docstrings in core.clj
This commit is contained in:
parent
8daae7ae22
commit
6ef987639d
|
@ -10,20 +10,22 @@
|
||||||
|
|
||||||
;; Thank you https://clojure.org/api/cheatsheet
|
;; Thank you https://clojure.org/api/cheatsheet
|
||||||
; Generate a keyword-string map of the templates folder
|
; Generate a keyword-string map of the templates folder
|
||||||
(defn generate-template-map [template-dir]
|
(defn generate-template-map
|
||||||
"Grab all files in the template directory and insert them into a map with
|
"Grab all files in the template directory and insert them into a map with
|
||||||
the filenames as keyword keys"
|
the filenames as keyword keys"
|
||||||
|
[template-dir]
|
||||||
(let [files (filter #(.isFile %) (file-seq (io/file template-dir)))]
|
(let [files (filter #(.isFile %) (file-seq (io/file template-dir)))]
|
||||||
(reduce #(assoc %1 (keyword (.getName %2)) (slurp %2)) {} files)))
|
(reduce #(assoc %1 (keyword (.getName %2)) (slurp %2)) {} files)))
|
||||||
|
|
||||||
; Generate a string-string map of the new filepaths and the unprocessed contents
|
; Generate a string-string map of the new filepaths and the unprocessed contents
|
||||||
(defn generate-output-file-map [html-dir, output-dir]
|
(defn generate-output-file-map
|
||||||
"Take the input html files, read them, and create a mapping of their paths to
|
"Take the input html files, read them, and create a mapping of their paths to
|
||||||
their contents.
|
their contents.
|
||||||
|
|
||||||
This would probably be better as a list of maps each containing a :contents
|
This would probably be better as a list of maps each containing a :contents
|
||||||
and :path keyword.
|
and :path keyword.
|
||||||
"
|
"
|
||||||
|
[html-dir, output-dir]
|
||||||
(let [file-listing (filter #(.isFile %) (file-seq (io/file html-dir)))
|
(let [file-listing (filter #(.isFile %) (file-seq (io/file html-dir)))
|
||||||
contents (map slurp file-listing)
|
contents (map slurp file-listing)
|
||||||
old-paths (map #(.getPath %) file-listing)
|
old-paths (map #(.getPath %) file-listing)
|
||||||
|
@ -31,18 +33,19 @@ the filenames as keyword keys"
|
||||||
new-paths (map #(string/join [output-dir %]) rootless-paths)]
|
new-paths (map #(string/join [output-dir %]) rootless-paths)]
|
||||||
(zipmap new-paths contents)))
|
(zipmap new-paths contents)))
|
||||||
|
|
||||||
(defn put_file [file_map_entry]
|
(defn put_file
|
||||||
"Output a file to a location while ensuring the required parent directories exist."
|
"Output a file to a location while ensuring the required parent directories exist."
|
||||||
|
[file_map_entry]
|
||||||
(io/make-parents (first file_map_entry))
|
(io/make-parents (first file_map_entry))
|
||||||
(spit (first file_map_entry) (second file_map_entry)))
|
(spit (first file_map_entry) (second file_map_entry)))
|
||||||
|
|
||||||
(defn insert_templates [file-map-entry template-map]
|
(defn insert_templates
|
||||||
; Will go through and check all the template names in the file then
|
"Go through and check all the template names in the file then
|
||||||
; mark which templates exist and which dont
|
mark which templates exist and which dont
|
||||||
;
|
|
||||||
; Using this we can report an error for any templates which do not exist
|
Using this we can report an error for any templates which do not exist"
|
||||||
(let [template-names (map first template-map)
|
[file-map-entry template-map]
|
||||||
file (first file-map-entry)
|
(let [file (first file-map-entry)
|
||||||
contents (second file-map-entry)
|
contents (second file-map-entry)
|
||||||
templates-used (re-seq template-reg contents)
|
templates-used (re-seq template-reg contents)
|
||||||
new-contents (reduce #(string/replace %1 (first %2) ((keyword (second %2)) template-map)) contents templates-used)]
|
new-contents (reduce #(string/replace %1 (first %2) ((keyword (second %2)) template-map)) contents templates-used)]
|
||||||
|
@ -51,6 +54,7 @@ the filenames as keyword keys"
|
||||||
; Main routine
|
; Main routine
|
||||||
; Read all the templates
|
; Read all the templates
|
||||||
(def template-map (generate-template-map template-dir))
|
(def template-map (generate-template-map template-dir))
|
||||||
|
|
||||||
; Read all the html files
|
; Read all the html files
|
||||||
(def output-file-map (generate-output-file-map html-dir output-dir))
|
(def output-file-map (generate-output-file-map html-dir output-dir))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue