summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Ostler <sostler@deathmachine.local>2010-03-17 22:50:49 -0400
committerScott Ostler <sostler@deathmachine.local>2010-03-17 22:50:49 -0400
commit924591575aa2e3aac2cc874b4c190e6daf21beeb (patch)
treedfcf5f512426c832133c7c1649218c1b44e4f3ac /src
parent245226bfd7b28bd979dda7356ee859d4dd880205 (diff)
Refactoring
Diffstat (limited to 'src')
-rwxr-xr-xsrc/site.clj43
1 files changed, 10 insertions, 33 deletions
diff --git a/src/site.clj b/src/site.clj
index f76531d..710b45b 100755
--- a/src/site.clj
+++ b/src/site.clj
@@ -70,22 +70,6 @@
;; Utils
-(defn ms-in-future [ms]
- (+ ms (System/currentTimeMillis)))
-
-(defn swap [f]
- (fn [& more] (apply f (reverse more))))
-
-(def YYYYMMDD-format (new SimpleDateFormat "yyyyMMdd"))
-
-(defn today []
- (.format YYYYMMDD-format (new Date)))
-
-(def formatter (new SimpleDateFormat "h:mm a EEE M/d"))
-
-(defn non-empty-string? [s]
- (and s (> (count s) 0)))
-
(defn open-file [dir-comps filename]
(let [d (str-join (System/getProperty "file.separator")
(cons *root-directory* dir-comps))
@@ -134,6 +118,9 @@
;; Output
+(defn strip-empty-vals [m]
+ (into {} (filter (fn [[k v]] (non-empty-string? v)) m)))
+
(defn stringify-and-escape [m]
(zipmap (map name (keys m)) (map escape-html (vals m))))
@@ -141,11 +128,9 @@
(assoc d :created_on (.getTime (d :created_on))))
(defn process-message-for-output [d]
- {"nick" (escape-html (d :nick))
- "avatar" (escape-html (d :avatar))
- "message_id" (d :message_id)
- "created_on" (.format formatter (d :created_on))
- "content" (escape-html (d :content))})
+ (stringify-and-escape
+ (strip-empty-vals
+ (assoc d :created_on (.format formatter (d :created_on))))))
(defn new-messages [room since-ts]
(let [since-date (new Date (long since-ts))]
@@ -153,19 +138,11 @@
@(room :messages)))))
(defn process-user [u]
- (if (non-empty-string? (u :avatar))
- {"nick" (u :nick)
- "avatar" (escape-html (u :avatar))}
- {"nick" (u :nick)}))
+ (stringify-and-escape (strip-empty-vals u)))
(defn process-directory-listing [d]
- (let [base {"nick" (escape-html (d :nick))
- "content" (escape-html (d :content))
- "count" (d :count)}
- avatar (d :avatar)]
- (if (non-empty-string? avatar)
- (assoc base "avatar" avatar)
- base)))
+ (stringify-and-escape
+ (strip-empty-vals d)))
(defn prepare-user-list [room]
(map process-user (sort-by #(% :nick)
@@ -417,7 +394,7 @@
dict (zipmap keys res)]
(map (fn [u]
(let [u-id (u :user_id)]
- (stringify-and-escape (merge u (dict u-id)))))
+ (process-directory-listing (merge u (dict u-id)))))
users)))))
(defn update-directory! []