Browse Source

Added documentation for parse-map

Stephen Starkey 1 year ago
parent
commit
d22cc8ee5c
2 changed files with 41 additions and 10 deletions
  1. 21
    6
      docs/index.html
  2. 20
    4
      src/defenv/core.clj

+ 21
- 6
docs/index.html View File

@@ -2926,13 +2926,30 @@ doesn't throw exceptions when loading namespaces (a huge pet peeve!).</p>
2926 2926
   (let [val (System/getenv env-name)] (if-not val default-value val)))</pre></td></tr><tr><td class="docs"><h2>Transformation convenience functions</h2>
2927 2927
 
2928 2928
 <p>(for use wherever you see <code>:tfn</code>)</p>
2929
-</td><td class="codes"></td></tr><tr><td class="docs">
2929
+</td><td class="codes"></td></tr><tr><td class="docs"><p>DEPRECATED in favor of parse-bool</p>
2930 2930
 </td><td class="codes"><pre class="brush: clojure">(defn parse-bool [s] (Boolean/parseBoolean s))
2931 2931
 (defn parse-int [s] (Integer/parseInt s))
2932 2932
 (defn parse-long [s] (Long/parseLong s))
2933 2933
 (defn parse-float [s] (Float/parseFloat s))
2934 2934
 (defn parse-double [s] (Double/parseDouble s))
2935
-(defn parse-map
2935
+(defn parse-boolean
2936
+  {:deprecated &quot;0.0.6&quot;} [s] (parse-bool s))</pre></td></tr><tr><td class="docs"><p>Parses a string containing key-value pairs into a map. Each pair is
2937
+   separated by a comma, and the key and value by an equal sign. Example:
2938
+   <code>a=b,c=d</code> parses to {"a"="b", "c"="d"}.</p>
2939
+
2940
+<p>   You can pass two configuration options into the <code>opts</code> map:</p>
2941
+
2942
+<p>   <code>:default-key</code>
2943
+   specifies what happens when either you don't follow the syntax (you get a map
2944
+   with the value of <code>:default-key</code> as its key, and the variable value as its
2945
+   value) or when you have a key in the map that is blank.</p>
2946
+
2947
+<p>   <code>:key-fn</code>
2948
+   specifies a function to execute on each key. This function is not executed
2949
+   on the <code>:default-key</code></p>
2950
+
2951
+<p>   See <code>defenv.tfn-spec</code> for examples.</p>
2952
+</td><td class="codes"><pre class="brush: clojure">(defn parse-map
2936 2953
   ([s] (parse-map {} s))
2937 2954
   ([{:keys [default-key key-fn] :or {default-key &quot;default&quot;
2938 2955
                                      key-fn identity}} s]
@@ -2944,10 +2961,8 @@ doesn't throw exceptions when loading namespaces (a huge pet peeve!).</p>
2944 2961
                    (when (m k)
2945 2962
                      (binding [*out* *err*]
2946 2963
                        (println &quot;**WARNING** Duplicate key found in map:&quot; k)))
2947
-                   (assoc m k (or v )))) {} kvs))
2948
-     {default-key s})))</pre></td></tr><tr><td class="docs"><p>DEPRECATED in favor of parse-bool</p>
2949
-</td><td class="codes"><pre class="brush: clojure">(defn parse-boolean
2950
-  {:deprecated &quot;0.0.6&quot;} [s] (parse-bool s))</pre></td></tr><tr><td class="docs"><h2>On-the-fly documentation</h2>
2964
+                   (assoc m k (or v &quot;&quot;)))) {} kvs))
2965
+     {default-key s})))</pre></td></tr><tr><td class="docs"><h2>On-the-fly documentation</h2>
2951 2966
 </td><td class="codes"></td></tr><tr><td class="docs"><h3>Generation</h3>
2952 2967
 </td><td class="codes"><pre class="brush: clojure">(def ^:private displays {::missing     &quot;*REQUIRED*&quot;
2953 2968
                          ::masked      &quot;--MASKED--&quot;

+ 20
- 4
src/defenv/core.clj View File

@@ -45,7 +45,27 @@
45 45
 (defn parse-long [s] (Long/parseLong s))
46 46
 (defn parse-float [s] (Float/parseFloat s))
47 47
 (defn parse-double [s] (Double/parseDouble s))
48
+(defn parse-boolean
49
+  "DEPRECATED in favor of parse-bool"
50
+  {:deprecated "0.0.6"} [s] (parse-bool s))
51
+
48 52
 (defn parse-map
53
+  "Parses a string containing key-value pairs into a map. Each pair is
54
+   separated by a comma, and the key and value by an equal sign. Example:
55
+   `a=b,c=d` parses to {\"a\"=\"b\", \"c\"=\"d\"}.
56
+
57
+   You can pass two configuration options into the `opts` map:
58
+
59
+   `:default-key`
60
+   specifies what happens when either you don't follow the syntax (you get a map
61
+   with the value of `:default-key` as its key, and the variable value as its
62
+   value) or when you have a key in the map that is blank.
63
+
64
+   `:key-fn`
65
+   specifies a function to execute on each key. This function is not executed
66
+   on the `:default-key`
67
+
68
+   See `defenv.tfn-spec` for examples."
49 69
   ([s] (parse-map {} s))
50 70
   ([{:keys [default-key key-fn] :or {default-key "default"
51 71
                                      key-fn identity}} s]
@@ -60,10 +80,6 @@
60 80
                    (assoc m k (or v "")))) {} kvs))
61 81
      {default-key s})))
62 82
 
63
-(defn parse-boolean
64
-  "DEPRECATED in favor of parse-bool"
65
-  {:deprecated "0.0.6"} [s] (parse-bool s))
66
-
67 83
 ;; ## On-the-fly documentation
68 84
 
69 85
 ;; ### Generation