weavejester / comb

Clojure templating library
67 stars 5 forks source link

is this package ready to use? #6

Open kangaroolab opened 1 month ago

kangaroolab commented 1 month ago

looking at functions below, they don't refer/call other functions like parse-string/emit-expr etc...when I just run the example in readme, it simply return nil...please advise.

(defn compile-fn [args src] (core/eval `(core/fn ~args (with-out-str ~(-> src read-source parse-string read-string)))))

(defmacro fn "Compile a template into a function that takes the supplied arguments. The template source may be a string, or an I/O source such as a File, Reader or InputStream." [args source] `(compile-fn '~args ~source))

(defn eval "Evaluate a template using the supplied bindings. The template source may be a string, or an I/O source such as a File, Reader or InputStream." ([source] (eval source {})) ([source bindings] (let [keys (map (comp symbol name) (keys bindings)) func (compile-fn [{:keys (vec keys)}] source)] (func bindings))))

weavejester commented 1 month ago

Yes, this package works as far as I'm aware. A week ago someone was telling me that they used this library recently.

Which example in particular is failing for you? I just tried the first example with the latest Clojure version and it works as expected:

$ clj
Downloading: comb/comb/0.1.1/comb-0.1.1.pom from clojars
Downloading: comb/comb/0.1.1/comb-0.1.1.jar from clojars
Clojure 1.12.0
user=> (require '[comb.template :as template])
nil
user=> (template/eval "<% (dotimes [x 3] %>foo<% ) %>")
"foofoofoo"
kangaroolab commented 1 month ago

I tried to debug by running following (I changed parse-string to defn from defn-):

(template/parse-string "<% (dotimes [x 3] %>foo<% ) %>")

and it return nil

btw I am running it with scittle in browser

weavejester commented 1 month ago

Because Comb uses macros and eval, it may not work with SCI. Comb has only been tested with Clojure on the JVM.

kangaroolab commented 4 weeks ago

thanks...how is this different from Clojure.template?

weavejester commented 4 weeks ago

As far as I can tell, clojure.template generates Clojure expressions. Comb generates strings of text.

borkdude commented 3 weeks ago

Btw, comb works perfectly fine as a library in babashka and powers the https://babashka.org/toolbox/, which is a fork of the Clojure Toolbox which also is generated using comb. Scittle is a different story probably.

The comb library not working in scittle has more to do with the fact that this library was written for the JVM rather than JS.