Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (51 sloc) 2.05 KB
(:use foreclojure.utils
(:require [clj-github.gists :as gist]
[sandbar.stateful-session :as session])
(defn tweet-link [status & [anchor-text]]
(str "<a href=\""
(URLEncoder/encode status) "\">"
(or anchor-text "Twitter")
(defn gist!
"Create a new gist containing a user's solution to a problem and
return its url."
[user-name problem-num solution]
(let [user-name (or user-name "anonymous")
filename (str user-name "-4clojure-solution" problem-num ".clj")
text (str ";; " user-name
"'s solution to" problem-num
(->> (gist/new-gist {} filename text)
(str ""))
(catch Throwable _ nil))))
(defn tweet-solution [id gist-url & [link-text]]
(let [status-msg (str "Check out how I solved"
id " - " gist-url " #clojure #4clojure")]
(tweet-link status-msg link-text)))
(def-page share-page []
(if-let [[id code] (session/session-get :code)]
(let [user (session/session-get :user)
gist-url (gist! user id code)
gist-link (if gist-url
[:div {:id "shared-code-box"}
[:h3 "Your Solution"]
[:pre {:class "brush: clojure;gutter: false;toolbar: false;light: true"} code]]
"Share this " (link-to gist-url "solution")
" on " (tweet-solution id gist-url) "?"]]
"Failed to create gist of your solution"])]
"Sorry...I don't remember you solving anything recently!"]))
(defroutes social-routes
(GET "/share/code" [] (share-page)))
Jump to Line
Something went wrong with that request. Please try again.