Skip to content

Commit

Permalink
upgrade schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Sep 24, 2014
1 parent 3792b89 commit c14c001
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 100 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ I personally like to start the repl with `lein repl :headless` and do all of thi

Om-Bootstrap works with the following dependencies:

- Clojure 1.6.x
- Clojure 1.6.x, 1.7.x
- React.JS 0.11.x
- Om 0.7.x
- Bootstrap 3.1.x (probably works on 3.2, haven't tested it)
Expand All @@ -100,6 +100,8 @@ and the latest version of ClojureScript. Please create a [GitHub issue](https://

Note that we've seen trouble with Safari 7.0.x on CLJS versions <= 0.0.2261. See [this ticket](https://github.com/racehub/om-bootstrap/issues/10) for details.

Also, if you're explicitly using [Prismatic's Schema](https://github.com/prismatic/schema), you'll need version `0.3.x` due to the new `:include-macros` syntax.

## Authors

- Sam Ritchie <https://twitter.com/sritchie>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/cljs/om_bootstrap/docs/getting_started.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
...
:dependencies [[org.clojure/clojure \"1.6.0\"]
[org.clojure/clojurescript \"0.0-2322\"]
[racehub/om-bootstrap \"0.2.9\"]
[racehub/om-bootstrap \"0.3.1\"]
[om \"0.7.3\"]]
...)"})
(d/p "Om-Bootstrap requires Om 0.7.0 or later, and has been tested against Bootstrap 3.1.0 and later. The "
Expand Down
6 changes: 3 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[http-kit "2.1.18"]
[hiccup "1.0.5"]])

(defproject racehub/om-bootstrap "0.2.10-SNAPSHOT"
(defproject racehub/om-bootstrap "0.3.0-SNAPSHOT"
:description "Bootstrap meets Om."
:url "http://github.com/racehub/om-bootstrap"
:license {:name "MIT Licens"
Expand All @@ -17,8 +17,8 @@
:jar-exclusions [#".DS_Store"]
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/core.async "0.1.267.0-0d7780-alpha"]
[prismatic/om-tools "0.3.2"]
[prismatic/schema "0.2.4"
[prismatic/om-tools "0.3.3"]
[prismatic/schema "0.3.0"
:exclude [org.clojure/clojurescript]]
[om "0.7.1"]]
:profiles {:provided
Expand Down
31 changes: 15 additions & 16 deletions src/om_bootstrap/button.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
[om-tools.core :refer-macros [defcomponentk]]
[om-tools.dom :as d :include-macros true]
[om-tools.mixin :refer-macros [defmixin]]
[schema.core :as s])
(:require-macros [schema.macros :as sm]))
[schema.core :as s :include-macros true]))

;; ## Basic Button

Expand All @@ -27,7 +26,7 @@

;; ## Code

(sm/defn render-anchor
(s/defn render-anchor
[opts :- {:classes {s/Any s/Any}
:disabled? (s/maybe s/Bool)
:props {s/Any s/Any}}
Expand All @@ -39,7 +38,7 @@
(d/a (u/merge-props props (:props opts))
children)))

(sm/defn button :- t/Component
(s/defn button :- t/Component
"Renders a button."
[props :- Button & children]
(let [[bs props] (t/separate Button props {:bs-class "button"
Expand Down Expand Up @@ -69,7 +68,7 @@

;; ## Button Toolbar

(sm/defn toolbar :- t/Component
(s/defn toolbar :- t/Component
"Renders a button toolbar."
[opts & children]
(let [[bs props] (t/separate {} opts {:bs-class "button-toolbar"})]
Expand All @@ -79,7 +78,7 @@

;; ## Button Group

(sm/defn button-group :- t/Component
(s/defn button-group :- t/Component
"Renders the supplied children in a wrapping button-group div."
[opts :- ButtonGroup & children]
(let [[bs props] (t/separate ButtonGroup opts {:bs-class "button-group"})
Expand All @@ -96,8 +95,8 @@
(t/bootstrap
{(s/optional-key :title) t/Renderable
(s/optional-key :href) s/Str
(s/optional-key :on-click) (sm/=> s/Any s/Any)
(s/optional-key :on-select) (sm/=> s/Any s/Any)
(s/optional-key :on-click) (s/=> s/Any s/Any)
(s/optional-key :on-select) (s/=> s/Any s/Any)
(s/optional-key :pull-right?) s/Bool
(s/optional-key :dropup?) s/Bool
(s/optional-key :nav-item?) s/Bool}))
Expand Down Expand Up @@ -125,7 +124,7 @@
(s/optional-key :divider?) s/Bool
(s/optional-key :href) s/Str
(s/optional-key :title) s/Str
(s/optional-key :on-select) (sm/=> s/Any s/Any)}))
(s/optional-key :on-select) (s/=> s/Any s/Any)}))

(defcomponentk menu-item*
"Generates an Om component of a menu item. Done this way so that
Expand Down Expand Up @@ -154,17 +153,17 @@
(d/li (u/merge-props props li-attrs)
children))))

(sm/defn menu-item :- t/Component
(s/defn menu-item :- t/Component
[opts :- MenuItem & children]
(->menu-item* {:opts opts
:children children}))

(def DropdownMenu
(t/bootstrap
{(s/optional-key :pull-right?) s/Bool
(s/optional-key :on-select) (sm/=> s/Any s/Any)}))
(s/optional-key :on-select) (s/=> s/Any s/Any)}))

(sm/defn dropdown-menu :- t/Component
(s/defn dropdown-menu :- t/Component
[opts :- DropdownMenu & children]
(let [[bs props] (t/separate DropdownMenu opts)
classes {:dropdown-menu true
Expand Down Expand Up @@ -222,7 +221,7 @@
:key 1}
(map #(u/clone-with-props % update-child-props) children))]))))

(sm/defn dropdown :- t/Component
(s/defn dropdown :- t/Component
"Returns a dropdown button component. The component manages its own
dropdown state."
[opts :- DropdownButton & children]
Expand All @@ -239,8 +238,8 @@
(s/optional-key :title) t/Renderable
(s/optional-key :href) s/Str
(s/optional-key :dropdown-title) t/Renderable
(s/optional-key :on-click) (sm/=> s/Any s/Any)
(s/optional-key :on-select) (sm/=> s/Any s/Any)}))
(s/optional-key :on-click) (s/=> s/Any s/Any)
(s/optional-key :on-select) (s/=> s/Any s/Any)}))

(defcomponentk split*
"Generates a split button component responsible for its own
Expand Down Expand Up @@ -287,7 +286,7 @@
:dropup (:dropup? bs)})}
btn drop-btn menu))))

(sm/defn split
(s/defn split
[opts :- SplitButton & children]
(->split* {:opts opts
:children children}))
9 changes: 4 additions & 5 deletions src/om_bootstrap/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
(:require [om-bootstrap.types :as t]
[om-bootstrap.util :as u]
[om-tools.dom :as d :include-macros true]
[schema.core :as s])
(:require-macros [schema.macros :as sm]))
[schema.core :as s :include-macros true]))

;; ## Schema

Expand All @@ -26,7 +25,7 @@
;; ## Code
;;
;; TODO: Do we want a custom component class, like in react-bootstrap?
(sm/defn grid :- t/Component
(s/defn grid :- t/Component
"Generates a wrapper for a bootstrap grid."
[opts :- Grid & children]
(let [[bs props] (t/separate Grid opts {})
Expand All @@ -36,13 +35,13 @@
(d/div (u/merge-props props {:class class})
children)))

(sm/defn row :- t/Component
(s/defn row :- t/Component
"Generates a Bootstrap row element."
[opts & children]
(d/div (u/merge-props opts {:class "row"})
children))

(sm/defn col :- t/Component
(s/defn col :- t/Component
"Generates a Bootstrap column element."
[opts :- Col & children]
(let [[bs props] (t/separate Col opts {})
Expand Down
31 changes: 15 additions & 16 deletions src/om_bootstrap/input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[om-bootstrap.types :as t]
[om-bootstrap.util :as u]
[om-tools.dom :as d :include-macros true]
[schema.core :as s])
(:require-macros [schema.macros :as sm]))
[schema.core :as s :include-macros true]))

;; ## Bootstrap Inputs for Om
;;
Expand Down Expand Up @@ -57,7 +56,7 @@

;; ### Utilities

(sm/defn class-set :- s/Str
(s/defn class-set :- s/Str
"Mimics the class-set behavior from React. Pass in a map of
potential class to Boolean; you'll get back a class string that
represents the final class to apply.
Expand All @@ -69,12 +68,12 @@
klasses)
(string/join " ")))

(sm/defn glyph :- t/Component
(s/defn glyph :- t/Component
"To be used with :addon-before or :addon-after."
[glyph-name :- s/Str]
(d/span {:class (str "glyphicon glyphicon-" glyph-name)}))

(sm/defn render-icon :- t/Component
(s/defn render-icon :- t/Component
[{:keys [feedback? bs-style]} :- FeedbackIcons]
(when feedback?
(let [klasses {:glyphicon true
Expand All @@ -84,12 +83,12 @@
:glyphicon-remove (= "error" bs-style)}]
(d/span {:class (class-set klasses)}))))

(sm/defn render-help
(s/defn render-help
[help :- (s/maybe s/Str)]
(when help
(d/span {:class "help-block"} help)))

(sm/defn render-input-group
(s/defn render-input-group
"Items is a vector of render instances."
[{:keys [addon-before addon-after]} :- Addons
items :- s/Any]
Expand All @@ -102,14 +101,14 @@
(d/span {:class "input-group-addon"} addon-after)))
items))

(sm/defn checkbox-or-radio? :- s/Bool
(s/defn checkbox-or-radio? :- s/Bool
"Returns true if the supplied input is of type checkbox or radio,
false otherwise."
[{type :type} :- Input]
(or (= type "checkbox")
(= type "radio")))

(sm/defn checkbox-or-radio-wrapper :- t/Component
(s/defn checkbox-or-radio-wrapper :- t/Component
"Wraps this business in a div."
[{type :type} :- Input
children]
Expand All @@ -118,7 +117,7 @@
(d/div {:class (class-set klasses)}
children)))

(sm/defn render-label
(s/defn render-label
"This doesn't handle any control group stuff."
([input :- Input] (render-label input nil))
([{lc :label-classname label :label :as input} :- Input
Expand All @@ -131,14 +130,14 @@
label)
child))))

(sm/defn render-wrapper
(s/defn render-wrapper
[{wc :wrapper-classname} :- Input
child]
(if wc
(d/div {:class wc} child)
child))

(sm/defn render-form-group :- t/Component
(s/defn render-form-group :- t/Component
"Wraps the entire form group."
[{bs-style :bs-style cn :group-classname :as input} :- Input
children]
Expand All @@ -151,7 +150,7 @@
(d/div {:class (class-set classes)}
children)))

(sm/defn render-input :- t/Component
(s/defn render-input :- t/Component
[input :- Input attrs children]
(let [props (fn [klass]
(u/merge-props attrs {:class klass
Expand All @@ -171,7 +170,7 @@

;; ### API Methods

(sm/defn input :- t/Component
(s/defn input :- t/Component
"Returns an input component. This currently does NOT handle any of
the default values or validation messages that we'll need to make
this work, though."
Expand All @@ -198,7 +197,7 @@
;; These bad dawgs need to be abstracted out into more solid input
;; components. Putting them here for now.

(sm/defn radio-option :- t/Component
(s/defn radio-option :- t/Component
"Generates a radio button entry, to place into a radio button
grouping."
[opts :- Radio]
Expand All @@ -211,7 +210,7 @@
(d/label {:class "radio-inline"} core label)
(d/div {:class "radio"} (d/label {} core label)))))

(sm/defn options :- [t/Component]
(s/defn options :- [t/Component]
"Returns a sequence of options for use as the children of a select
input."
[header :- s/Str
Expand Down
7 changes: 3 additions & 4 deletions src/om_bootstrap/mixins.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
(:require [cljs.core.async :as a :refer [put!]]
[om.core :as om]
[om-tools.mixin :refer-macros [defmixin]]
[schema.core :as s])
(:require-macros [schema.macros :as sm]))
[schema.core :as s :include-macros true]))

;; ## Listener Mixin

(sm/defn event-listener :- (sm/=> s/Any)
(s/defn event-listener :- (s/=> s/Any)
"Registers the callback on the supplied target for events of type
`event-type`. Returns a function of no arguments that, when called,
unregisters the callback."
[target :- s/Any
event-type :- s/Str
callback :- (sm/=> s/Any s/Any)]
callback :- (s/=> s/Any s/Any)]
(cond (.-addEventListener target)
(do (.addEventListener target event-type callback false)
(fn [] (.removeEventListener target event-type callback false)))
Expand Down
11 changes: 5 additions & 6 deletions src/om_bootstrap/modal.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
[om-tools.core :refer-macros [defcomponentk]]
[om-tools.dom :as d :include-macros true]
[om-tools.mixin :refer-macros [defmixin]]
[schema.core :as s])
(:require-macros [cljs.core.async.macros :refer [go-loop]]
[schema.macros :as sm]))
[schema.core :as s :include-macros true])
(:require-macros [cljs.core.async.macros :refer [go-loop]]))

;; ## Schema
;;
Expand All @@ -31,9 +30,9 @@
:close-button? s/Bool
:animate? s/Bool
:children (s/named s/Any "Child elements, if any.")
:on-request-hide (sm/=> s/Any s/Any)})
:on-request-hide (s/=> s/Any s/Any)})

(sm/defn render-header :- t/Component
(s/defn render-header :- t/Component
"Renders the header for the modal."
[{:keys [close-button? on-request-hide title]} :- Modal]
(let [close-button (when close-button?
Expand All @@ -48,7 +47,7 @@
title
(d/h4 {:class "modal-title"} title)))))

(sm/defn render-backdrop :- t/Component
(s/defn render-backdrop :- t/Component
"Renders the backdrop behind the modal."
[{:keys [animation? backdrop? on-request-hide] :- Modal} modal-elem]
(let [klasses {:modal-backdrop true
Expand Down
Loading

0 comments on commit c14c001

Please sign in to comment.