Skip to content

Commit

Permalink
Merge branch 'yogthos-master'
Browse files Browse the repository at this point in the history
PR didn't merge cleanly due to outdated travis config
  • Loading branch information
theleoborges committed Mar 13, 2017
2 parents 8396e00 + 23b93bd commit eebc17d
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pom.xml.asc
.lein-plugins
.lein-repl-history
.nrepl-port
out/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: clojure
lein: lein2
script: lein2 all-tests
script: lein2 clj-tests
jdk:
- openjdk7
- oraclejdk7
Expand Down
64 changes: 26 additions & 38 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
(defproject bouncer "1.0.0"
(defproject bouncer "1.0.1"
:description "A validation library for Clojure apps"
:url "http://github.com/leonardoborges/bouncer"
:license {:name "MIT License"
:url "http://opensource.org/licenses/MIT"}
:url "http://opensource.org/licenses/MIT"}

:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2665"]
[clj-time "0.9.0"]
[com.andrewmcveigh/cljs-time "0.3.0"]]
:jar-exclusions [#"\.cljx"]
:source-paths ["src" "target/classes"]
:test-paths ["target/test-classes"]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.495"]
[clj-time "0.13.0"]
[com.andrewmcveigh/cljs-time "0.5.0-alpha2"]]

:prep-tasks [["cljx-once"] "javac" "compile"]

:profiles {:dev {:plugins [[com.keminglabs/cljx "0.6.0"
:exclusions [org.clojure/clojure]]]}
:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
:1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
:profiles {:dev {}
:1.6 {:jdependencies [[org.clojure/clojure "1.6.0"]]}
:cljs {:plugins [[lein-cljsbuild "1.0.3"]
[com.cemerick/clojurescript.test "0.3.3"]]
:cljsbuild {:test-commands {"phantom" ["phantomjs" :runner "target/testable.js"]}
:builds [{:source-paths ["target/classes" "target/test-classes"]
:compiler {:output-to "target/testable.js"
:optimizations :whitespace}}]}
:cljs {:plugins [[lein-cljsbuild "1.1.5"]
[lein-doo "0.1.7"]]
:doo {:build "test"}
:cljsbuild
{:builds
{:test
{:source-paths ["src" "test"]
:compiler {:main bouncer.runner
:output-to "target/test/core.js"
:target :nodejs
:optimizations :none
:source-map true
:pretty-print true}}}}
:prep-tasks [["cljsbuild" "once"]]
:hooks [leiningen.cljsbuild]}
:cljx {:cljx {:builds [{:source-paths ["src"]
:output-path "target/classes"
:rules :clj}
{:source-paths ["src"]
:output-path "target/classes"
:rules :cljs}
{:source-paths ["test"]
:output-path "target/test-classes"
:rules :clj}
{:source-paths ["test"]
:output-path "target/test-classes"
:rules :cljs}]}}}

:aliases {"all-tests" ["with-profile" "cljs:1.4:1.5:1.6" "test"]
"cljx-auto" ["with-profile" "cljx" "cljx" "auto"]
"cljx-once" ["with-profile" "cljx" "cljx" "once"]})
:hooks [leiningen.cljsbuild]}}
;; TODO: Update travis configuration so cljs tests run alongside JVM tests
:aliases {"clj-tests" ["with-profile" "1.6:dev" "test"]
"cljs-tests" ["with-profile" "cljs" "doo" "node" "once"]
"cljs-auto" ["with-profile" "cljs" "cljsbuild" "auto"]
"cljs-once" ["with-profile" "cljs" "cljsbuild" "once"]})
72 changes: 36 additions & 36 deletions src/bouncer/core.cljx → src/bouncer/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ it's pretty comprehensive.
If you'd like to know more about the motivation behind `bouncer`, check the
[announcement post](http://www.leonardoborges.com/writings/2013/01/04/bouncer-validation-lib-for-clojure/)."
{:author "Leonardo Borges"}
#+cljs (:require [goog.string :as gstring]
[goog.string.format]))
#?(:cljs (:require [goog.string :as gstring]
[goog.string.format])))



Expand All @@ -24,18 +24,18 @@ If you'd like to know more about the motivation behind `bouncer`, check the
(defn- build-multi-step
([key-or-vec fn-vec] (build-multi-step key-or-vec fn-vec []))
([key-or-vec [f-or-list & rest] acc]
(if-not f-or-list
acc
(cond
(sequential? f-or-list)
(let [[f & opts] f-or-list]
(recur key-or-vec
rest
(conj acc (concat [f key-or-vec ] opts))))

:else (recur key-or-vec
rest
(conj acc [f-or-list key-or-vec]))))))
(if-not f-or-list
acc
(cond
(sequential? f-or-list)
(let [[f & opts] f-or-list]
(recur key-or-vec
rest
(conj acc (concat [f key-or-vec] opts))))

:else (recur key-or-vec
rest
(conj acc [f-or-list key-or-vec]))))))

