comb icon indicating copy to clipboard operation
comb copied to clipboard

is this package ready to use?

Open kangaroolab opened this issue 1 year ago • 6 comments

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))))

kangaroolab avatar Oct 02 '24 17:10 kangaroolab

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"

weavejester avatar Oct 02 '24 22:10 weavejester

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

kangaroolab avatar Oct 03 '24 02:10 kangaroolab

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

weavejester avatar Oct 03 '24 04:10 weavejester

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

kangaroolab avatar Oct 04 '24 03:10 kangaroolab

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

weavejester avatar Oct 04 '24 04:10 weavejester

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.

borkdude avatar Oct 08 '24 14:10 borkdude