Fork me on GitHub
#clojurescript
<
2018-10-08
>
mavbozo04:10:59

I want to use goog.html.SafeHtml class https://google.github.io/closure-library/api/goog.html.SafeHtml.html and calls its static function SafeHtml.htmlEscape. I tried using (:import (goog.html SafeHtml)) then calling the static function (SafeHtml/htmlEscape "foo") but the compiler throws No such namespace: goog.html.SafeHtml, could not locate goog/html/SafeHtml.cljs, goog/html/SafeHtml.cljc, or JavaScript source providing "goog.html.SafeHtml"

mavbozo04:10:38

how do I import goog.html.SafeHtml class in my clojurescript code?

christos06:10:39

(:import [goog.html SafeHtml]) should work

christos06:10:31

@mavbozo as should (:require [goog.html.Safehtml :as gshtml]

christos06:10:20

then you can either SafeHtml/htmlEscape or gshtml/htmlEscape

christos06:10:28

what version of cljs do you use ?

mavbozo06:10:45

@hee-foo i'm using [org.clojure/clojurescript "1.10.339"]. it doesn't work when using :import

mavbozo06:10:22

but it works when I use (:require [goog.html.SafeHtml :as SafeHtml])

christos06:10:54

@mavbozo I suspected as much. I have encountered something similar a while ago, i remember i figured why this is happening, but forgot about that. Avoid using names that begin with capital

christos06:10:39

@mavbozo safe-html instead SafeHtml is considered better practice

christos06:10:00

when requiring at least

khardenstine21:10:15

when targeting nodejs, is there a way to have cljs include the node_modules from npm-deps in the build?

lloydshark09:10:44

I'm not aware of it. I target nodejs for lambda. To package the node_modules I use a bash script.

khardenstine15:10:47

Thanks, Ive resorted to just copying my node_modules manually via script too.

lloydshark21:10:48

Actually and I realise that I swapped a while ago to resolve node modules via npm directly rather than lein-npm so the above is not what you asked for.