Permalink
Browse files

Non-semantic: Cursive and code formatting.

  • Loading branch information...
pupeno committed Aug 3, 2017
1 parent 5cedd99 commit cfe78b4b4b487d61c510416da84765e5f52d4d74
@@ -7,7 +7,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="false" project-jdk-name="IDE SDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>
@@ -1,18 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="lein doo chrome test auto" type="LeiningenRunConfiguration" factoryName="Leiningen" singleton="true">
<LeiningenRunnerParameters>
<option name="myGoals">
<list>
<option value="doo" />
<option value="chrome" />
<option value="test" />
<option value="auto" />
</list>
</option>
<option name="myWorkingDirectory" value="$PROJECT_DIR$" />
<option name="profiles" value="" />
<option name="trampoline" value="false" />
</LeiningenRunnerParameters>
<module name="free-form" />
<arguments argument="doo" />
<arguments argument="chrome" />
<arguments argument="test" />
<arguments argument="auto" />
<setting name="profiles" value="" />
<setting name="trampoline" value="false" />
<method />
</configuration>
</component>
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module cursive.leiningen.project.LeiningenProjectsManager.displayName="com.pupeno/free-form:0.6.0-SNAPSHOT" cursive.leiningen.project.LeiningenProjectsManager.isLeinModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/cljs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/cljs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/dev-resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/out" />
<excludeFolder url="file://$MODULE_DIR$/target" />
@@ -7,10 +7,10 @@
[free-form.util :refer [field? key->keys attributes-index]]))
(defn- extract-attributes [node key]
(let [attributes (get node attributes-index)
(let [attributes (get node attributes-index)
re-attributes (key attributes)
attributes (dissoc attributes key)
keys (or (:keys re-attributes) [(:key re-attributes)])]
attributes (dissoc attributes key)
keys (or (:keys re-attributes) [(:key re-attributes)])]
[attributes re-attributes keys]))
(defn- input? [node]
@@ -26,8 +26,8 @@
(defn- extract-event-value [event]
(if (or (boolean? event)
(string? event))
event ; React-toolbox generates events that already contain a stracted string of the value as the first paramenter
(js-event-value event))) ; for all other cases, we extract it ourselves.
event ; React-toolbox generates events that already contain a stracted string of the value as the first paramenter
(js-event-value event))) ; for all other cases, we extract it ourselves.
(defn- first-non-nil [& coll]
(first (filter (complement nil?) coll)))
@@ -38,20 +38,20 @@
(let [[attributes free-form-attributes keys] (extract-attributes node :free-form/input)
{:keys [value-on error-on extra-error-keys]} free-form-attributes
on-change-fn #(on-change keys (extract-event-value %1))
value-on (or value-on (case (:type attributes)
(:checkbox :radio) :default-checked
:value))
value (case (:type attributes)
:checkbox (= true (get-in values keys))
:radio (= (:value attributes) (get-in values keys))
(first-non-nil (get-in values keys) (:blank-value free-form-attributes) ""))
value-on (or value-on (case (:type attributes)
(:checkbox :radio) :default-checked
:value))
value (case (:type attributes)
:checkbox (= true (get-in values keys))
:radio (= (:value attributes) (get-in values keys))
(first-non-nil (get-in values keys) (:blank-value free-form-attributes) ""))
input-errors (get-in errors keys)]
(assoc node attributes-index
(cond-> attributes
true (assoc :on-change on-change-fn)
true (assoc value-on value)
(and error-on input-errors) (assoc error-on (clojure.string/join " " input-errors))
(and extra-error-keys (some #(get-in errors %) extra-error-keys)) (assoc error-on " "))))))
true (assoc :on-change on-change-fn)
true (assoc value-on value)
(and error-on input-errors) (assoc error-on (clojure.string/join " " input-errors))
(and extra-error-keys (some #(get-in errors %) extra-error-keys)) (assoc error-on " "))))))
(defn- error-class?
"Tests whether the node should be marked with an error class should the field have an associated error."
@@ -79,8 +79,8 @@
(let [[attributes _ keys] (extract-attributes node :free-form/error-message)]
(if-let [errors (get-in errors keys)]
(vec (concat
(drop-last (assoc node attributes-index attributes))
(map #(conj (get node 2) %) errors)))
(drop-last (assoc node attributes-index attributes))
(map #(conj (get node 2) %) errors)))
nil))))
(defn- warn-of-leftovers [node]
@@ -94,12 +94,12 @@
([values errors on-change html]
(form values errors on-change [] html))
([values errors on-change extensions html]
(let [errors (or errors {})
(let [errors (or errors {})
extensions (if (sequential? extensions) extensions [extensions])
inner-fn (fn [html]
(->> html
(postwalk #(bind-input values errors on-change %))
(postwalk #(bind-error-class errors %))
(postwalk #(bind-error-messages errors %))))]
inner-fn (fn [html]
(->> html
(postwalk #(bind-input values errors on-change %))
(postwalk #(bind-error-class errors %))
(postwalk #(bind-error-messages errors %))))]
(postwalk #(warn-of-leftovers %)
((reduce #(extension/extension %2 %1) inner-fn extensions) html)))))
@@ -5,12 +5,12 @@
[re-frame.core :as re-frame]))
(defn form [& args]
(let [event (nth args 2)
(let [event (nth args 2)
re-frame-event-generator (fn [keys value]
(let [event-v (cond
(fn? event) (event keys value)
(vector? event) (conj event keys value)
:else [event keys value])]
(re-frame/dispatch event-v)))
args (assoc (vec args) 2 re-frame-event-generator)]
args (assoc (vec args) 2 re-frame-event-generator)]
(into [core/form] args)))
@@ -110,11 +110,10 @@
[:div.errors {:free-form/error-message {:key :radio-buttons}} [:p.error]]]
[:button "Button"]]]
(testing "simple generation"
(let [generated-input (hide-on-change
(free-form/form {} {} (fn [_keys _value])
plain-reagent-form-template))]
(free-form/form {} {} (fn [_keys _value])
plain-reagent-form-template))]
(is (= generated-input
[:form {:noValidate true}
nil
@@ -227,17 +226,17 @@
(testing "generation with initial data"
(let [generated-input (hide-on-change
(free-form/form {:text "Text value"
:email "Email value"
:password "Password value"
;:select "cat" ; TODO: enable this and fix generation, as it's broken right now.
;:select-with-group "two" ; TODO: enable this and fix generation, as it's broken right now.
:textarea "Textarea value"
:t {:e {:x {:t "Text with deep keys value"}}}
:checkbox true
:radio-buttons "radio-option-2"
} {} (fn [_keys _value])
plain-reagent-form-template))]
(free-form/form {:text "Text value"
:email "Email value"
:password "Password value"
;:select "cat" ; TODO: enable this and fix generation, as it's broken right now.
;:select-with-group "two" ; TODO: enable this and fix generation, as it's broken right now.
:textarea "Textarea value"
:t {:e {:x {:t "Text with deep keys value"}}}
:checkbox true
:radio-buttons "radio-option-2"
} {} (fn [_keys _value])
plain-reagent-form-template))]
(is (= generated-input
[:form {:noValidate true}
nil

0 comments on commit cfe78b4

Please sign in to comment.