Skip to content

Commit

Permalink
Problem title added to tweet text if it will fit
Browse files Browse the repository at this point in the history
  • Loading branch information
dbyrne committed May 20, 2011
1 parent 1636129 commit 52f44fd
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/foreclojure/social.clj
Expand Up @@ -36,16 +36,20 @@
(or anchor-text "Twitter")
"</a>"))

(defn get-problem-title [id]
(:title
(fetch-one :problems
:only [:title]
:where {:_id id})))

(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 possessive] (if user-name
[user-name "'s"]
["anonymous" nil])

{name :title} (fetch-one :problems
:where {:_id problem-num})
name (get-problem-title problem-num)
filename (str user-name "-4clojure-solution" problem-num ".clj")
text (str ";; " user-name possessive " solution to " name "\n"
";; https://4clojure.com/problem/" problem-num
Expand All @@ -58,8 +62,12 @@
(catch Throwable _))))

(defn tweet-solution [id gist-url & [link-text]]
(let [status-msg (str "Check out how I solved problem #"
id " on #4clojure " (clojure-hashtag) gist-url)]
(let [status-msg (str "Check out how I solved "
(let [title (get-problem-title id)]
(if (> (count title) 35)
(str "problem " id)
(str "\"" title "\"")))
" on #4clojure " (clojure-hashtag) gist-url)]
(tweet-link id status-msg link-text)))

(def-page share-page []
Expand Down

0 comments on commit 52f44fd

Please sign in to comment.