Permalink
Browse files

release 0.3.1, clojure 1.3 compat

  • Loading branch information...
dakrone committed Oct 17, 2011
1 parent bd3df45 commit d7c08118925b0335eea722da4b7434c735a37fe5
Showing with 34 additions and 24 deletions.
  1. +3 −3 README.markdown
  2. +2 −3 project.clj
  3. +29 −18 src/cd_client/core.clj
View
@@ -29,14 +29,14 @@ Search for a method using just the name or a namespace and name.
Comments works just like examples do, with strings, a symbol, and
pretty-printing.
- (comments "clojure.contrib.json" "read-json")
+ (comments "clojure.java.io" "reader")
(comments read-json)
(pr-comments read-json) ; pretty-prints the comments
See-also works with either strings for ns/name or a symbol.
(see-also "clojure.test" "are")
- (see-also are)
+ (see-also map)
Browse to the url for a method in your default browser:
@@ -47,7 +47,7 @@ Browse to the url for a method in your default browser:
For Leiningen:
- [org.thnetos/cd-client "0.3.0"]
+ [org.thnetos/cd-client "0.3.1"]
## Installation
View
@@ -1,6 +1,5 @@
-(defproject org.thnetos/cd-client "0.3.0"
+(defproject org.thnetos/cd-client "0.3.1"
:description "A client for the clojuredocs API"
:dependencies [[org.clojure/clojure "1.3.0"]
[clj-http "0.2.1"]
- [org.clojure/data.json "0.1.2"]]
- :dev-dependencies [[swank-clojure "1.2.1"]])
+ [cheshire "2.0.2"]])
View
@@ -1,13 +1,13 @@
(ns cd-client.core
- (:require [clojure.data.json :as json]
+ (:use [clojure.java.browse :only [browse-url]])
+ (:require [cheshire.core :as json]
[clj-http.client :as http]
- [clojure.string :as string])
- (:use [clojure.java.browse :only [browse-url]]))
+ [clojure.string :as string]))
-; For testing purposes use localhost:8080
+;; For testing purposes use localhost:8080
(def ^:dynamic *clojuredocs-root* "http://api.clojuredocs.org")
-;(def ^:dynamic *clojuredocs-root* "http://localhost:8080")
+;;(def ^:dynamic *clojuredocs-root* "http://localhost:8080")
(def ^:dynamic *examples-api* (str *clojuredocs-root* "/examples/"))
(def ^:dynamic *search-api* (str *clojuredocs-root* "/search/"))
@@ -16,7 +16,8 @@
(defn- fixup-name-url
- "Replace some special characters in symbol names in order to construct a URL that works on clojuredocs.org"
+ "Replace some special characters in symbol names in order to construct a URL
+ that works on clojuredocs.org"
[name]
(-> name
(string/replace "." "_dot")
@@ -61,7 +62,7 @@
`(call-with-ns-and-name ~fn (var ~name))))))
(defn- get-simple [url]
- (json/read-json (:body (http/get url {:accept-encoding ""}))))
+ (json/decode (:body (http/get url {:accept-encoding ""})) true))
(defn examples-core
"Return examples from clojuredocs for a given namespace and name (as strings)"
@@ -70,15 +71,17 @@
(defmacro examples
- "Return examples from clojuredocs for a given (unquoted) var, fn, macro, special form, or a namespace and name (as strings)"
+ "Return examples from clojuredocs for a given (unquoted) var, fn, macro,
+ special form, or a namespace and name (as strings)"
([name]
`(handle-fns-etc ~name examples-core))
([ns name]
`(examples-core ~ns ~name)))
(defn pr-examples-core
- "Given a namespace and name (as strings), pretty-print all the examples for it from clojuredocs"
+ "Given a namespace and name (as strings), pretty-print all the examples for it
+ from clojuredocs"
[ns name]
(let [res (examples-core ns name)]
(println)
@@ -97,7 +100,8 @@
(defmacro pr-examples
- "Given an (unquoted) var, fn, macro, special form, or a namespace and name (as strings), pretty-print all the examples for it from clojuredocs"
+ "Given an (unquoted) var, fn, macro, special form, or a namespace and name (as
+ strings), pretty-print all the examples for it from clojuredocs"
([name]
`(handle-fns-etc ~name pr-examples-core))
([ns name]
@@ -117,15 +121,17 @@
(defmacro comments
- "Return comments from clojuredocs for a given (unquoted) var, fn, macro, special form, or namespace and name (as strings)"
+ "Return comments from clojuredocs for a given (unquoted) var, fn, macro,
+ special form, or namespace and name (as strings)"
([name]
`(handle-fns-etc ~name comments-core))
([ns name]
`(comments-core ~ns ~name)))
(defn pr-comments-core
- "Given a namespace and name (as strings), pretty-print all the comments for it from clojuredocs"
+ "Given a namespace and name (as strings), pretty-print all the comments for it
+ from clojuredocs"
[ns name]
(let [res (comments-core ns name)]
(println)
@@ -141,41 +147,46 @@
(println))
(println "======================================== ^^^")
(println (count res) "comment(s) found for" (str ns "/" name))
- ; no URL in comments yet
+ ;; no URL in comments yet
#_(println "Taken from" (:url res))))
(defmacro pr-comments
- "Given a (unquoted) var, fn, macro, special form, or a namespace and name (as strings), pretty-print all the comments for it from clojuredocs"
+ "Given a (unquoted) var, fn, macro, special form, or a namespace and name (as
+ strings), pretty-print all the comments for it from clojuredocs"
([name]
`(handle-fns-etc ~name pr-comments-core))
([ns name]
`(pr-comments-core ~ns ~name)))
(defn see-also-core
- "Return 'see also' info from clojuredocs for a given namespace and name (as strings)"
+ "Return 'see also' info from clojuredocs for a given namespace and name
+ (as strings)"
([ns name]
(get-simple (str *seealso-api* ns "/" (fixup-name-url name)))))
(defmacro see-also
- "Given a (unquoted) var, fn, macro, special form, or a namespace and name (as strings), show the 'see also' for it from clojuredocs"
+ "Given a (unquoted) var, fn, macro, special form, or a namespace and name (as
+ strings), show the 'see also' for it from clojuredocs"
([name]
`(handle-fns-etc ~name see-also-core))
([ns name]
`(see-also-core ~ns ~name)))
(defn browse-to-core
- "Open a browser to the clojuredocs page for a given namespace and name (as strings)"
+ "Open a browser to the clojuredocs page for a given namespace and name
+ (as strings)"
([ns name]
(when-let [url (:url (examples ns name))]
(browse-url url))))
(defmacro browse-to
- "Given a (unquoted) var, fn, macro, or special form, or a namespace and name (as strings), open a browser to the clojuredocs page for it"
+ "Given a (unquoted) var, fn, macro, or special form, or a namespace and name
+ (as strings), open a browser to the clojuredocs page for it"
([name]
`(handle-fns-etc ~name browse-to-core))
([ns name]

0 comments on commit d7c0811

Please sign in to comment.