Ich bin relativ neu in Clojure und Compojure Web-Entwicklung. Das erste Problem, das ich in dem Spielzeug-Beispiel bemerkt habe, das ich erstelle, ist das HTML-Templating. Ich würde gerne Unterstützung für Teilbereiche in Rails oder für das Template-Framework, das Django verwendet, haben.Komponieren Vorlagen mit Hiccup und Compojure
Zur Zeit habe ich:
(defn index-page []
(html5
[:head
[:title "Home | Compojure Docs"]
(include-css "/css/bootstrap.min.css")
(include-css "/css/bootstrap-responsive.min.css")]
[:body
[:div {:class "container-fluid"}
[:div {:class "row-fluid"}
[:div {:class "span2 menu"}]
[:div {:class "span10 content"}
[:h1 "Compojure Docs"]
[:ul
[:li
[:a {:href "/getting-started"} "Getting Started"]]
[:li
[:a {:href "/routes-in-detail"} "Routes in Detail"]]
[:li
[:a {:href "/destructuring-syntax"} "Destructuring Syntax"]]
[:li
[:a {:href "/nesting-routes"} "Nesting Routes"]]
[:li
[:a {:href "/api-documentation"} "API Documentation"]]
[:li
[:a {:href "/paas-platforms"} "PaaS Platforms"]]
[:li
[:a {:href "/example-project"} "Example Project"]]
[:li
[:a {:href "/example-project-on-cloudbees"} "Example Project on CloudBees"]]
[:li
[:a {:href "/interactive-development-with-ring"} "Interactive Development with Ring"]]
[:li
[:a {:href "/emacs-indentation"} "Emacs Indentation"]]
[:li
[:a {:href "/sessions"} "Sessions"]]
[:li
[:a {:href "/common-problems"} "Common Problems"]]]
(include-js "/js/jquery-1.9.1.min.js")
(include-js "/js/bootstrap.min.js")]]]]))
(defn routes-in-detail []
(html5
[:head
[:title "Routes in Detail | Compojure Docs"]
(include-css "/css/style.css")]
[:body
[:h1 "Routes in Detail"]]))
Gibt es für mich eine gute Möglichkeit, nicht-Code zu wiederholen? Ich möchte, dass das Zeug in dem HEAD-Tag in einer eigenen Vorlagendatei oder Funktion ist, und dann in der Lage sein, es einzuschließen, wie ich gehe. Zum Beispiel möchte ich es in die Funktion "routes-ins Detail" aufnehmen. Ich habe Enlive angeschaut, aber ich weiß nicht, wie ich das mit Hiccup anwenden soll. Irgendwelche Gedanken zu Best Practices würden hier geschätzt werden.
Dank für die ausführliche Antwort danken. Genau das habe ich gesucht. –