Take script fragments from resources in the jar

This commit is contained in:
Simon Brooke 2018-07-19 21:46:59 +01:00
parent f62d08e5e7
commit 577f4eb1b8
3 changed files with 21 additions and 20 deletions

View file

@ -12,4 +12,14 @@
[hiccup "1.0.5"]] [hiccup "1.0.5"]]
:aot [adl.main] :aot [adl.main]
:main adl.main :main adl.main
:plugins [[lein-codox "0.10.3"]]) :plugins [[lein-codox "0.10.3"]
[lein-release "1.0.5"]]
:release-tasks [["vcs" "assert-committed"]
["change" "version" "leiningen.release/bump-version" "release"]
["vcs" "commit"]
;; ["vcs" "tag"] -- not working, problems with secret key
["clean"]
["uberjar"]
["change" "version" "leiningen.release/bump-version"]
["vcs" "commit"]])

View file

@ -3,7 +3,7 @@
adl.to-selmer-templates adl.to-selmer-templates
(:require [adl.to-hugsql-queries :refer [expanded-token]] (:require [adl.to-hugsql-queries :refer [expanded-token]]
[adl-support.utils :refer :all] [adl-support.utils :refer :all]
[clojure.java.io :refer [file make-parents]] [clojure.java.io :refer [file make-parents resource]]
[clojure.pprint :as p] [clojure.pprint :as p]
[clojure.string :as s] [clojure.string :as s]
[clojure.xml :as x] [clojure.xml :as x]
@ -423,11 +423,11 @@
(defn embed-script-fragment (defn embed-script-fragment
"Return the content of the file at `filepath`, with these `substitutions` "Return the content of the file at `resource-path`, with these `substitutions`
made into it in order. Substitutions should be pairss [`pattern` `value`], made into it in order. Substitutions should be pairss [`pattern` `value`],
where `pattern` is a string, a char, or a regular expression." where `pattern` is a string, a char, or a regular expression."
([filepath substitutions] ([resource-path substitutions]
(let [v (slurp filepath)] (let [v (slurp (resource resource-path))]
(reduce (reduce
(fn [s [pattern value]] (fn [s [pattern value]]
(if (and pattern value) (if (and pattern value)
@ -435,8 +435,8 @@
s)) s))
v v
substitutions))) substitutions)))
([filepath] ([resource-path]
(embed-script-fragment filepath []))) (embed-script-fragment resource-path [])))
(defn edit-link (defn edit-link
@ -622,7 +622,7 @@
(if (if
(> magnitude 2) (> magnitude 2)
(embed-script-fragment (embed-script-fragment
"resources/js/selectize-one.js" "js/selectize-one.js"
[["{{widget_id}}" (-> property :attrs :name)] [["{{widget_id}}" (-> property :attrs :name)]
["{{widget_value}}" (str "{{record." (-> property :attrs :name) "}}")] ["{{widget_value}}" (str "{{record." (-> property :attrs :name) "}}")]
["{{entity}}" farname] ["{{entity}}" farname]
@ -635,7 +635,7 @@
(child-with-tag (child-with-tag
form :field form :field
#(= "text-area" (widget-type (property-for-field % entity) application))) #(= "text-area" (widget-type (property-for-field % entity) application)))
(embed-script-fragment "resources/js/text-area-md-support.js" (embed-script-fragment "js/text-area-md-support.js"
[["{{page}}" (-> form :attrs :name)]]))))))}}) [["{{page}}" (-> form :attrs :name)]]))))))}})
@ -899,6 +899,7 @@
template template
(try (try
(do (do
(make-parents filepath)
(spit (spit
filepath filepath
(s/join (s/join
@ -967,6 +968,7 @@
(str (str
"ERROR: Exception " "ERROR: Exception "
(.getName (.getClass any)) (.getName (.getClass any))
" "
(.getMessage any) (.getMessage any)
" while writing " " while writing "
filename)))))) filename))))))

View file

@ -69,17 +69,6 @@
(remove :tag (remove nil? (map first (map (remove :tag (remove nil? (map first (map
#(try-validate ~o '%) #(try-validate ~o '%)
~validations)))))) ~validations))))))
;; ]
;; ;; if *any* succeeded, we succeeded
;; ;; otherwise, one of these is the valid error - but which? The answer, in my case
;; ;; is that if there is any which did not fail on the :tag check, then that is the
;; ;; interesting one. But generally?
;; (try
;; (doall (map #(println (str "ERROR: " %)) suspicious))
;; (empty? suspicious)
;; (catch Exception _ (println "ERROR while trying to print errors")
;; true))))
;;; the remainder of this file is a fairly straight translation of the ADL 1.4 DTD into Clojure ;;; the remainder of this file is a fairly straight translation of the ADL 1.4 DTD into Clojure