forked from zero-one-group/fxl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specs.clj
95 lines (85 loc) · 2.81 KB
/
specs.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(ns zero-one.fxl.specs
(:require
[clojure.spec.alpha :as s]
[expound.alpha :as expound]
[zero-one.fxl.alignments :refer [horizontal-alignments vertical-alignments]]
[zero-one.fxl.borders :refer [border-styles]]
[zero-one.fxl.colours :refer [colours]]))
;; Coordinates
(def max-rows (int 1e5))
(def max-cols (int 1e4))
(s/def ::row (s/and nat-int? #(<= % max-rows)))
(s/def ::col (s/and nat-int? #(<= % max-cols)))
(s/def ::sheet string?)
(s/def ::coord
(s/keys :req-un [::row ::col]
:opt-un [::sheet]))
;; Cell Style
;;;; Font Style
(s/def ::bold boolean?)
(s/def ::italic boolean?)
(s/def ::underline boolean?)
(s/def ::strikeout boolean?)
(s/def ::font-name string?)
(s/def ::font-colour (-> colours keys set))
(s/def ::font-size nat-int?)
(s/def ::font-style
(s/keys :opt-un [::bold
::italic
::underline
::strikeout
::font-size
::font-name
::font-colour]))
;;;; Alignment Style
(s/def ::horizontal (-> horizontal-alignments keys set))
(s/def ::vertical (-> vertical-alignments keys set))
(s/def ::alignment-style (s/keys :opt-un [::horizontal ::vertical]))
;;;; Border Style
(s/def :border/style (-> border-styles keys set))
(s/def :border/colour (-> colours keys set))
(s/def ::single-border-style (s/keys :opt-un [:border/style :border/colour]))
(s/def :border/bottom-border ::single-border-style)
(s/def :border/left-border ::single-border-style)
(s/def :border/right-border ::single-border-style)
(s/def :border/top-border ::single-border-style)
(s/def ::border-style (s/keys :opt-un [:border/bottom-border
:border/left-border
:border/right-border
:border/top-border]))
;;;; Aggregated Style
(s/def ::data-format string?)
(s/def ::background-colour (-> colours keys set))
(s/def ::row-size ::row)
(s/def ::col-size (s/or :number ::col
:auto #(= % :auto)))
(s/def ::style
(s/merge ::font-style
::alignment-style
::border-style
(s/keys :opt-un [::data-format
::background-colour
::row-size
::col-size])))
;; Cell Value
(s/def ::value (s/nilable (s/or :string string?
:number number?
:boolean boolean?)))
;; Cell
(s/def ::cell
(s/keys :req-un [::value ::coord ::style]))
;; Handy Functions
(defn valid?
([spec]
(fn [value] (valid? spec value)))
([spec value]
(if (s/valid? spec value)
true
(do
(expound/expound spec value)
false))))
(defn invalid?
([spec]
(fn [value] (invalid? spec value)))
([spec value]
(not (s/valid? spec value))))