fotoetienne / cljstache

{{ mustache }} templates for Clojure[Script].
GNU Lesser General Public License v3.0
70 stars 17 forks source link

Lambdas for cljs #14

Open shen-tian opened 4 years ago

shen-tian commented 4 years ago

The readme says this only works in JVM, which I take to mean Clojure only. But based on some experiments, it seem to work fine for ClojureScript too:

(let [d {:text "hello"}]
    (render "Text is {{#uppercase}}{{ text }}{{/uppercase}} {{lambda}}"
            (merge d
                   {:uppercase (fn [x] (str/upper-case (mustache/render x d)))
                    :lambda (fn [] "from inside lambda!!")})))
;; => "Text is HELLO from inside lambda!!"

Is there some limitations I should be aware of? of is the doc just out of date?

fotoetienne commented 4 years ago

It probably works. I just wasn't able to get the lambda spec tests to pass due to missing load-string in cljs https://github.com/fotoetienne/cljstache/blob/1a2f6c049967f8f4f97c3f732324e6e783b61468/test/cljstache/mustache_spec_test.cljc#L84

fotoetienne commented 4 years ago

Kudos to anyone who can get the lambda tests working in cljs!