Permalink
Browse files

wip

  • Loading branch information...
1 parent 3b7ea01 commit df257c2c70e18ef5f17fc45d3767ee9da77cb3d5 @stuarthalloway stuarthalloway committed Sep 27, 2010
Showing with 116 additions and 90 deletions.
  1. +19 −1 resources/public/stylesheets/mobile.css
  2. +40 −21 src/mycroft/breadcrumb.clj
  3. +6 −8 src/mycroft/class.clj
  4. +2 −60 src/mycroft/data.clj
  5. +49 −0 src/mycroft/selector.clj
@@ -84,7 +84,7 @@ pre code{
white-space: pre-wrap;
}
#breadcrumb {
- margin: 10px;
+ margin: 10px 10px 0px 10px;
background: #ebebeb;
padding: 5px 7px;
border: 1px solid #ccc;
@@ -96,6 +96,24 @@ pre code{
color: #3D5A96;
}
+#options {
+ text-align: center;
+ margin: 0px 15px 10px 15px;
+ background: #ebebeb;
+ padding: 5px 7px;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+}
+
+#options a:link,
+#options a:visited {
+ color: #3D5A96;
+}
+
+#options span {
+ margin: 0px 10px;
+}
+
.buttons {
padding: 5px;
}
View
@@ -1,6 +1,8 @@
(ns mycroft.breadcrumb
- (:use [hiccup.page-helpers :only (encode-params)]
- [hiccup.core :only (escape-html)]))
+ (:use mycroft.selector
+ [hiccup.page-helpers :only (encode-params)]
+ [hiccup.core :only (escape-html)])
+ (:require [mycroft.docs :as docs]))
(defn options->query-string
"Generate query string for the options provided. Options include
@@ -63,24 +65,41 @@
(get {:mycroft.data/deref "@" :mycroft.data/meta "<meta>"} selector-component selector-component))
(defn render
- [ns var {:keys [selectors]}]
- [:div {:id "breadcrumb"}
- (if ns (top-link) "top")
- (when ns
- [:span " « "
- (if var (link-to ns) ns)])
- (when var
- [:span " / "
- (if selectors (link-to var) (link-name var))])
+ [item options selection]
+ (let [ns (when (var? item) (.ns item))
+ var (when (var? item) item)
+ classname (when (class? item) (.getName item))
+ selectors (:selectors options)]
+ [:div
+ [:div {:id "breadcrumb"}
+ (if ns (top-link) "top")
+ (when ns
+ [:span " « "
+ (if var (link-to ns) ns)])
+ (when classname
+ [:span " « "
+ (str "class " classname)])
+ (when var
+ [:span " / "
+ (if selectors (link-to var) (link-name var))])
- (when selectors
- (let [first-crumb (if (= ::deref (first selectors)) 2 1)]
- [:span
- (->> (map (fn [n] (subvec selectors 0 n)) (range first-crumb (count selectors)))
- (map (fn [partial-selectors]
- [:span
- " » "
- [:a {:href (str "?" (options->query-string {:selectors partial-selectors}))}
- (breadcrumb-text (last partial-selectors)) ]])))
- [:span " » " (breadcrumb-text (last selectors))]]))])
+ (when selectors
+ (let [first-crumb (if (= ::deref (first selectors)) 2 1)]
+ [:span
+ (->> (map (fn [n] (subvec selectors 0 n)) (range first-crumb (count selectors)))
+ (map (fn [partial-selectors]
+ [:span
+ " » "
+ [:a {:href (str "?" (options->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"]])
+ (when-let [class (and selection (.getClass selection))]
+ [:span (link-to class)])
+ (when-let [doc-url (docs/doc-url selection)]
+ [:span
+ [:a {:href doc-url} "api docs"]])]]))
View
@@ -1,19 +1,17 @@
(ns mycroft.class
- (:use [mycroft.data :only (select-in render-type)])
+ (:use [mycroft.data :only (render-type)]
+ mycroft.selector)
(:require [mycroft.reflect :as reflect]
[mycroft.breadcrumb :as breadcrumb]))
(defn render
- [classname options]
- (let [cls (Class/forName classname)
+ [classname options selection]
+ (let [cls (when classname (Class/forName classname))
obj (reflect/members cls)
- selectors (:selectors options)
- selection (select-in obj selectors)]
+ selectors (:selectors options)]
[:div
[:div {:id "breadcrumb"}
- (breadcrumb/top-link)
- [:span " « "
- (str "class " classname)]]
+ (breadcrumb/render cls options)]
[:div
(render-type {:superclasses (supers cls)}
{})]
View
@@ -1,5 +1,6 @@
(ns mycroft.data
(:use clojure.pprint
+ mycroft.selector
[hiccup.core :only (escape-html)])
(:require [mycroft.docs :as docs]
[mycroft.breadcrumb :as breadcrumb]))
@@ -12,26 +13,6 @@
[s]
(map vector (iterate inc 0) s))
-(defn special-selector?
- "Keywords in the mycroft.data namespace are interpreted specially,
- instead of just drilling further into the collection by index or
- key."
- [selector]
- (and (keyword? selector)
- (= (namespace selector) "mycroft.data")))
-
-(defn add-selector
- "Update the options by adding a selector to the end of the
- selectors already included."
- [options s]
- (let [options (if (:selectors options)
- (update-in options [:selectors] conj s)
- (assoc options :selectors [s]))
- options (if (special-selector? s)
- options
- (dissoc options :start))]
- (dissoc options :headers)))
-
(declare render-collection render-string)
(defmulti keyed class)
@@ -75,33 +56,6 @@
(prefer-method render-type clojure.lang.IPersistentCollection java.util.Collection)
-(defn select
- [item sel]
- (cond
- (= sel ::deref) @item
- (= sel ::meta) (meta item)
- (associative? item) (get item sel)
- (set? item) (nth (seq item) sel)
- (integer? sel) (nth item sel)))
-
-(defn select-in
- "Like get-in on steroids.
-
- * basic get-in behavior, plus
- * uses nth to follow (in O(n) time!) lazy sequences.
- * follows magic key mycroft.data/meta to metadata
- * follows mycroft.data/deref to indirect through reference"
- [item selectors]
- (reduce select
- item
- selectors))
-
-#_(defn selections-in
- "Like select-in, but returns vector of the
- intermediate steps."
- [item selectors]
- (vec (reductions select item selectors)))
-
(defn render
"Given a var and some options, render the var
as html. Options:
@@ -113,19 +67,7 @@
(let [selectors (:selectors options)
selection (select-in var selectors)]
[:div
- (breadcrumb/render (.ns var) var options)
- [:div.buttons
- (if (meta selection)
- [:span
- [:a {:href (str "?" (breadcrumb/options->query-string (add-selector options ::meta)))} "metadata"]]
- [:span.disabled-button "metadata"])
- (if-let [class (.getClass selection)]
- [:span (breadcrumb/link-to class)]
- [:span.disabled-button "no class"])
- (if-let [doc-url (docs/doc-url selection)]
- [:span
- [:a {:href doc-url} "api docs"]]
- [:span.disabled-button "api docs"])]
+ (breadcrumb/render var options selection)
(render-type selection options)]))
(defn render-string
View
@@ -0,0 +1,49 @@
+(ns mycroft.selector)
+
+(defn special-selector?
+ "Keywords in the mycroft.data namespace are interpreted specially,
+ instead of just drilling further into the collection by index or
+ key."
+ [selector]
+ (and (keyword? selector)
+ (= (namespace selector) "mycroft.data")))
+
+(defn add-selector
+ "Update the options by adding a selector to the end of the
+ selectors already included."
+ [options s]
+ (let [options (if (:selectors options)
+ (update-in options [:selectors] conj s)
+ (assoc options :selectors [s]))
+ options (if (special-selector? s)
+ options
+ (dissoc options :start))]
+ (dissoc options :headers)))
+
+(defn select
+ [item sel]
+ (cond
+ (= sel ::deref) @item
+ (= sel ::meta) (meta item)
+ (associative? item) (get item sel)
+ (set? item) (nth (seq item) sel)
+ (integer? sel) (nth item sel)))
+
+(defn select-in
+ "Like get-in on steroids.
+
+ * basic get-in behavior, plus
+ * uses nth to follow (in O(n) time!) lazy sequences.
+ * follows magic key mycroft.data/meta to metadata
+ * follows mycroft.data/deref to indirect through reference"
+ [item selectors]
+ (reduce select
+ item
+ selectors))
+
+#_(defn selections-in
+ "Like select-in, but returns vector of the
+ intermediate steps."
+ [item selectors]
+ (vec (reductions select item selectors)))
+

0 comments on commit df257c2

Please sign in to comment.