Back
fmt (clj)
(source)variable
A shorter alias to `format` function.
Examples
penpot/penpot
#_:clj-kondo/ignore
(ns app.common.data.macros
"Data retrieval & manipulation specific macros."
(:refer-clojure :exclude [get-in select-keys str with-open min max])
#?(:cljs (:require-macros [app.common.data.macros]))
(:require
#?(:clj [clojure.core :as c]
:cljs [cljs.core :as c])
[app.common.data :as d]
[cljs.analyzer.api :as aapi]
[cuerdas.core :as str]))
(defmacro fmt
"String interpolation helper. Can only be used with strings known at
compile time. Can be used with indexed params access or sequential.
(dm/fmt \"url(%)\" my-url) ; sequential
(dm/fmt \"url(%1)\" my-url) ; indexed
"
[s & params]
`(str/ffmt ~s ~@params))
(defmacro assert!
([expr]
`(assert! nil ~expr))
([hint expr]
(let [hint (cond
(vector? hint)
`(str/ffmt ~@hint)
(defmacro verify!
([expr]
`(verify! nil ~expr))
([hint expr]
(let [hint (cond
(vector? hint)
`(str/ffmt ~@hint)
penpot/penpot
(ns app.main.ui.components.numeric-input
(:require
[app.common.data :as d]
[app.common.schema :as sm]
[app.main.ui.formats :as fmt]
[app.main.ui.hooks :as h]
[app.util.dom :as dom]
[app.util.globals :as globals]
[app.util.keyboard :as kbd]
[app.util.object :as obj]
[app.util.simple-math :as smt]
[cljs.core :as c]
[cuerdas.core :as str]
[goog.events :as events]
[rumext.v2 :as mf]))
update-input
(mf/use-fn
(fn [new-value]
(when-let [node (mf/ref-val ref)]
(dom/set-value! node (fmt/format-number new-value)))))
props (-> (obj/clone props)
(obj/unset! "selectOnFocus")
(obj/unset! "nillable")
(obj/set! "value" mf/undefined)
(obj/set! "onChange" mf/undefined)
(obj/set! "className" class)
(obj/set! "type" "text")
(obj/set! "ref" ref)
(obj/set! "defaultValue" (fmt/format-number value))
(obj/set! "title" title)
(obj/set! "onKeyDown" handle-key-down)
(obj/set! "onBlur" handle-blur)
(obj/set! "onFocus" handle-focus))]
(mf/with-effect [value]
(when-let [input-node (mf/ref-val ref)]
(dom/set-value! input-node (fmt/format-number value))))
penpot/penpot
(ns app.main.ui.workspace.viewport.presence
(:require
[app.main.refs :as refs]
[app.util.time :as dt]
[app.util.timers :as ts]
[beicon.v2.core :as rx]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
(mf/defc session-cursor
[{:keys [session profile] :as props}]
(let [zoom (mf/deref refs/selected-zoom)
point (:point session)
background-color (:color session "var(--black)")
text-color (:text-color session "var(--white)")
transform (str/fmt "translate(%s, %s) scale(%s)" (:x point) (:y point) (/ 1 zoom))
shown-name (if (> (count (:fullname profile)) 16)
(str (str/slice (:fullname profile) 0 12) "...")
(:fullname profile))]
[:g.multiuser-cursor {:transform transform}
[:path {:fill background-color
:d pointer-icon-path}]
[:g {:transform "translate(17 -10)"}
[:foreignObject {:x -0.3
:y -12.5
:width 300
:height 120}
[:div.profile-name {:style {:background-color background-color
:color text-color}}
shown-name]]]]))
penpot/penpot
(ns app.main.ui.workspace.shapes.debug
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.text :as gst]
[app.common.math :as mth]
[app.main.refs :as refs]
[app.util.color :as uc]
[app.util.debug :as dbg]
[app.util.dom :as dom]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
(mf/defc debug-bounding-boxes
[{:keys [shape]}]
(let [points (->> (:points shape)
(map #(dm/fmt "%,%" (dm/get-prop % :x) (dm/get-prop % :y)))
(str/join " "))
color (mf/use-memo #(uc/random-color))
sr (:selrect shape)]
[:g.debug-bounding-boxes
[:rect {:transform (gsh/transform-str shape)
:x (:x sr)
:y (:y sr)
:width (:width sr)
:height (:height sr)
:fill color
:opacity 0.2}]
(for [p (:points shape)]
[:circle {:cx (dm/get-prop p :x)
:cy (dm/get-prop p :y)
:r 2
:fill color}])
[:polygon {:points points
:stroke-width 1
:stroke color}]]))
penpot/penpot
(ns app.main.ui.workspace.viewport.debug
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.files.helpers :as cfh]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.flex-layout :as gsl]
[app.common.geom.shapes.grid-layout :as gsg]
[app.common.geom.shapes.points :as gpo]
[app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid]
[cuerdas.core :as str]
[rumext.v2 :as mf]))
[:g.debug-layout {:pointer-events "none"}
[:polygon {:points (->> layout-bounds (map #(dm/fmt "%, %" (:x %) (:y %))) (str/join " "))
:style {:stroke "red" :fill "none"}}]
[:g.layout-line {:key (dm/str "line-" idx)}
[:polygon {:points (->> points (map #(dm/fmt "%, %" (:x %) (:y %))) (str/join " "))
:style {:stroke "red" :stroke-width (/ 2 zoom) :stroke-dasharray (dm/str (/ 10 zoom) " " (/ 5 zoom))}}]]))]))))
(let [shape (unchecked-get props "shape")
parent (unchecked-get props "parent")
zoom (unchecked-get props "zoom")
[i1 i2 i3 i4] (gpo/parent-coords-bounds (:points shape) (:points parent))]
[:*
[:polygon {:points (->> [i1 i2 i3 i4] (map #(dm/fmt "%,%" (:x %) (:y %))) (str/join ","))
:style {:fill "none" :stroke "red" :stroke-width (/ 1 zoom)}}]