Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cleaned up the gravatar appearance on the profile and users pages. #142

Closed
wants to merge 4 commits into from

2 participants

@darrenaustin

No description provided.

amalloy and others added some commits
@amalloy amalloy Pull a few pieces out of utils.clj
Functionality is now in ring-utils and version-utils.
52ab45f
@amalloy amalloy First draft on gravatars.
Top Users page looks all right, but surely can be improved.
Profile page looks an absolute mess, and I'm out of my depth in
CSS. Can someone (@gigasquid, @amcnamara?) have a look?
258535b
@darrenaustin darrenaustin Cleaned up the appearance of the gravatars on the profile and top use…
…rs pages
b390349
@darrenaustin darrenaustin Fixed sorting on the user names with gravatars next to them. 1d113ee
@amalloy amalloy closed this pull request from a commit
@amalloy amalloy Merge branch 'feature/gravatar' into develop
Closes #142, closes #139
1c7b8d9
@amalloy amalloy closed this in 1c7b8d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 2, 2011
  1. @amalloy

    Pull a few pieces out of utils.clj

    amalloy authored
    Functionality is now in ring-utils and version-utils.
  2. @amalloy

    First draft on gravatars.

    amalloy authored
    Top Users page looks all right, but surely can be improved.
    Profile page looks an absolute mess, and I'm out of my depth in
    CSS. Can someone (@gigasquid, @amcnamara?) have a look?
  3. @darrenaustin
  4. @darrenaustin
