Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render avatar and profile in format json #165

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/statuses/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@
(defn avatar-path [username]
(clojure.string/replace (config :avatar-url) "{username}" username))

(defn profile-path [username]
(str (config :profile-url-prefix) username))
3 changes: 2 additions & 1 deletion src/statuses/routing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[statuses.backend.persistence :refer [db]]
[statuses.routes :as route]
[statuses.views.atom :as atom]
[statuses.views.json :as json-decorator]
[statuses.views.info :as info-view]
[statuses.views.main :refer [list-page reply-form]]
[statuses.views.too-long :as too-long-view]))
Expand Down Expand Up @@ -54,7 +55,7 @@
(cond
(= format "json") (content-type
"application/json"
(json/as-json {:items items, :next next}))
(json/as-json {:items (json-decorator/decorate items), :next next}))
(= format "atom") (content-type
"application/atom+xml;charset=utf-8"
(atom/render-atom items
Expand Down
13 changes: 13 additions & 0 deletions src/statuses/views/json.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns statuses.views.json
(:require [statuses.routes :refer [avatar-path profile-path]]))

(defn add-avatar [items]
(map (fn [item] (assoc item :avatar (avatar-path (:author item)))) items))

(defn add-profile [items]
(map (fn [item] (assoc item :self (profile-path (:author item)))) items))

(defn decorate [items]
(->> items
(add-avatar)
(add-profile)))
2 changes: 1 addition & 1 deletion src/statuses/views/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
(defn update [is-current {:keys [id text author time in-reply-to conversation can-delete?]}]
(list
[:div.avatar
(link-to (str (config :profile-url-prefix) author) [:img {:src (avatar-path author) :alt author}])]
(link-to (profile-path author) [:img {:src (avatar-path author) :alt author}])]
[:div.meta
[:span.author (link-to (str (updates-path) "?author=" author) author)]
(if in-reply-to
Expand Down