Fork me on GitHub
#portal
<
2023-10-13
>
markaddleman14:10:10

I’m sending a bunch of strings to portal that I’d like to be formatted as :portal.view/code by default. Of course, since they’re strings, I can’t attach metadata to them. Is there some metadata-capable container that I can put them in which will display as strings in portal?

djblue15:10:27

I think you might be looking for this guide https://cljdoc.org/d/djblue/portal/0.48.0/doc/guides/default-viewer. I'm planning on releasing an updated version of the https://github.com/djblue/portal/blob/master/src/portal/viewer.cljc#L14-L26 ns which contains this pattern so you don't have to think about it.

markaddleman15:10:13

Yeah, I saw this but it seemed like just a bit more work than I was wiling to put in just to save a few mouse clicks.

markaddleman15:10:24

I shouldn’t be this lazy 🙂 Thanks!

djblue15:10:40

What do you feel would be an easier approach?

markaddleman15:10:05

Something like this:

(portal.console/debug ^:portal.viewer/code (portal.console/metadata-container "my code string")

djblue15:10:39

That might cause issues with the current semantics of the viewer key which is to pass options to the viewer. For example:

{:portal.viewer/default :portal.viewer/table
 :portal.viewer/table {:columns [:a :b :c]}}

markaddleman15:10:09

Sorry, my example was bad. It should have been :

(portal.console/debug ^{:portal.viewer/default :portal.viewer/code} (portal.console/metadata-container "my code string")

markaddleman16:10:06

As you can see (I hope), I’m just looking for a container to which I can attach metadata. I’d like the portal viewer to visualize the value within the container

👍 1
seancorfield17:10:16

Could you put your strings in vectors and attach metadata to that? (I don't know what the code viewer would do with that tho')

markaddleman18:10:27

ah! that does it

markaddleman18:10:02

disregard - I got a little too excited

markaddleman18:10:19

Portal does not display the string in code format

markaddleman18:10:18

But it occurs to me I could stuff the string into some hiccup and put the metadata on the hiccup vector.

markaddleman18:10:48

fwiw, my specific use case is generating SQL strings from honey, prettifying them using a formatter, looking at them in portal and copy & pasting the string into my sql editor

markaddleman18:10:14

It’s a very nice workflow, although I wish I had a way of sending them directly to my sql editor (this has nothing to do with portal, however)