Fork me on GitHub
#clojure
<
2023-04-26
>
sergey.shvets05:04:26

Is there a way to send some javascript inside a hiccup tag? I want to utilize Google Chart to draw some charts, but I need to load some javascript that will call my server for data. Smth like that: https://developers.google.com/chart/interactive/docs/php_example I don't see a way to force hiccup to not escape javascript...

p-himik08:04:17

Why not just write that JS code in CLJS?

p-himik08:04:15

Adding <script> tags is not that easy with naked React either. It needs extra fiddling, and all that effort will be much more than simply rewriting those few JS lines from the linked page into CLJS.

p-himik09:04:08

Oh, I just realized that we're in #C03S1KBA2 so you're probably asking about the CLJ Hiccup and not the CLJS one as can be seen in e.g. Reagent? If so, then it shouldn't do any escaping, as far as I'm aware:

Clojure 1.12.0-alpha2
user=> (add-lib 'hiccup/hiccup)
Downloading: hiccup/hiccup/maven-metadata.xml from clojars
[hiccup/hiccup]
user=> (use 'hiccup.core)
nil
user=> (html [:script "var x = {a: 1};"])
"<script>var x = {a: 1};</script>"
user=> 
If the behavior that you see is different, can you share a code snippet?

sergey.shvets17:04:24

Thanks for the response! I'm using it from clojure and trying to send a specific graph code inside a specific page. Not sure where it breaks, but browser receives the tag and insides of the script are encoded. But I found a workaround with _dangerouslySetInnerHTML in rum and it works. And then even better, I got rid of the need to send javascript over by doing htmx extension. Now the backend just sends JSON data to that extension and it takes care of the proper javascript. Win-win.

wottis08:04:51

Greetings. I'm trying to use the profile-credentials-provider for the aws-api. But it fails to load any credentials and can't figure out why. It says to look at the logs. But i don't know where it's actually logging things to because i didn't configure anything related to that. Following the code i use to setup the provider and trying to use it:

(def dev-profile (profile-credentials-provider "a-profile-in-the-file" (file "~/.aws/config")))
(def dev-client (aws/client {:api :ec2 :credentials-provider dev-profile}))
(aws/invoke dev-client {:op :DescribeVpcs})
;; => #:cognitect.anomalies{:category :cognitect.anomalies/fault,
                      :message
                      "Unable to fetch credentials. See log for more details."}

wottis09:04:26

Example from ~/.aws/config:

[profile a-profile-in-the-file]
role_arn = arn:aws:iam::123456789:role/a-role
role_session_name = a-session-name
source_profile = a-source-profile
region = us-west-2

p-himik09:04:18

Don't use ~ in the path. Java's File (and consequently CLJ's io/file) does not expand it to the home directory, so you gotta provide the full path.

p-himik09:04:05

And the "see log" message is definitely misleading - judging by the code, nothing else is logged at all when the credentials file could not be found.

wottis10:04:44

I also tried with the full path. Cause i thought maybe it doesn't expand ~. But still the same issue.

p-himik10:04:59

If you call .exist on that file, does it return true?

p-himik10:04:41

If yes, then the most likely cause is the fact that you're using source_profile: https://github.com/cognitect-labs/aws-api/issues/172

p-himik10:04:13

Can work around that by incorporating the source profile into the target one.

p-himik10:04:35

Or read the profile manually and provide the credentials explicitly.

wottis10:04:35

Yeah looked into the provider code how it parses the file and the file format. And the file format is the issue.

wottis10:04:43

Thanks a lot for the help and the issue link.

👍 2
vemv18:04:39

Is there a simple technique/adapter for using Integrant components within a Component system?

vemv18:04:20

(Assume I can't directly edit a given Integrant component: framework stuff, 3rd party deps)

Joshua Suskalo21:04:01

That sounds like a challenge considering the two have different default assumptions about how you are going to work with them. What's the exact kind of case you'd want to adapt?

Joshua Suskalo21:04:33

If the Component protocols have :extend-via-metadata set to true then it might not be that hard though.

vemv03:04:20

> What's the exact kind of case you'd want to adapt? Simply being able to leverage as many Integrant things as possible from an Integrant-based web framework, while refactoring the project from using Integrant to Component

emccue13:04:35

Well, you can always just take the start/stop methods

emccue13:04:17

Like, look up the implementation registered for a given key, then make something which delegates to those impls for it's component start/stop methods

vemv15:04:56

Thanks, yes I guess that for a specific work scenario, I can simply look at the source of each thing and create a hopefully-simple delegator. Eventually one would be able to phase out that code from ~12 to 0 'adapted' code paths. Although I was interested in a generalized technique - maybe someone hacked it at some point :)

igrishaev16:04:04

I may guess you can write a component that, when started or stopped, calls the corresponding multi-methods from Integrant. Something like

(start [this]
  (assoc this :state (integrant/init-key! :foo/bar options)))e