Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'jafingerhut-develop' into develop

  • Loading branch information...
commit 2a024203c2122f24045877f08892e283b9e89db6 2 parents 1269965 + 095d039
Lee Hinman authored March 03, 2011

Showing 1 changed file with 24 additions and 7 deletions. Show diff stats Hide diff stats

  1. 31  src/cd_client/core.clj
31  src/cd_client/core.clj
@@ -15,6 +15,15 @@
15 15
 (def *seealso-api*      (str *clojuredocs-root* "/see-also/"))
16 16
 
17 17
 
  18
+(defn- fixup-name-url
  19
+  "Replace some special characters in symbol names in order to construct a URL that works on clojuredocs.org"
  20
+  [name]
  21
+  (-> name
  22
+      (string/replace "." "_dot")
  23
+      (string/replace "?" "_q")
  24
+      (string/replace "/" "_")))
  25
+
  26
+
18 27
 (defn remove-markdown
19 28
   "Remove basic markdown syntax from a string."
20 29
   [text]
@@ -24,6 +33,8 @@
24 33
       (.replaceAll "<p>" "")
25 34
       (.replaceAll "</p>" "")
26 35
       (.replaceAll "&gt;" ">")
  36
+      (.replaceAll "&lt;" "<")
  37
+      (.replaceAll "&amp;" "&")
27 38
       (.replaceAll "<br>" "")
28 39
       (.replaceAll "<br/>" "")
29 40
       (.replaceAll "<br />" "")
@@ -48,14 +59,17 @@
48 59
    :else
49 60
     (let [nspace (find-ns name)]
50 61
       (if nspace
51  
-        `(println "No usage examples for namespaces as a whole like" '~name "\nTry a particular symbol in a namespace, e.g. clojure.string/join")
  62
+        `(println "No usage examples for namespaces as a whole like" '~name
  63
+                  "\nTry a particular symbol in a namespace,"
  64
+                  "e.g. clojure.string/join")
52 65
         `(call-with-ns-and-name ~fn (var ~name))))))
53 66
 
54 67
 
55 68
 (defn examples-core
56 69
   "Return examples from clojuredocs for a given namespace and name (as strings)"
57 70
   [ns name]
58  
-  (json/decode-from-str (:body (http/get (str *examples-api* ns "/" name)))))
  71
+  (json/decode-from-str (:body (http/get (str *examples-api* ns "/"
  72
+                                              (fixup-name-url name))))))
59 73
 
60 74
 
61 75
 (defmacro examples
@@ -75,12 +89,13 @@
75 89
     (doseq [ex (:examples res)]
76 90
       (println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
77 91
       (println)
78  
-      (println " " (string/replace (:body ex) #"\n" "\n  "))
  92
+      (println " " (-> (remove-markdown (:body ex))
  93
+                       (string/replace #"\n" "\n  ")))
79 94
       (println)
80 95
       (println "  *** Last Updated:" (:updated_at ex))
81 96
       (println))
82 97
     (println "======================================== ^^^")
83  
-    (println (count res) "example(s) found for" (str ns "/" name))
  98
+    (println (count (:examples res)) "example(s) found for" (str ns "/" name))
84 99
     (println "Taken from" (:url res))))
85 100
 
86 101
 
@@ -103,7 +118,8 @@
103 118
 (defn comments-core
104 119
   "Return comments from clojuredocs for a given namespace and name (as strings)"
105 120
   [ns name]
106  
-  (json/decode-from-str (:body (http/get (str *comments-api* ns "/" name)))))
  121
+  (json/decode-from-str (:body (http/get (str *comments-api* ns "/"
  122
+                                              (fixup-name-url name))))))
107 123
 
108 124
 
109 125
 (defmacro comments
@@ -117,7 +133,7 @@
117 133
 (defn pr-comments-core
118 134
   "Given a namespace and name (as strings), pretty-print all the comments for it from clojuredocs"
119 135
   [ns name]
120  
-  (let [res (comments ns name)]
  136
+  (let [res (comments-core ns name)]
121 137
     (println)
122 138
     (println "======================================== vvv")
123 139
     (doseq [ex res]
@@ -146,7 +162,8 @@
146 162
 (defn see-also-core
147 163
   "Return 'see also' info from clojuredocs for a given namespace and name (as strings)"
148 164
   ([ns name]
149  
-     (json/decode-from-str (:body (http/get (str *seealso-api* ns "/" name))))))
  165
+     (json/decode-from-str (:body (http/get (str *seealso-api* ns "/"
  166
+                                                 (fixup-name-url name)))))))
150 167
 
151 168
 
152 169
 (defmacro see-also

0 notes on commit 2a02420

Please sign in to comment.
Something went wrong with that request. Please try again.