From b8cf100209309e275da42a92093d6d0b1f0c4571 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 23 Jan 2021 14:21:54 +0100 Subject: [PATCH] [#646] hiccup --- deps.edn | 3 ++- feature-hiccup/babashka/impl/hiccup.clj | 21 +++++++++++++++++++++ project.clj | 4 +++- script/compile | 1 + script/uberjar | 7 +++++++ src/babashka/impl/features.clj | 1 + src/babashka/main.clj | 14 +++++++++++--- 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 feature-hiccup/babashka/impl/hiccup.clj diff --git a/deps.edn b/deps.edn index c3cba45b..46b6ae04 100644 --- a/deps.edn +++ b/deps.edn @@ -28,7 +28,8 @@ http-kit/http-kit {:mvn/version "2.5.0"} babashka/clojure-lanterna {:mvn/version "0.9.8-SNAPSHOT"} org.clojure/math.combinatorics {:mvn/version "0.1.6"} - org.clojure/core.match {:mvn/version "1.0.0"}} + org.clojure/core.match {:mvn/version "1.0.0"} + hiccup/hiccup {:mvn/version "2.0.0-alpha2"}} :aliases {:main {:main-opts ["-m" "babashka.main"]} :profile diff --git a/feature-hiccup/babashka/impl/hiccup.clj b/feature-hiccup/babashka/impl/hiccup.clj new file mode 100644 index 00000000..db119f84 --- /dev/null +++ b/feature-hiccup/babashka/impl/hiccup.clj @@ -0,0 +1,21 @@ +(ns babashka.impl.hiccup + {:no-doc true} + (:require [hiccup.core :as hiccup] + [hiccup.util :as util] + [hiccup2.core :as hiccup2] + [sci.core :as sci :refer [copy-var]])) + +(def hns (sci/create-ns 'hiccup.core nil)) +(def hns2 (sci/create-ns 'hiccup2.core nil)) +(def uns (sci/create-ns 'hiccup.util nil)) + +(def hiccup-namespace + {'html (copy-var hiccup/html hns)}) + +(def hiccup2-namespace + {'html (copy-var hiccup2/html hns2)}) + +(def hiccup-util-namespace + {'*html-mode* (copy-var util/*html-mode* uns) + '*escape-strings?* (copy-var util/*escape-strings?* uns) + 'raw-string (copy-var util/raw-string uns)}) diff --git a/project.clj b/project.clj index 29b51276..bffcb55a 100644 --- a/project.clj +++ b/project.clj @@ -48,7 +48,8 @@ :dependencies [[babashka/clojure-lanterna "0.9.8-SNAPSHOT"]]} :feature/core-match {:source-paths ["feature-core-match"] :dependencies [[org.clojure/core.match "1.0.0"]]} - + :feature/hiccup {:source-paths ["feature-hiccup"] + :dependencies [[hiccup/hiccup "2.0.0-alpha2"]]} :test [:feature/xml :feature/lanterna :feature/yaml @@ -61,6 +62,7 @@ :feature/httpkit-client :feature/httpkit-server :feature/core-match + :feature/hiccup {:dependencies [[clj-commons/conch "0.9.2"] [com.clojure-goes-fast/clj-async-profiler "0.4.1"] [com.opentable.components/otj-pg-embedded "0.13.3"]]}] diff --git a/script/compile b/script/compile index dffa18dd..6a594250 100755 --- a/script/compile +++ b/script/compile @@ -95,6 +95,7 @@ then export BABASHKA_FEATURE_HTTPKIT_CLIENT="${BABASHKA_FEATURE_HTTPKIT_CLIENT:-false}" export BABASHKA_FEATURE_HTTPKIT_SERVER="${BABASHKA_FEATURE_HTTPKIT_SERVER:-false}" export BABASHKA_FEATURE_CORE_MATCH="${BABASHKA_FEATURE_CORE_MATCH:-false}" + export BABASHKA_FEATURE_HICCUP="${BABASHKA_FEATURE_HICCUP:-false}" fi "$GRAALVM_HOME/bin/native-image" "${args[@]}" diff --git a/script/uberjar b/script/uberjar index bba50055..afe654e4 100755 --- a/script/uberjar +++ b/script/uberjar @@ -125,6 +125,13 @@ else BABASHKA_LEIN_PROFILES+=",-feature/core-match" fi +if [ "$BABASHKA_FEATURE_HICCUP" != "false" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/hiccup" +else + BABASHKA_LEIN_PROFILES+=",-feature/hiccup" +fi + if [ -z "$BABASHKA_JAR" ]; then lein with-profiles "$BABASHKA_LEIN_PROFILES,+reflection,-uberjar" do run lein with-profiles "$BABASHKA_LEIN_PROFILES" do clean, uberjar diff --git a/src/babashka/impl/features.clj b/src/babashka/impl/features.clj index c2a4e671..dbf6fa62 100644 --- a/src/babashka/impl/features.clj +++ b/src/babashka/impl/features.clj @@ -12,6 +12,7 @@ (def httpkit-client? (not= "false" (System/getenv "BABASHKA_FEATURE_HTTPKIT_CLIENT"))) (def httpkit-server? (not= "false" (System/getenv "BABASHKA_FEATURE_HTTPKIT_SERVER"))) (def core-match? (not= "false" (System/getenv "BABASHKA_FEATURE_CORE_MATCH"))) +(def hiccup? (not= "false" (System/getenv "BABASHKA_FEATURE_HICCUP"))) ;; excluded by default (def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC"))) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 186b7c30..14dd3c55 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -97,6 +97,9 @@ (when features/core-match? (require '[babashka.impl.match])) +(when features/hiccup? + (require '[babashka.impl.hiccup])) + (sci/alter-var-root sci/in (constantly *in*)) (sci/alter-var-root sci/out (constantly *out*)) (sci/alter-var-root sci/err (constantly *err*)) @@ -303,7 +306,8 @@ Use -- to separate script command line args from bb command line args. :feature/oracledb %s :feature/httpkit-client %s :feature/lanterna %s - :feature/core-match %s}") + :feature/core-match %s + :feature/hiccup %s}") version features/core-async? features/csv? @@ -317,7 +321,8 @@ Use -- to separate script command line args from bb command line args. features/oracledb? features/httpkit-client? features/lanterna? - features/core-match?))) + features/core-match? + features/hiccup?))) (defn read-file [file] (let [f (io/file file)] @@ -427,7 +432,10 @@ Use -- to separate script command line args from bb command line args. features/lanterna? (assoc 'lanterna.screen @(resolve 'babashka.impl.lanterna/lanterna-screen-namespace) 'lanterna.terminal @(resolve 'babashka.impl.lanterna/lanterna-terminal-namespace) 'lanterna.constants @(resolve 'babashka.impl.lanterna/lanterna-constants-namespace)) - features/core-match? (assoc 'clojure.core.match @(resolve 'babashka.impl.match/core-match-namespace)))) + features/core-match? (assoc 'clojure.core.match @(resolve 'babashka.impl.match/core-match-namespace)) + features/hiccup? (-> (assoc 'hiccup.core @(resolve 'babashka.impl.hiccup/hiccup-namespace)) + (assoc 'hiccup2.core @(resolve 'babashka.impl.hiccup/hiccup2-namespace)) + (assoc 'hiccup.util @(resolve 'babashka.impl.hiccup/hiccup-util-namespace))))) (def imports '{ArithmeticException java.lang.ArithmeticException