 (defn template [tag style & more]
   (let [arr #js [tag (if (empty? style) #js {} #js {"style" style})]]
     (doseq [o more]
-      (.push arr o))
+      (if (seq? o)
+        (.apply (aget arr "push") arr (into-array o)) ; convenience helper to splat cljs-seqs
+        (.push arr o)))
     arr))
 
 (defn reference [object & more]

  (cond
    (map? value) (header-map-template value)
    (set? value) (header-set-template value)
    (seq? value) (header-seq-template value)
    ))

(defn inlined-value-template [value]


; TODO: abbreviate long strings
(defn string-template [value]
  (template "span" "color:#C41A16" (str dq value dq)))

(defn fn-template [value]
  (template "span" "color:#f00" (reference value) "fn"))

(defn header-inlined-templates [value renderer max]
  (let [rendered-items (apply concat (interpose [(spacer)] (map renderer (take max value))))]
    (if (> (count value) max)
      (concat rendered-items [abbreviation])
      rendered-items)))

(defn header-coll-template [value]
  (let [renderer (fn [item] [(inlined-value-template item)])
        items (header-inlined-templates value renderer max-coll-elements)]
    (template "span" "color:#000" "[" items "]")))

(defn header-map-template [value]
  (let [renderer (fn [[key value]] [(inlined-value-template key) (spacer) (inlined-value-template value)])
        items (header-inlined-templates value renderer max-map-elements)]
    (template "span" "color:#000" "{" items "}")))

(defn header-set-template [value]
  (let [renderer (fn [item] [(inlined-value-template item)])
        items (header-inlined-templates value renderer max-set-elements)]
    (template "span" "color:#000" "#{" items "}")))

(defn generic-template [value]
  (template "span" "color:#000" (reference value)))
