Permalink
Browse files

Add fn fixup-name-url so names with . ? / can be looked up

fixup-name-url is called when creating URLs to retreive from
clojuredocs.org.  It expects symbols with a few special characters in
them like . ? / to be replaced with other strings.

Without this change, symbols like string? and .. cannot be searched
for, and symbols like char? will return results for char instead.
  • Loading branch information...
jafingerhut committed Feb 25, 2011
1 parent 4fd3086 commit 09a5e52c07111658efc0a1ee493aaa5985ff9753
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/cd_client/core.clj
View
@@ -15,6 +15,15 @@
(def *seealso-api* (str *clojuredocs-root* "/see-also/"))
+(defn- fixup-name-url
+ "Replace some special characters in symbol names in order to construct a URL that works on clojuredocs.org"
+ [name]
+ (-> name
+ (string/replace "." "_dot")
+ (string/replace "?" "_q")
+ (string/replace "/" "_")))
+
+
(defn remove-markdown
"Remove basic markdown syntax from a string."
[text]
@@ -55,7 +64,8 @@
(defn examples-core
"Return examples from clojuredocs for a given namespace and name (as strings)"
[ns name]
- (json/decode-from-str (:body (http/get (str *examples-api* ns "/" name)))))
+ (json/decode-from-str (:body (http/get (str *examples-api* ns "/"
+ (fixup-name-url name))))))
(defmacro examples
@@ -80,7 +90,7 @@
(println " *** Last Updated:" (:updated_at ex))
(println))
(println "======================================== ^^^")
- (println (count res) "example(s) found for" (str ns "/" name))
+ (println (count (:examples res)) "example(s) found for" (str ns "/" name))
(println "Taken from" (:url res))))
@@ -103,7 +113,8 @@
(defn comments-core
"Return comments from clojuredocs for a given namespace and name (as strings)"
[ns name]
- (json/decode-from-str (:body (http/get (str *comments-api* ns "/" name)))))
+ (json/decode-from-str (:body (http/get (str *comments-api* ns "/"
+ (fixup-name-url name))))))
(defmacro comments
@@ -146,7 +157,8 @@
(defn see-also-core
"Return 'see also' info from clojuredocs for a given namespace and name (as strings)"
([ns name]
- (json/decode-from-str (:body (http/get (str *seealso-api* ns "/" name))))))
+ (json/decode-from-str (:body (http/get (str *seealso-api* ns "/"
+ (fixup-name-url name)))))))
(defmacro see-also

0 comments on commit 09a5e52

Please sign in to comment.