Skip to content

Commit

Permalink
Add fn fixup-name-url so names with . ? / can be looked up
Browse files Browse the repository at this point in the history
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 09a5e52
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cd_client/core.clj
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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))))


Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09a5e52

Please sign in to comment.