Fork me on GitHub
#biff
<
2023-11-16
>
Lyn Headley12:11:22

generic object browser.

(ns org.stinkless.rekonstruction.browser
  (:require [com.biffweb :as biff]
            [org.stinkless.rekonstruction.middleware :as mid]))

(defn render-value [valu]
  (if (uuid? valu)
    [:a {:href (format "/browser/thing/%s" valu)}
     "visit"]
    [:span (format "%s" valu)]))

(defn- render-thing
  [thing]
  [:table
     (for [[k v] thing]
       [:tr [:td (str k)] [:td (render-value v)]])])

(defn- browser-handler [{:keys [biff/db] :as ctx}]
  (let [things (biff/q db '{:find [when (pull thing [*])]
                            :order-by [[when :desc]]
                            :where [[thing :rekon/when when]]})]
    (for [[_when thing] things]
      (render-thing thing))))

(defn- get-thing-handler [{:keys [path-params biff/db]}]
  (let [thing (biff/lookup db :xt/id (parse-uuid (:thing-id path-params)))]
    (render-thing thing)))

(def plugin
  {:routes ["/browser" {:middleware [mid/wrap-signed-in]}
            ["" {:get browser-handler}]
            ["/thing/:thing-id" {:get get-thing-handler}]]})

🆒 3
👀 1
dobladez16:11:54

Hey, new to biff here. I like what I see so far 👏 thanks @foo

dobladez16:11:51

First question: Could the use-beholder component read its on-save callback(s) from a plugin key? Any reason against that?

Jacob O'Bryant16:11:13

welcome! Do you have a use-case in mind? e.g. are you wanting to add on-save functionality from a third party plugin? I think it makes a little more sense to just set the :biff.beholder/on-save key on the system map since you (typically?) don't need add a bunch of different implementations--since it's tooling-related and not application-related, it doesn't need to accumulate more functionality as you add more features to your app. even schema used to not be added via plugins, but then I made that supported so that the authentication plugin could define some of its own schema. that being said: you can pretty easily add support for on-save-in-plugins yourself. Just modify the default on-save function so that it iterate through the plugins and calls any functions it finds under the e.g. :on-save key (as a best practice, might want to namespace it, like :com.example/on-save)

dobladez17:11:49

my immediate use-case: I was just re-arranging the code from the template. I like to separate the "application core" code from the "UI" and "infrastructure" (say, DB, email) code. So, I while moving all "web" related code to a separate namespace, I wanted to move generate-assets! out of the <projectname>.clj file, but it's used by on-save ... thus, I thought it'd be cleaner if :on-save was a plugin hook that the "web" plug-in could hook into.... instead of having a top-level on-save function that "knows" about the "web" plugin. Of course other plugins could use it (say, test frameworks/tooling/monitoring incoming folders, etc)

👍 1
Curious Yogurt17:11:24

Hi all. I'm still working on deploying the tutorial. I think I have the server set up, but I'm having a problem with rsync. When I run bb deploy, the app builds, but then I get the following error: bash: line 1: rsync: command not found rsync: connection unexpectedly closed (0 bytes received so far) [sender] I think this has something to do with biff/tasks/src/com/biffweb/tasks.clj, lines 309-327 (push-files-rsync) — but I'm not entirely sure. What's puzzling to me is that the first message seems to be from bash, which says rsync command not found; but then the second line is from rsync — so it seems that rsync is found by that point. In my shell, "which rsync" returns /usr/bin/rsync — which I assume is what (fs/which "rsync") on line 343 is returning. Any suggestions as to how to resolve this would be greatly appreciated.

dobladez17:11:50

I know nothing about biff's rsync imp, but I do know the rsync command, to work, must be installed in both client and server... Maybe you are missing it on the server side?

Curious Yogurt17:11:10

Ah you know, that at least got me past that error—it wasn't deployed on the other side. Once it is, the rsync error goes away.

🙌 1
Lyn Headley19:11:43

you also need curl

Curious Yogurt20:11:16

Thanks all—with your help, I actually got it serving a website. There are still some teething problems that I need to work on—logs are not working, and it's deploying with git even though rsync is available. But it is at least serving pages!

🎉 1