Skip to content

Commit

Permalink
added unambig alias example
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 20, 2024
1 parent e05b655 commit 189cc8d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions dev/bench/chassis.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
[:h3 "Description"]
[:p (:text item)]]))

(defmethod c/resolve-alias ::ItemCompiledUnambig
[_ _ {item ::item :as attrs} content]
(cc/compile
[:div.item (merge {:id (:uuid item)
:class (:type item)} attrs)
[:h2 nil (:name item)]
[:p nil (:date item)]
[:p [:a.baz.buz {:href (str "/item/" (:uuid item))}
"See more details."]]
[:h3 "Description"]
[:p nil (:text item)]]))

(defmethod c/resolve-alias ::Layout
[_ _ {title ::title :as attrs} content]
[:html {:lang "en"}
Expand Down Expand Up @@ -56,6 +68,22 @@
[:main attrs content]
[:footer "Footer"]]]))

(defmethod c/resolve-alias ::LayoutCompiledUnambig
[_ _ {title ::title :as attrs} content]
(cc/compile
[:html {:lang "en"}
[:head
[:link {:href "/foobar1" :rel "stylesheet"}]
[:link {:href "/foobar2" :rel "stylesheet"}]
[:link {:href "/foobar3" :rel "stylesheet"}]
[:link {:href "/foobar4" :rel "stylesheet"}]
[:title nil title]]
[:body
[:header
[:h1 nil title]]
[:main ^java.util.Map attrs content]
[:footer "Footer"]]]))

(defn item-element
[item]
[:div.item {:id (:uuid item)
Expand Down Expand Up @@ -143,6 +171,14 @@
(map #(cc/compile [::ItemCompiled {::item %}]))
(interpose (cc/compile [:hr])))]))

(defn page-alias-compiled-unambig
[data]
(cc/compile
[::LayoutCompiledUnambig {::title (:title data)}
(->> (:items data)
(map #(cc/compile [::ItemCompiledUnambig {::item %}]))
(interpose (cc/compile [:hr])))]))

(defn page-compiled
[data]
(cc/compile
Expand Down Expand Up @@ -193,6 +229,10 @@
[data]
(c/html [c/doctype-html5 (page-alias-compiled data)]))

(defn chassis-page-alias-compiled-unambig
[data]
(c/html [c/doctype-html5 (page-alias-compiled-unambig data)]))

(defn chassis-page-compiled
[data]
(c/html [c/doctype-html5 (page-compiled data)]))
Expand Down
1 change: 1 addition & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:refer [page
chassis-page
chassis-page-alias chassis-page-alias-compiled
chassis-page-alias-compiled-unambig
chassis-page-compiled chassis-page-compiled-unambig
chassis-page-print-writer chassis-page-print-stream
chassis-page-output-stream-writer]]
Expand Down

0 comments on commit 189cc8d

Please sign in to comment.