Skip to content

Commit

Permalink
[new] [Experimental] Add :default-tag option to `default-resource-c…
Browse files Browse the repository at this point in the history
…ompiler`
  • Loading branch information
ptaoussanis committed Oct 17, 2022
1 parent 6d25ca5 commit 36b15ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/taoensso/tempura.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
Good general-purpose resource compiler.
Supports output of text, and Hiccup forms with simple Markdown styles."
(enc/fmemoize
(fn [{:keys [escape-html?]}]
(fn [{:keys [default-tag escape-html?]
:or {default-tag :span}}]

(let [esc1 (if escape-html? impl/escape-html identity)
esc2 (if escape-html? impl/vec-escape-html-in-strs identity)]

Expand All @@ -42,10 +44,10 @@
(fn? res) (-> res) ; Completely arb, full control
(string? res) (-> res esc1 impl/str->vargs-fn)
(vector? res) (-> res
impl/vec->vtag
(impl/vec->vtag default-tag)
impl/vec-explode-styles-in-strs
impl/vec-explode-args-in-strs
esc2 ; Avoid for Reactjs
esc2 ; Avoid for Reactjs
impl/vec->vargs-fn))))))))

(comment
Expand Down
13 changes: 7 additions & 6 deletions src/taoensso/tempura/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,13 @@

(defn vec->vtag
"[\"foo\"] -> [:span \"foo\"] as a convenience."
[v]
(have? vector? v)
(let [[v1] v]
(if-not (keyword? v1)
(into [:span] v)
v)))
([v ] (vec->vtag v :span))
([v default-tag]
(have? vector? v)
(let [[v1] v]
(if-not (keyword? v1)
(into [default-tag] v)
v))))

(comment
(vec->vtag [:div.special "foo"]) ; Allow control of tag type
Expand Down

0 comments on commit 36b15ac

Please sign in to comment.