Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More fixes

  • Loading branch information...
commit feb0d5bb45fa662c0baa5eb18cb4ae99c658ea08 1 parent 2c567f9
@abedra abedra authored
View
12 src/mycroft/breadcrumb.clj
@@ -4,14 +4,14 @@
[hiccup.core :only (escape-html)])
(:require [mycroft.docs :as docs]))
-(defn options->query-string
- "Generate query string for the options provided. Options include
+(defn params->query-string
+ "Generate query string for the params provided. Params include
:selectors vector of selectors for select-in
:start first item to show (for pagination)
:headers explicitly select table headers."
- [options]
- (encode-params options))
+ [params]
+ (encode-params (select-keys params [:selectors :start :headers])))
(defprotocol Resource
(url-for [o])
@@ -90,13 +90,13 @@
(map (fn [partial-selectors]
[:span
" » "
- [:a {:href (str "?" (options->query-string {:selectors partial-selectors}))}
+ [:a {:href (str "?" (params->query-string {:selectors partial-selectors}))}
(breadcrumb-text (last partial-selectors)) ]])))
[:span " » " (breadcrumb-text (last selectors))]]))]
[:div#options
(when (meta selection)
[:span
- [:a {:href (str "?" (options->query-string (add-selector options ::meta)))} "metadata"]])
+ [:a {:href (str "?" (params->query-string (add-selector options :mycroft/meta)))} "metadata"]])
(when-let [class (and selection (.getClass selection))]
[:span (link-to class)])
(when-let [doc-url (docs/doc-url selection)]
View
17 src/mycroft/class.clj
@@ -6,22 +6,17 @@
[mycroft.breadcrumb :as breadcrumb]))
(defn render
- [cls options selection]
+ [cls n-params selection]
(info "Class" cls)
- (info "Options" options)
(info "Selection" selection)
(let [obj (reflect/members cls)
- selectors (:selectors options)
+ selectors (:selectors n-params)
selection (select-in obj selectors)]
[:div
- [:div {:id "breadcrumb"} (breadcrumb/render cls options selection)]
+ [:div {:id "breadcrumb"} (breadcrumb/render cls n-params selection)]
[:div (render-type {:superclasses (supers cls)} {})]
[:div (render-type selection
(if selectors
- (do
- (info "selectors present" options)
- options)
- (do
- (info "selectors not present")
- (assoc options :headers
- [:name :type :parameter-types :return-type :modifiers :declaring-class]))))]]))
+ n-params
+ (assoc n-params :headers
+ [:name :type :parameter-types :return-type :modifiers :declaring-class])))]]))
View
31 src/mycroft/data.clj
@@ -37,30 +37,22 @@
(defmulti render-type (fn [type options] (tag type)))
(defmethod render-type nil [this options]
- (info "NIL")
(render-type "<nil>" options))
(defmethod render-type :Array [this options]
- (info "Array")
(render-type (seq this) options))
(defmethod render-type java.util.Collection [this options]
- (info "Collection")
(render-collection this options))
(defmethod render-type clojure.lang.ISeq [this options]
- (info "ISeq")
(render-collection this options))
(defmethod render-type clojure.lang.IPersistentCollection [this options]
- (info "IPersistentCollection")
(render-collection this options))
(defmethod render-type clojure.lang.IRef [this options]
- (info "IRef")
(render-type @this (add-selector options :mycroft/deref)))
(defmethod render-type clojure.lang.Var [this options]
- (info "Var")
(if (fn? (safe-deref this))
(docs/render this options)
(render-type (safe-deref this) (add-selector options :mycroft/deref))))
(defmethod render-type :default [this options]
- (info "Default")
(render-string this options))
(prefer-method render-type clojure.lang.IPersistentCollection java.util.Collection)
@@ -104,7 +96,7 @@
[row options]
{:pre (= 2 (count row))}
`[:tr
- ~(render-cell (first row) {:href (str "?" (breadcrumb/options->query-string (add-selector options (first row))))})
+ ~(render-cell (first row) {:href (str "?" (breadcrumb/params->query-string (add-selector options (first row))))})
~@(map render-cell (rest row))])
(defn render-row-matching-headers
@@ -112,7 +104,7 @@
{:pre [(= 2 (count row))
(associative? obj)]}
`[:tr
- ~(render-cell key {:href (str "?" (breadcrumb/options->query-string (add-selector options key)))})
+ ~(render-cell key {:href (str "?" (breadcrumb/params->query-string (add-selector options key)))})
~@(let [explicit-columns (map #(% obj) headers)]
(map render-cell explicit-columns))
~(let [rest-of-object (apply dissoc obj headers)]
@@ -129,23 +121,23 @@
(def items-per-page 15)
(defn render-pagination
- [{:keys [start] :as options} count has-more?]
+ [{:keys [start] :as params} count has-more?]
(info "Pagination Count:" count)
- (info "Pagination Options:" options)
+ (info "Pagination Options:" params)
(info "Pagination Has More?:" has-more?)
(info "Pagination Start:" start)
(when (or (not count)
(> count items-per-page))
[:div.buttons {:id "pagination"}
- ;; (if (> start 0)
- ;; [:a {:href (str "?" (breadcrumb/options->query-string (update-in options [:start] - items-per-page)))}
- ;; "prev"]
- ;; [:span.disabled-button "prev"])
+ (if (> start 0)
+ [:a {:href (str "?" (breadcrumb/params->query-string (update-in params [:start] - items-per-page)))}
+ "prev"]
+ [:span.disabled-button "prev"])
(when count
[:span
(str "Items " start "-" (min count (+ start items-per-page)) " of " count)])
(if has-more?
- [:a {:href (str "?" (breadcrumb/options->query-string (update-in options [:start] + 0 items-per-page)))}
+ [:a {:href (str "?" (breadcrumb/params->query-string (update-in params [:start] + items-per-page)))}
"next"]
[:span.disabled-button "next"])]))
@@ -182,9 +174,8 @@
content (take items-per-page content)]
(if (composite? content)
[:div
- (render-table content options)]
- ;; Currently broken because of missing start
- ;; (render-pagination options count has-more?)]
+ (render-table content options)
+ (render-pagination options count has-more?)]
(render-type content options))))
View
1  src/mycroft/handlers.clj
@@ -11,3 +11,4 @@
"\n\tSession " (:session request)))
response))))
+
View
2  src/mycroft/history.clj
@@ -7,7 +7,7 @@
"Add an object to history, returning its URL."
[obj]
(str "/vars/mycroft.history/history?"
- (breadcrumb/options->query-string {:selectors [:mycroft/deref :mycroft/deref (dec (count (swap! history conj obj)))]})))
+ (breadcrumb/params->query-string {:selectors [:mycroft/deref :mycroft/deref (dec (count (swap! history conj obj)))]})))
View
28 src/mycroft/layouts/application.clj
@@ -27,21 +27,33 @@
(defn namespaces []
(minib-layout "Namespaces" (namespace/browser)))
-(defn classes [params query-params]
- (info "params" params)
- (info "query-params" query-params)
+(defn read-param-string
+ "Use Clojure reader to read a param strings, or return
+ default is param string empty/nil."
+ ([s] (read-param-string s nil))
+ ([s default]
+ (if (seq s)
+ (read-string s)
+ default)))
+
+(defn normalize-params
+ [params]
+ (-> params
+ (update-in [:selectors] read-param-string)
+ (update-in [:headers] read-param-string)
+ (update-in [:start] read-param-string 0)))
+
+(defn classes [params]
(let [classname (:* params)
cls (Class/forName classname)]
(minib-layout classname
- (class/render cls query-params cls))))
+ (class/render cls (normalize-params params) cls))))
-(defn vars [params query-params]
- (info "params" params)
- (info "query-params" query-params)
+(defn vars [params]
(let [qname (:* params)
[ns var] (split qname #"/")]
(namespace/safe-load-ns ns)
(minib-layout qname
(if var
- (data/render (find-var (symbol qname)) query-params)
+ (data/render (find-var (symbol qname)) (normalize-params params))
(namespace/var-browser ns)))))
View
11 src/mycroft/server.clj
@@ -16,8 +16,9 @@
(defroutes base-routes
(GET "/vars" [] (layout/namespaces))
- (GET "/vars/*" {:keys [params query-params]} (layout/vars params query-params))
- (GET "/classes/*" {:keys [params query-params]} (layout/classes params query-params))
+ (GET "/foo" request (prn request))
+ (GET "/vars/*" {:keys [params]} (layout/vars params))
+ (GET "/classes/*" {:keys [params]} (layout/classes params))
(route/files "/")
(route/not-found "not found"))
@@ -35,10 +36,10 @@
(defrecord Instance [port]
Inspector
(launch [_]
- (run-jetty application {:port port
- :join? false}))
+ (run-jetty (var application) {:port port
+ :join? false}))
(inspect [_ obj options]
- (let [query (breadcrumb/options->query-string options)]
+ (let [query (breadcrumb/params->query-string options)]
(if (class? obj)
(browse-url (str "http://localhost:" port
"/classes/" (.getName obj) "?"
Please sign in to comment.
Something went wrong with that request. Please try again.