Browse code

Refactor license notice code to reduce duplication between panels

Joseph Weston authored on 05/12/2021 03:18:28
Showing 1 changed files
... ...
@@ -61,6 +61,13 @@
61 61
                  [:span (first %)]
62 62
                  [:span (second %)])))))
63 63
 
64
+(defn- license-notice
65
+    [x]
66
+    (let [l (x :license-notice)]
67
+      (when l
68
+        [:section.license-notice
69
+         (spaced (x :name) "is" (l :content-kind) "subject to the" (l :license-name))])))
70
+
64 71
 (defn- pounds [w]
65 72
     (if (= w 1)
66 73
       (spaced w "lb")
... ...
@@ -81,12 +88,6 @@
81 88
      (into [:ol.clauses] (->> license :clauses (map #(vector :li %))))
82 89
      [:div.copyright-notice (->> license :copyright-notice (map #(vector :p %)))]])
83 90
 
84
-(defn- license-notice
85
-    [x]
86
-    (let [l (x :license-notice)]
87
-      (spaced
88
-       (x :name) "is" (l :content-kind) "subject to the" (l :license-name))))
89
-
90 91
 (defn spell-panel [spell]
91 92
       [:article {:class (styles/spell-panel)}
92 93
        [:h1 (spell :name)]
... ...
@@ -123,8 +124,7 @@
123 124
            [:section.higher-level
124 125
              [:span "At higher levels"]
125 126
              [:span at-higher-levels]]))
126
-       (when (spell :license-notice)
127
-           [:section.license-notice (license-notice spell)])])
127
+       (license-notice spell)])
128 128
 
129 129
 (defn equipment-panel [item]
130 130
     [:article {:class (styles/equipment-panel)}
... ...
@@ -149,8 +149,7 @@
149 149
          (some->> item :quantity (str "for ") parenthesize)))
150 150
      (when (item :desc)
151 151
          [:section.description (->> item :desc (map #(vector :p %)))])
152
-     (when (item :license-notice)
153
-         [:section.license-notice (license-notice item)])])
152
+     (license-notice item)])
154 153
 
155 154
 (defn weapon-panel [weapon]
156 155
  (let [weapon-kind (-> weapon :weapon_range string/lower-case)
... ...
@@ -177,8 +176,7 @@
177 176
        (-> weapon :weight pounds)
178 177
      :Cost
179 178
        (cost weapon))
180
-    (when (weapon :license-notice)
181
-        [:section.license-notice (license-notice weapon)])]))
179
+    (license-notice weapon)]))
182 180
 
183 181
 (defn error-message
184 182
     [{e :err}]