Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better naming around selection, quick and dirty table headers for ref…

…lection
  • Loading branch information...
commit 13a7e5dbbc8b2de61fea80c143542a734a42faf3 1 parent 1f1836c
@stuarthalloway stuarthalloway authored
View
2  src/mycroft/breadcrumb.clj
@@ -41,7 +41,7 @@
(map (fn [partial-selector]
[:span
" » "
- [:a {:href (url {:selector partial-selector})}
+ [:a {:href (url {:selectors partial-selector})}
(breadcrumb-text (last partial-selector)) ]])))
[:span " » " (breadcrumb-text (last selector))]]))])
View
30 src/mycroft/class.clj
@@ -1,25 +1,35 @@
(ns mycroft.class
- (:use [mycroft.data :only (select render-type)])
+ (:use [mycroft.data :only (select-in render-type)])
(:require [mycroft.reflect :as reflect]
[mycroft.breadcrumb :as breadcrumb]))
-(defn member-selector?
- [selector]
- (contains? #{[:fields] [:methods] [:constructors]} selector))
+(defmulti customize-options
+ (fn [options selectors] selectors))
+
+(defmethod customize-options :default [options & _] options)
+
+(defmethod customize-options [:fields]
+ [options _]
+ (assoc options :headers [:name :type :modifiers]))
+
+(defmethod customize-options [:methods]
+ [options _]
+ (assoc options :headers [:name :parameter-types :return-type :modifiers]))
+
+(defmethod customize-options [:constructors]
+ [options _]
+ (assoc options :headers [:name :parameter-types :modifiers]))
(defn render
[classname options]
(let [cls (Class/forName classname)
obj (reflect/reflect cls)
- selector (:selector options)
- selection (select obj selector)
- options (if (member-selector? selector)
- (assoc options :headers [:name :modifiers])
- options)]
+ selectors (:selectors options)
+ selection (select-in obj selectors)]
[:div
[:div {:id "breadcrumb"}
(breadcrumb/top-link)
[:span " « "
(str "class " classname)]]
[:div
- (render-type selection options)]]))
+ (render-type selection (customize-options options selectors))]]))
View
41 src/mycroft/data.clj
@@ -20,9 +20,9 @@
(defn add-selector
[options s]
- (let [options (if (:selector options)
- (update-in options [:selector] conj s)
- (assoc options :selector [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))]
@@ -71,33 +71,43 @@
(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 magic key mycroft.data/meta to metadata
+ * follows mycroft.data/deref to indirect through reference"
[item selectors]
- (reduce
- (fn [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)))
+ (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:
- :selector : vector is passed to select to drill in
+ :selectors : vector is passed to select to drill in
:meta : true to look at metadata instead of data
:start : start at the nth item
:count : how many items to show"
[var options]
- (let [selector (:selector options)
- selection (select var selector)]
+ (let [selectors (:selectors options)
+ selection (select-in var selectors)]
[:div
(breadcrumb/render (.ns var) var options)
[:div.buttons
@@ -188,7 +198,6 @@
[:tbody
~@(map
(fn [o]
- (println o)
(render-row-matching-headers o options))
content)]])
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/url {:selector [:mycroft.data/deref :mycroft.data/deref (dec (count (swap! history conj obj)))]})))
+ (breadcrumb/url {:selectors [:mycroft.data/deref :mycroft.data/deref (dec (count (swap! history conj obj)))]})))
View
4 src/mycroft/server.clj
@@ -60,8 +60,8 @@
to data structures as needed."
[options]
(let [options (keywordize-keys options)
- options (if (:selector options)
- (update-in options [:selector] read-string)
+ options (if (:selectors options)
+ (update-in options [:selectors] read-string)
options)
options (if (:start options)
(update-in options [:start] parse-start)
Please sign in to comment.
Something went wrong with that request. Please try again.