Commits

Kresimir Sojat  committed 3e0b3a8

First chunks of text in manual, example of circular dependency for cells and almost functional automatic rule creation in web added.

  • Participants
  • Parent commits b3ef461

Comments (0)

Files changed (4)

File docs/index.textile

 
 h1. Core functions and macros
 
-TODO: Add documentation!
+Main part of @neman.core@ library is @=>@ (builder) macro used for constructiong Java objects and there compositions. Usage of builder is similar to builtin @doto@ macro and @new@ special form with abbility to __inject__ new methods in existing Java classes, add __new constructors__, __override__ existing methods and (*TODO*).
 
+p(notice). There is no real injection of new methods and constructors, they are effective only inside builder macro.
+
+This is how you would construct a SWING menu for your app using builder macro (configured with @neman.swing@):
+
+pre.. 
+ (ns user
+   (:import (javax.swing JMenuBase JMenu JMenuItem JSeparator))
+   (:require net.ksojat.neman.swing)
+   (:use net.ksojat.neman.core))
+
+ (def m
+   (=> (JMenuBar.)
+     [(=> [JMenu "&File"]
+        [(=> [JMenuItem "&New [ctrl n]"])
+         (=> [JMenuItem "&Open [ctrl o]"])
+         (=> [JMenuItem "&Save [ctrl s]"]
+           :Enabled false)
+         (JSeparator.)
+         (=> [JMenuItem "&Exit [ctrl q]"])])
+       (=> [JMenu "&Edit"]
+         [(=> [JMenuItem "Cu&t [ctrl x]"])
+          (=> [JMenuItem "&Copy [ctrl c]"])
+          (=> [JMenuItem "&Paste [ctrl v]"])])]))
+p. Equivalent code using @doto@ and @new@ could be written as:
+
+pre.. 
+  (ns user
+    (:import (javax.swing JMenuBar JMenu JMenuItem JSeparator KeyStroke))
+
+  (def m
+    (doto (JMenuBar.)
+      (.add
+        (doto (JMenu. "File")
+          (.setMnemonic "f")
+          (.add
+            (doto (JMenuItem. "New")
+              (.setMnemonic "n")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl n"))))
+          (.add
+            (doto (JMenuItem. "Open")
+              (.setMnemonic "o")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl o"))))
+          (.add
+            (doto (JMenuItem. "Save")
+              (.setEnabled false)
+              (.setMnemonic "s")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl s"))))))
+      (.add
+        (doto (JMenu. "Edit")
+          (.setMnemonic "e")
+          (.add
+            (doto (JMenuItem. "Cut")
+              (.setMnemonic "t")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl x"))))
+          (.add
+            (doto (JMenuItem. "Copy")
+              (.setMnemonic "c")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl c"))))
+          (.add
+            (doto (JMenuItem. "Paste")
+              (.setMnemonic "p")
+              (.setAccelerator (KeyStroke/getKeyStroke "ctrl v"))))))))
 h1. XML and XML templates
 
-TODO: Add documentation!
+Neman XML library is thin wrapper around "JDOM":http://www.jdom.org/ using builder macro for DOM construction. This way you don't loose any capabilities of original JDOM API.
+
+pre.. 
+ (ns user
+   (:use
+     (net.ksojat.neman
+       core
+       [xml :only [xml]])))
+
+ (def simple-html-page
+   (xml
+     (=> :html
+       [(=> :head [(=> :title "Hello World!")])
+        (=> :body
+          [(=> :h1 "Hello World!")
+           (=> :p  "Example paragraph.")])])))
+
+p. Default methods for JDOM classes:
+|_.Class|_.Method|_.Default|
+(odd).|org.jdom.Document|setDocType|:string|
+(even).|org.jdom.Element|addContent|:vector|
+(odd).|org.jdom.Element|addContent|:string|
+(even).|org.jdom.Element|setAttributes|:map|
+
+p. Patched methods for JDOM classes:
+|_.Class|_.Method|_.Description|
+(odd).|org.jdom.Document|setDocType|Accepts @org.jdom.DocType@ or regular @java.lang.String@|
+(even).|org.jdom.Element|setAttributes|*TODO*|
+(odd).|org.jdom.Element|addContent|Accepts @java.util.List@ of @org.jdom.Content@ objects, single @org.jdom.Content@ object or anything that can be converted to String (it will be inserted as text node).|
+
+p. TODO: Add documentation!
 
 h1. Web library
 

File docs/style.css

     color: #215A6D;
 }
 
+p {
+    letter-spacing: 0.2px;
+    line-height: 1.5em;
+}
+
+.notice {
+    padding: 3px;
+    background-color: #CCCCCC;
+    border-left: 4px solid black;
+    font-size: 0.8em;
+}
+
 pre {
-    margin: 0 10px;
     padding: 5px;
     background-color: #FFFFF5;
     border-top: 1px solid #CDDAD9;
     border-bottom: 1px solid #CDDAD9;
+    border-left: 4px solid orange;
+    line-height: 1.4em;
 }
 
 code {
 .pagetitle {
     font-size: 2.3em;
     font-weight: bold;
-    text-align: center;
 }
+
+table {
+    border-spacing: 0;
+    border-collapse: collapse;
+    border: 1px solid #C72545;
+}
+
+th {
+    color: white;
+    background-color: #C72545;
+    text-align: left;
+    font-family: Monospace;
+    font-weight: normal;
+    padding: 2px;
+}
+
+td {
+    padding: 4px;
+}
+
+tr.odd {
+    background-color: #f8f8f8;
+}

File src/net/ksojat/neman/cells.clj

      (update#)
      cell#))
 
-(defmacro cell [parents bindings expr]
-  `(alter-cell (net.ksojat.neman.cells.Cell. {}) ~parents ~bindings ~expr))
+(defmacro cell
+  ([parents bindings expr]
+    `(alter-cell (net.ksojat.neman.cells.Cell. {}) ~parents ~bindings ~expr))
+  ([init-val]
+    `(net.ksojat.neman.cells.Cell. {:value ~init-val})))
 
 ;(defn add-trigger [cell trigger-fn]
 ;  (dosync
 
 (defn add-trigger [cell trigger-fn]
   (dosync
-    (alter (.state cell) assoc-in :triggers conj trigger-fn))
+    (alter (.state cell) update-in [:triggers] conj trigger-fn))
   trigger-fn)
 
 ;(defn remove-trigger [cell trigger-fn]
     (fn [old-v new-v]
       (println old-v)
       (println new-v)))
+
+  ; circular dependancies.
+  (def a (Cell. {:value 5}))
+  (def b (cell [a] [v] (dec v)))
+  (add-trigger a
+    (fn [old-v new-v]
+      (println (str "Cell a changed from: " old-v " to " new-v))))
+  (add-trigger b
+    (fn [old-v new-v]
+      (println (str "Cell b changed from: " old-v " to " new-v))))
+  (alter-cell a [b] [v] (if (< v 0) 0 v))
 )

File src/net/ksojat/neman/web.clj

     (when (seq rs) (recur url-path rs))))
 
 ;; TODO: Move to core
-;(defn tree-paths [tree]
-;  (let [paths (fn paths [parent children]
-;                (mapcat
-;                  (fn [[k v]]
-;                    (let [p (conj parent k)]
-;                      (if (map? v) (paths p v) [p v])))
-;                  children))]
-;    (paths [] tree)))
-
-;(defn tree-paths [tree]
-;  (let [paths (fn paths [parent children]
-;                (mapcat
-;                  (fn [[k v]]
-;                    (let [p (conj parent k)]
-;                      (if (branch? v) (paths p v) [p v])))
-;                  children))]
-;    (paths [] tree)))
-
 (defn tree-paths [branch? tree]
   (let [paths (fn paths [parent children]
                 (mapcat
                   children))]
     (paths [] tree)))
 
+;; TODO: Remove this
+(defn numerics-path? [path]
+  (some number? path))
+
 (defn auto-rules [paths rule-ex]
-  (let [paths           (tree-paths (complement view?) paths)
-        [rel-ex abs-ex] (split-with (fn [[k _]] (keyword? k)) rule-ex)]
-    (println paths)))
+  (let [paths           (filter
+                          (fn [[p _]] (not (numerics-path? p)))
+                          (partition 2 (tree-paths (complement view?) paths)))
+        [rel-ex abs-ex] (split-with (fn [[k _]] (keyword? k)) rule-ex)
+        rel-ex (into {} rel-ex)
+        abs-ex (sort-by first #(> (count %1) (count %2)) abs-ex)]
+    (into {}
+      (map
+        (fn [[path view]]
+          [path
+           (apply str "/"
+             (interpose "/"
+               (concat
+                 (filter #(not (empty? %)) (map #(get rel-ex % (name %)) path))
+                 (map #(str "<" % ">") (argument-names view)))))])
+        paths))))
+
+;; TODO: Add this
+(defn paths-vfn [new-state]
+  ; 1. Niti jedan view nesmije imati argumente koji imaju :internal flag na sebi
+  nil)
+
+(defn paths [x]
+  (ref x paths-vfn))
+
+;; TODO: Add this
+(defn rules-vfn [new-state]
+  nil)
+
+(defn rules
+  ([specs]
+    (ref specs rules-vfn))
+  ([paths ex]
+    (cell [paths] [v] (auto-rules v ex))))
 
 (defn mapper [paths rules]
   (let [routes (cell [paths rules] [p r] (create-routes p r))]