To use Portal without any particular runtime, try the standalone version of Portal. It can be installed as a chrome pwa which will provide a dock launcher for easy access.
To quickly paste some edn, json or transit into Portal, try the ctrl | cmd + v
paste command. Upon pasting portal will prompt for the format type in order to
parse the data.
If the data you want to view in Portal is in a file, it can be easily dragged and dropped over the UI.
To open the UI with pre-loaded data, you can pass the content-url
and
content-type
via query params. For example
this link pulls some edn data via a GitHub Gist with the content-type=application/edn
, this can be very handy to share data.
The supported content-types:
application/edn
application/json
application/transit+json
text/plain
If you want to automate the sharing of data from your runtime, you can create a Portal command that automatically uploads and generates a similar link as above. One such command could look like:
(ns portal.share
(:require [clojure.pprint :as pp]
[clojure.string :as str]
[org.httpkit.client :as http]
[portal.api :as p]
[portal.runtime.json :as json]))
(defn- pprint [value]
(binding [*print-meta* true]
(with-out-str (pp/pprint value))))
(defn- create-gist [content]
(-> @(http/post
"https://api.github.com/gists"
{:basic-auth [(System/getenv "GIT_USERNAME")
(System/getenv "GIT_PASSWORD")]
:headers {"Accept" "application/vnd.github.v3+json"}
:body (json/write
{:public false
:description "Portal Share"
:files {"data.clj" {:content content}}})})
:body
json/read
(get-in [:files :data.clj :raw_url])))
(defn- ->query-string [m]
(str/join "&" (for [[k v] m] (str (name k) "=" v))))
(defn- create-url [gist-raw-url]
(str "https://djblue.github.io/portal/?"
(->query-string {:content-url gist-raw-url
:content-type "application/edn"})))
(defn- shorten-url [url]
(-> @(http/post
"https://url.api.stdlib.com/temporary@0.3.0/create/"
{:headers {"Content-Type" "application/json"}
:body (json/write {:url url :ttl 86400})})
:body
json/read
:link_url))
(defn share
"Create a shareable portal link for the supplied value."
[value]
(-> value pprint create-gist create-url shorten-url))
(p/register! #'share)
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close