Browse files

funkier row formats

treats a map as a series of tuples (where each tuple has two entries,
:key and :val), and treats vectors as maps of their indices
  • Loading branch information...
1 parent 5dace7c commit c3f71715a353993b2729cd58ab37f822bc28ecaf @joegallo committed Jan 14, 2013
Showing with 18 additions and 3 deletions.
  1. +18 −3 src/doric/core.clj
@@ -22,7 +22,10 @@
(defn title [col & [data]]
(or (:title col)
- (.replaceAll (clojure.core/name (:name col))
+ (.replaceAll (clojure.core/name (let [n (:name col)]
+ (if (number? n)
+ (str n)
+ n)))
"-" " "))))
(defn title-align [col & [data]]
@@ -128,17 +131,29 @@
(defn unaligned-td [col row]
(row (:name col)))
+(defn mapify [rows]
+ (let [example (first rows)]
+ (cond (map? rows) (for [k (sort (keys rows))]
+ {:key k :val (rows k)} )
+ (vector? example) (for [row rows]
+ (into {}
+ (map-indexed (fn [i x] [i x]) row)))
+ (map? example) rows)))
(defn table*
- (table* (vary-meta (or (keys (first rows)) [])
- merge (meta rows)) rows))
+ (let [meta (meta rows)
+ rows (mapify rows)
+ cols (or (keys (first rows)) [])]
+ (table* (with-meta cols meta) rows)))
([cols rows]
(let [meta (meta cols)
format (or (:format meta) org)
_ (require format)
th (ns-resolve format 'th)
td (ns-resolve format 'td)
render (ns-resolve format 'render)
+ rows (mapify rows)
cols (columns1 cols rows)
rows (format-rows cols rows)
cols (columns2 cols rows)]

0 comments on commit c3f7171

Please sign in to comment.