28 Nov 2013, 22:53
Marcus_pragsmall

Marcus Brito (8 posts)

Using compojure.response.Renderable just to add a JavaScript variable for the context path seems way overkill to me.

I’m as new to Clojure as most people reading this book, but exploring the namespaces used so far, I think using noir.request/*request* is a better way:

(ns picture-gallery.views.layout
  (:require [noir.request :refer [*request*]]))

…

(defn base [& body]
  (html5
    [:head
     [:title "Welcome to picture-gallery"]
     (include-css "/css/screen.css")
     [:script {:type "text/javascript"} (str "var context=\"" (:context *request*) "\";")]
     (include-js "//code.jquery.com/jquery-2.0.3.min.js")]
    [:body body]))

Skimming the Compojure documentation, it seems to me that Renderable would be more appropriate for cases where you need to render a complex type that’s not supported out of the box.

29 Nov 2013, 01:00
Profile_pic_pragsmall

Dmitri Sotnikov (36 posts)

Using the *request* would be perfectly fine in this scenario. I thought this was a good opportunity to introduce protocols and Renderable in particular.

  You must be logged in to comment