Browse files

Misc cleanup, release 0.2.1, more work needed

  • Loading branch information...
1 parent 9e6c386 commit 3ff6d6758adf2ddc5b25943eb1c413cfd82d767a @dakrone committed Jan 25, 2012
Showing with 48 additions and 47 deletions.
  1. +3 −6 project.clj
  2. +45 −41 src/cd_wsapi/core.clj
View
9 project.clj
@@ -1,13 +1,10 @@
-(defproject cd-wsapi "0.2.0"
+(defproject cd-wsapi "0.2.1"
:description "ClojureDocs External API"
- :dependencies [[org.clojure/clojure "1.2.0"]
+ :dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[mysql/mysql-connector-java "5.1.12"]
[aleph "0.1.0-SNAPSHOT"]
[net.cgrand/moustache "1.0.0-SNAPSHOT"]
[org.danlarkin/clojure-json "1.1"]]
- :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]
- [leiningen-init-script "1.2.0-SNAPSHOT"]]
- :lis-opts {:properties {:config-clj.env "prod"}
- :redirect-output-to "/var/log/cd-wsapi.log"}
+ :dev-dependencies []
:main main)
View
86 src/cd_wsapi/core.clj
@@ -8,19 +8,19 @@
(def *default-page* (slurp "resources/index.html"))
;;JSON Encoders
-(add-encoder
- java.util.Date
- (fn [#^java.util.Date date #^java.io.Writer writer
- #^String pad #^String current-indent
- #^String start-token-indent #^Integer indent-size]
- (.append writer (str start-token-indent \" date \"))))
+(add-encoder
+ java.util.Date
+ (fn [#^java.util.Date date #^java.io.Writer writer
+ #^String pad #^String current-indent
+ #^String start-token-indent #^Integer indent-size]
+ (.append writer (str start-token-indent \" date \"))))
;; Database
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
:subname "//localhost:3306/clojuredocs_development?user=cd_wsapi&password=cd_wsapi"
-; :subname "//localhost:3306/clojuredocs_production?user=cd_wsapi&password=cd_wsapi"
+ ; :subname "//localhost:3306/clojuredocs_production?user=cd_wsapi&password=cd_wsapi"
:create true
:username "cd_wsapi"
:password "cd_wsapi"})
@@ -114,21 +114,21 @@
{:status 200
:headers {"Content-Type" "application/json"}
:body (encode-to-str
- (with-connection db
- (transaction
- (when-let [functions (with-query-results rs queryvec (doall rs))]
- (map format-search functions)))))}))
+ (with-connection db
+ (transaction
+ (when-let [functions (with-query-results rs queryvec (doall rs))]
+ (map format-search functions)))))}))
(defn search
"Search for a method by name or namespace & name."
([name]
- (search nil name))
+ (search nil name))
([ns name]
(let [qv (if (nil? ns)
- [(str "select id,name,ns from flat_functions_view where name like '%" name "%'")]
- [(str "select id,name,ns from flat_functions_view where ns = ? and name like '%" name "%'") ns])]
- (perform-search qv))))
+ [(str "select id,name,ns from flat_functions_view where name like '%" name "%'")]
+ [(str "select id,name,ns from flat_functions_view where ns = ? and name like '%" name "%'") ns])]
+ (perform-search qv))))
(defn format-comment
@@ -145,16 +145,20 @@
(fn [n]
{:status 200
:headers {"Content-Type" "application/json"}
- :body (encode-to-str
- (with-connection db
- (transaction
- (when-let [comments (with-query-results
- rs
- (if version
- ["select * from flat_comments_view where ns = ? and function = ? and version = ?" ns name version]
- ["select * from flat_comments_view where ns = ? and function = ?" ns name])
- (doall rs))]
- (map format-comment comments)))))})))
+ :body (.replaceAll
+ (encode-to-str
+ (with-connection db
+ (transaction
+ (when-let
+ [comments
+ (with-query-results
+ rs
+ (if version
+ ["select * from flat_comments_view where ns = ? and function = ? and version = ?" ns name version]
+ ["select * from flat_comments_view where ns = ? and function = ?" ns name])
+ (doall rs))]
+ (map format-comment comments)))))
+ "\\\\r" "")})))
(defn format-see-also-function
@@ -168,12 +172,12 @@
"Given an id, format the function to see also."
[id]
(with-connection db
- (transaction
- (when-let [functions (with-query-results
- rs
- ["select * from functions where id = ?" (:to_id id)]
- (doall rs))]
- (format-see-also-function (first functions)))))) ; should only be 1 function per id
+ (transaction
+ (when-let [functions (with-query-results
+ rs
+ ["select * from functions where id = ?" (:to_id id)]
+ (doall rs))]
+ (format-see-also-function (first functions)))))) ; should only be 1 function per id
(defn see-also
@@ -183,18 +187,18 @@
{:status 200
:headers {"Content-Type" "application/json"}
:body (encode-to-str
- (with-connection db
- (transaction
- (when-let [see-also-ids (with-query-results
- rs
- ["select to_id from flat_see_alsos_view where ns = ? and function = ?" ns name]
- (doall rs))]
- (map format-see-also see-also-ids)))))}))
+ (with-connection db
+ (transaction
+ (when-let [see-also-ids (with-query-results
+ rs
+ ["select to_id from flat_see_alsos_view where ns = ? and function = ?" ns name]
+ (doall rs))]
+ (map format-see-also see-also-ids)))))}))
(defn app-handler [channel request]
- (enqueue-and-close
+ (enqueue-and-close
channel
((app
["examples" ns name] (examples ns name)
@@ -219,8 +223,8 @@
(defn restart-server []
- (server)
- (def server (start-http-server app-wrapper {:port *server-port*})))
+ (server)
+ (def server (start-http-server app-wrapper {:port *server-port*})))
(restart-server))

0 comments on commit 3ff6d67

Please sign in to comment.