(defn- merge-path
"Takes two arguments:
Expand Down Expand Up @@ -67,15 +67,15 @@ If you'd like to know more about the motivation behind `bouncer`, check the
forms)]
(reduce (fn [acc [key-or-vec sym-or-coll :as rule]]
(cond
(vector? sym-or-coll)
(concat acc (build-multi-step key-or-vec sym-or-coll))
(vector? sym-or-coll)
(concat acc (build-multi-step key-or-vec sym-or-coll))


(map? sym-or-coll)
(concat acc (build-steps (merge-path key-or-vec
sym-or-coll)))
(map? sym-or-coll)
(concat acc (build-steps (merge-path key-or-vec
sym-or-coll)))

:else (conj acc [sym-or-coll key-or-vec])))
:else (conj acc [sym-or-coll key-or-vec])))
[]
(partition 2 forms))))

Expand All @@ -102,17 +102,17 @@ If you'd like to know more about the motivation behind `bouncer`, check the
Returns `acc` augmented with a namespace qualified ::errors keyword
"
[message-fn acc [pred k & args]]
(let [k (if (vector? k) k [k])
error-path (cons ::errors k)
(let [k (if (vector? k) k [k])
error-path (cons ::errors k)

{:keys [optional default-message-format]
:or {optional false
default-message-format "Custom validation failed for %s"}
:as metadata} (meta pred)
:or {optional false
default-message-format "Custom validation failed for %s"}
:as metadata} (meta pred)

meta-with-defaults
(merge metadata {:default-message-format default-message-format
:optional optional})
(merge metadata {:default-message-format default-message-format
:optional optional})

[args opts] (split-with (complement keyword?) args)
{:keys [message pre]} (apply hash-map opts)
Expand All @@ -123,10 +123,10 @@ If you'd like to know more about the motivation behind `bouncer`, check the
(apply pred pred-subject args))
acc
(update-in acc error-path
#(conj % (message-fn {:path k, :value pred-subject
:args (seq args)
#(conj % (message-fn {:path k, :value pred-subject
:args (seq args)
:metadata meta-with-defaults
:message message}))))
:message message}))))
acc)))


Expand Down Expand Up @@ -170,10 +170,10 @@ If you'd like to know more about the motivation behind `bouncer`, check the
:name v/required)"
[error]
(let [{:keys [message path metadata]} error]
#+clj (format (or message (:default-message-format metadata))
(name (peek path)))
#+cljs (gstring/format (or message (:default-message-format metadata))
(name (peek path)))))
#?(:clj (format (or message (:default-message-format metadata))
(name (peek path))))
#?(:cljs (gstring/format (or message (:default-message-format metadata))
(name (peek path))))))

(defn validate
"Takes a
Expand Down Expand Up @@ -213,8 +213,8 @@ If you'd like to know more about the motivation behind `bouncer`, check the
"
[& args]
(let [[message-fn args] (if (fn? (first args))
[(first args) (next args)]
[with-default-messages args])
[(first args) (next args)]
[with-default-messages args])
[m forms] [(first args) (next args)]]
(validate* message-fn m (build-steps forms))))

Expand Down
10 changes: 5 additions & 5 deletions src/bouncer/validators.cljx → src/bouncer/validators.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"This namespace contains all built-in validators as well as
macros for defining new validators and validator sets"
{:author "Leonardo Borges"}
#+clj (:require [clj-time.format :as f])
#+cljs (:require [cljs-time.format :as f])
#+cljs (:require-macros [bouncer.validators :refer [defvalidator]])
#?(:clj (:require [clj-time.format :as f]))
#?(:cljs (:require [cljs-time.format :as f]))
#?(:cljs (:require-macros [bouncer.validators :refer [defvalidator]]))
(:refer-clojure :exclude [boolean]))

;; ## Customization support
Expand Down Expand Up @@ -181,8 +181,8 @@
(let [formatter (if (string? opt) (f/formatter opt) opt)]
(try
(if formatter (f/parse formatter value) (f/parse value))
#+clj (catch IllegalArgumentException e false)
#+cljs (catch js/Error e false))))
#?(:clj (catch IllegalArgumentException e false))
#?(:cljs (catch js/Error e false)))))

(defvalidator max-count
"Validates value is not greater than a max count
Expand Down
Loading

0 comments on commit eebc17d

Please sign in to comment.