Skip to content

Commit

Permalink
Add docs for diff-text
Browse files Browse the repository at this point in the history
  • Loading branch information
djblue committed Aug 28, 2024
1 parent e2509d3 commit 85167a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions dev/tasks/docs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
::v/diff
{:file "portal/ui/viewer/diff.cljs"
:examples [(vary-meta d/diff-data dissoc ::v/default)]}
::v/diff-text
{:file "portal/ui/viewer/diff_text.cljs"
:examples [d/diff-text-data]}
::v/tree
{:examples [(vary-meta d/hiccup dissoc ::v/default)]}
::v/code
Expand Down
1 change: 1 addition & 0 deletions resources/viewers.edn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
{:name :portal.viewer/diff,
:doc
"Diff a collection of values successively starting with the first two."}
{:name :portal.viewer/diff-text, :doc "Diff two strings."}
{:name :portal.viewer/markdown,
:doc "Parse string as markdown and view as html."}
{:name :portal.viewer/hiccup,
Expand Down
15 changes: 9 additions & 6 deletions src/portal/ui/viewer/diff_text.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns portal.ui.viewer.diff-text
(:require ["diff" :as df]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[portal.colors :as c]
[portal.ui.icons :as icons]
Expand All @@ -8,6 +9,13 @@
[portal.ui.styled :as d]
[portal.ui.theme :as theme]))

;;; :spec
(s/def ::diff-text (s/cat :a string? :b string?))
;;;

(defn- diff-text? [value]
(s/valid? ::diff-text value))

(defn- changed? [^js item]
(or (some-> item .-added)
(some-> item .-removed)))
Expand Down Expand Up @@ -106,13 +114,8 @@
:border-bottom-left-radius (:border-radius theme)
:border-bottom-right-radius (:border-radius theme)}}]]))

(defn- text-diff? [value]
(and (coll? value)
(string? (first value))
(string? (second value))))

(def viewer
{:predicate text-diff?
{:predicate diff-text?
:component inspect-text-diff
:name :portal.viewer/diff-text
:doc "Diff two strings."})

0 comments on commit 85167a0

Please sign in to comment.