This page is out of date. Refresh to see the latest.
View
18 resources/public/css/style.css
@@ -134,6 +134,22 @@ a.novisited {color: #00e;}
color: black;
}
+td a.user-profile-link {
+ display: block;
+ margin-top: 5px;
+}
+
+.user-profile-img{
+ float: left;
+ padding-right: 10px;
+}
+
+img.gravatar{
+ float: left;
+ display: inline;
+ margin-right: 5px;
+}
+
#user-info{
float:right;
}
@@ -217,7 +233,6 @@ a.novisited {color: #00e;}
padding: 15px;
}
-
/*
* By default only show the text label for the "Following" column on
* the users page. If they have javascript turned on (detected
@@ -391,6 +406,7 @@ table.my-table {
table.my-table td {
text-align: left;
font-size: 12px;
+ vertical-align: middle;
}
tr.evenrow {
View
39 resources/public/script/foreclojure.js
@@ -59,20 +59,31 @@ $(document).ready(function() {
});
});
-var difficulty = new Array();
-difficulty["Elementary"] = 0;
-difficulty["Easy"] = 1;
-difficulty["Medium"] = 2;
-difficulty["Hard"] = 3;
-difficulty[""] = 4;
-
-jQuery.fn.dataTableExt.oSort['difficulty-asc'] = function(a, b) {
- return difficulty[a] - difficulty[b];
+var difficulty = {
+ "Elementary": 0,
+ "Easy": 1,
+ "Medium": 2,
+ "Hard": 3,
+ "": 4
};
-jQuery.fn.dataTableExt.oSort['difficulty-desc'] = function(a, b) {
- return difficulty[b] - difficulty[a];
-};
+jQuery.fn.dataTableExt.afnSortData['difficulty'] = function(oSettings, iColumn)
+{
+ var aData = [];
+ $('td:eq('+iColumn+')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
+ aData.push(difficulty[$(this).text()]);
+ });
+ return aData;
+}
+
+jQuery.fn.dataTableExt.afnSortData['user-name'] = function(oSettings, iColumn)
+{
+ var aData = [];
+ $('td:eq('+iColumn+') a.user-profile-link', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
+ aData.push($(this).text());
+ });
+ return aData;
+}
function configureDataTables(){
@@ -81,7 +92,7 @@ function configureDataTables(){
"aaSorting": [[5, "desc"], [1, "asc"], [4, "desc"]],
"aoColumns": [
{"sType": "string"},
- {"sType": "difficulty"},
+ {"sSortDataType": "difficulty", "sType": "numeric"},
{"sType": "string"},
{"sType": "string"},
{"sType": "numeric"},
@@ -105,7 +116,7 @@ function configureDataTables(){
"aaSorting": [[0, "asc"]],
"aoColumns": [
{"sType": "numeric"},
- {"sType": "string"},
+ {"sSortDataType": "user-name"},
{"sType": "numeric"},
{"sType": "string"}
]
View
4 src/foreclojure/core.clj
@@ -16,7 +16,7 @@
[foreclojure.version :only [version-routes]]
[foreclojure.graphs :only [graph-routes]]
[foreclojure.mongo :only [prepare-mongo]]
- [foreclojure.utils :only [wrap-uri-binding]]
+ [foreclojure.ring-utils :only [wrap-request-bindings]]
[foreclojure.periodic :only [schedule-task]]
[ring.adapter.jetty :only [run-jetty]]
[ring.middleware.reload :only [wrap-reload]]
@@ -47,7 +47,7 @@
#(wrap-reload % '(foreclojure.core))
identity))
session/wrap-stateful-session
- wrap-uri-binding
+ wrap-request-bindings
handler/site
wrap-strip-trailing-slash))
View
3  src/foreclojure/problems.clj
@@ -4,7 +4,8 @@
[clojure.string :as s]
[ring.util.response :as response])
(:import [org.apache.commons.mail EmailException])
- (:use [foreclojure.utils :only [from-mongo get-user get-solved login-link *url* flash-msg flash-error row-class approver? can-submit? send-email image-builder with-user as-int maybe-update escape-html]]
+ (:use [foreclojure.utils :only [from-mongo get-user get-solved login-link flash-msg flash-error row-class approver? can-submit? send-email image-builder with-user as-int maybe-update escape-html]]
+ [foreclojure.ring-utils :only [*url*]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.social :only [tweet-link gist!]]
[foreclojure.feeds :only [create-feed]]
View
19 src/foreclojure/ring.clj
@@ -1,12 +1,13 @@
(ns foreclojure.ring
- (:require [clojure.java.io :as io]
- [clojure.string :as s]
- [compojure.route :as route])
- (:import [java.net URL])
- (:use [compojure.core :only [GET]]
- [foreclojure.utils :only [strip-version-number]]
- [useful.debug :only [?]]
- [ring.util.response :only [response]]))
+ (:require [clojure.java.io :as io]
+ [clojure.string :as s]
+ [compojure.route :as route])
+ (:import [java.net URL])
+ (:use [compojure.core :only [GET]]
+ [foreclojure.version-utils :only [strip-version-number]]
+ [foreclojure.ring-utils :only [get-host]]
+ [useful.debug :only [?]]
+ [ring.util.response :only [response]]))
;; copied from compojure.route, modified to use File instead of Stream
(defn resources
@@ -45,7 +46,7 @@
(defn split-hosts [host-handlers]
(let [default (:default host-handlers)]
(fn [request]
- (let [host (get-in request [:headers "host"])
+ (let [host (get-host request)
handler (or (host-handlers host) default)]
(handler request)))))
View
20 src/foreclojure/ring_utils.clj
@@ -0,0 +1,20 @@
+(ns foreclojure.ring-utils
+ (:require [foreclojure.config :as config]))
+
+(def ^:dynamic *url* nil) ; url of current request
+(def ^:dynamic *host* nil) ; Host header sent by client
+(def ^:dynamic *http-scheme* nil) ; keyword, :http or :https
+
+(defn get-host [request]
+ (get-in request [:headers "host"]))
+
+(defn wrap-request-bindings [handler]
+ (fn [req]
+ (binding [*url* (:uri req)
+ *host* (or (get-host req) "www.4clojure.com")
+ *http-scheme* (:scheme req)]
+ (handler req))))
+
+(def static-url (if-let [host config/static-host]
+ #(str (name *http-scheme*) "://" host "/" %)
+ #(str "/" %)))
View
10 src/foreclojure/static.clj
@@ -1,9 +1,9 @@
(ns foreclojure.static
- (:use [compojure.core :only [defroutes GET]]
- [foreclojure.problems :only [solved-stats]]
- [foreclojure.config :only [repo-url]]
- [foreclojure.utils :only [static-url]]
- [foreclojure.template :only [def-page]]))
+ (:use [compojure.core :only [defroutes GET]]
+ [foreclojure.problems :only [solved-stats]]
+ [foreclojure.config :only [repo-url]]
+ [foreclojure.ring-utils :only [static-url]]
+ [foreclojure.template :only [def-page]]))
(def df
(let [df (java.text.DecimalFormat.)
View
12 src/foreclojure/template.clj
@@ -1,9 +1,11 @@
(ns foreclojure.template
- (:require [sandbar.stateful-session :as session])
- (:use [hiccup.core :only [html]]
- [hiccup.page-helpers :only [doctype javascript-tag link-to]]
- [foreclojure.config :only [config repo-url]]
- [foreclojure.utils :only [css js page-attributes rendering-info login-url approver? can-submit? static-url]]))
+ (:require [sandbar.stateful-session :as session])
+ (:use [hiccup.core :only [html]]
+ [hiccup.page-helpers :only [doctype javascript-tag link-to]]
+ [foreclojure.config :only [config repo-url]]
+ [foreclojure.utils :only [page-attributes rendering-info login-url approver? can-submit?]]
+ [foreclojure.ring-utils :only [static-url]]
+ [foreclojure.version-utils :only [css js]]))
;; Global wrapping template
(defn html-doc [body]
View
28 src/foreclojure/users.clj
@@ -1,14 +1,17 @@
(ns foreclojure.users
(:require [ring.util.response :as response]
+ [clojure.string :as string]
[sandbar.stateful-session :as session])
(:use [foreclojure.utils :only [from-mongo row-class rank-class get-user with-user]]
[foreclojure.template :only [def-page content-page]]
+ [foreclojure.ring-utils :only [*http-scheme*]]
[foreclojure.config :only [config repo-url]]
[somnium.congomongo :only [fetch-one fetch update!]]
[compojure.core :only [defroutes GET POST]]
[hiccup.form-helpers :only [form-to hidden-field]]
[hiccup.page-helpers :only [link-to]]
- [clojure.contrib.json :only [json-str]]))
+ [clojure.contrib.json :only [json-str]])
+ (:import org.apache.commons.codec.digest.DigestUtils))
(def golfer-tags (into [:contributor]
(when (:golfing-active config)
@@ -23,7 +26,7 @@
(defn get-users []
(from-mongo
(fetch :users
- :only [:user :solved :contributor])))
+ :only [:user :solved :contributor :email])))
(defn get-ranked-users []
(let [users (get-users)
@@ -66,6 +69,18 @@
(link-to (str "mailto:" (email-address username))
username))
+
+
+(let [canonical-email (comp string/trim string/lower-case)
+ md5 #(DigestUtils/md5Hex %)]
+ (defn gravatar-img [{:keys [email size class] :or {size 24}}]
+ (let [hash (md5 (canonical-email email))
+ url (str (name *http-scheme*) "://www.gravatar.com/avatar/"
+ hash "?s=" size "&d=identicon")]
+ [:img (conj {:src url, :alt "gravatar icon"
+ :width size :height size}
+ (when class {:class class}))])))
+
(defn format-user-ranking [{:keys [rank user contributor solved]}]
(when user
[:div
@@ -102,12 +117,12 @@
[:th {:style "width: 200px;"} "Username"]
[:th {:style "width: 180px;"} "Problems Solved"]
[:th "Following"]]]
- (map-indexed (fn [rownum {:keys [_id position rank user contributor solved]}]
+ (map-indexed (fn [rownum {:keys [_id email position rank user contributor solved]}]
[:tr (row-class rownum)
[:td (rank-class position) rank]
[:td
- (when contributor [:span.contributor "* "])
- [:a.user-profile-link {:href (str "/user/" user)} user]]
+ (gravatar-img {:email email :class "gravatar"})
+ [:a.user-profile-link {:href (str "/user/" user)} user (when contributor [:span.contributor " *"])]]
[:td.centered (count solved)]
[:td (following-checkbox user-id following _id user)]])
user-set)])))
@@ -158,10 +173,11 @@
(def-page user-profile [username]
(let [page-title (str "User: " username)
- user-id (:_id (get-user username))]
+ {user-id :_id email :email} (get-user username)]
{:title page-title
:content
(list
+ (gravatar-img {:email email, :size 80 :class "user-profile-img"})
[:div.user-profile-name page-title]
(if (session/session-get :user)
(with-user [{:keys [_id following]}]
View
31 src/foreclojure/utils.clj
@@ -14,15 +14,9 @@
[hiccup.form-helpers :only [label]]
[useful.fn :only [to-fix]]
[somnium.congomongo :only [fetch-one]]
+ [foreclojure.ring-utils :only [*url* static-url]]
[foreclojure.config :only [config repo-url]]))
-(def ^{:dynamic true} *url* nil)
-
-(defn wrap-uri-binding [handler]
- (fn [req]
- (binding [*url* (:uri req)]
- (handler req))))
-
(defn as-int [s]
(if (integer? s) s,
(try (Integer. s)
@@ -158,29 +152,6 @@
(>= (count (get-solved username))
(:advanced-user-count config)))))
-(let [prefix (str (when-let [host config/static-host]
- (str "http://" host))
- "/")]
- (defn static-url [url]
- (str prefix url)))
-
-(let [version-suffix (str "__" git/tag)]
- (defn add-version-number [file]
- (let [[_ path ext] (re-find #"(.*)\.(.*)$" file)]
- (str path version-suffix "." ext)))
-
- (defn strip-version-number [file]
- (string/replace file version-suffix "")))
-
-(letfn [(wrap-versioning [f]
- (fn [& files]
- (for [file files]
- (f (static-url (add-version-number file))))))]
- (def js (wrap-versioning hiccup/include-js))
- (def css (wrap-versioning hiccup/include-css)))
-
-
-
(defn image-builder
"Return a function for constructing an [:img] element from a keyword.
View
21 src/foreclojure/version_utils.clj
@@ -0,0 +1,21 @@
+(ns foreclojure.version-utils
+ (:use [foreclojure.ring-utils :only [static-url]])
+ (:require [foreclojure.git :as git]
+ [foreclojure.config :as config]
+ [clojure.string :as string]
+ [hiccup.page-helpers :as hiccup]))
+
+(let [version-suffix (str "__" git/tag)]
+ (defn add-version-number [file]
+ (let [[_ path ext] (re-find #"(.*)\.(.*)$" file)]
+ (str path version-suffix "." ext)))
+
+ (defn strip-version-number [file]
+ (string/replace file version-suffix "")))
+
+(letfn [(wrap-versioning [f]
+ (fn [& files]
+ (for [file files]
+ (f (static-url (add-version-number file))))))]
+ (def js (wrap-versioning hiccup/include-js))
+ (def css (wrap-versioning hiccup/include-css)))
Something went wrong with that request. Please try again.