Skip to content
Browse files

Add a universal-url function.

We need to distinguish between static URLs that will be loaded
by the user, vs static URLs some external site (such as gravatar)
will see; the latter must always include a host portion.
  • Loading branch information...
1 parent 8f44330 commit 5aa276a90d91be2315cf1000be5a0ea49b0843fb @amalloy amalloy committed Nov 22, 2011
Showing with 8 additions and 4 deletions.
  1. +6 −2 src/foreclojure/ring_utils.clj
  2. +2 −2 src/foreclojure/users.clj
View
8 src/foreclojure/ring_utils.clj
@@ -15,5 +15,9 @@
*http-scheme* (:scheme req)]
(handler req))))
-(def static-url (let [host (or config/static-host config/canonical-host)]
- #(str (name (or *http-scheme* :http)) "://" host "/" %)))
+(letfn [(url-fn [host]
+ (if host
+ #(str (name (or *http-scheme* :http)) "://" host "/" %)
+ #(str "/" %)))]
+ (def universal-url (url-fn (or config/static-host config/canonical-host)))
+ (def static-url (url-fn config/static-host)))
View
4 src/foreclojure/users.clj
@@ -5,7 +5,7 @@
[cheshire.core :as json])
(:use [foreclojure.utils :only [from-mongo row-class rank-class get-user if-user with-user]]
[foreclojure.template :only [def-page content-page]]
- [foreclojure.ring-utils :only [*http-scheme* static-url]]
+ [foreclojure.ring-utils :only [*http-scheme* universal-url]]
[foreclojure.config :only [config repo-url]]
[somnium.congomongo :only [fetch-one fetch update!]]
[compojure.core :only [defroutes GET POST]]
@@ -73,7 +73,7 @@
(let [canonical-email (comp string/trim string/lower-case)
md5 #(DigestUtils/md5Hex %)
- as-url #(URLEncoder/encode (static-url %))
+ as-url #(URLEncoder/encode (universal-url %))
no-gravatar-url (as-url "images/no-gravatar.png")]
(defn gravatar-img [{:keys [email size class default] :or {size 24}}]
(let [hash (if email

0 comments on commit 5aa276a

Please sign in to comment.
Something went wrong with that request. Please try again.