Explorar el Código

split util.marker & util.priority lib

rcmerci hace 4 años
padre
commit
09b2ea368d

+ 5 - 3
src/main/frontend/commands.cljs

@@ -1,5 +1,7 @@
 (ns frontend.commands
   (:require [frontend.util :as util]
+            [frontend.util.marker :as marker]
+            [frontend.util.priority :as priority]
             [frontend.date :as date]
             [frontend.state :as state]
             [frontend.search :as search]
@@ -431,7 +433,7 @@
 
 (defn compute-pos-delta-when-change-marker
   [current-input edit-content new-value marker pos]
-  (let [old-marker (some->> (first (re-find util/bare-marker-pattern edit-content))
+  (let [old-marker (some->> (first (re-find marker/bare-marker-pattern edit-content))
                             (string/trim))
         old-marker (if old-marker old-marker "")
         pos-delta (- (count marker)
@@ -456,7 +458,7 @@
                     (count (re-find re-pattern prefix))))
             new-value (str (subs edit-content 0 pos)
                            (string/replace-first (subs edit-content pos)
-                                                 util/marker-pattern
+                                                 marker/marker-pattern
                                                  (str marker " ")))]
         (state/set-edit-content! input-id new-value)
         (let [new-pos (compute-pos-delta-when-change-marker
@@ -470,7 +472,7 @@
       (let [format (or (db/get-page-format (state/get-current-page)) (state/get-preferred-format))
             edit-content (gobj/get current-input "value")
             new-priority (util/format "[#%s]" priority)
-            new-value (string/trim (util/add-or-update-priority edit-content format new-priority))]
+            new-value (string/trim (priority/add-or-update-priority edit-content format new-priority))]
         (state/set-edit-content! input-id new-value)))))
 
 (defmethod handle-step :editor/set-heading [[_ heading]]

+ 2 - 1
src/main/frontend/components/page.cljs

@@ -1,6 +1,7 @@
 (ns frontend.components.page
   (:require [rum.core :as rum]
             [frontend.util :as util :refer-macros [profile]]
+            [frontend.util.marker :as marker]
             [frontend.tools.html-export :as html-export]
             [frontend.handler.file :as file]
             [frontend.handler.page :as page-handler]
@@ -238,7 +239,7 @@
     (let [current-repo (state/sub :git/current-repo)
          repo (or repo current-repo)
          page-name (string/lower-case path-page-name)
-         marker-page? (util/marker? page-name)
+         marker-page? (marker/marker? page-name)
          priority-page? (contains? #{"a" "b" "c"} page-name)
          block? (util/uuid-string? page-name)
          block-id (and block? (uuid page-name))

+ 2 - 1
src/main/frontend/db/react.cljs

@@ -8,6 +8,7 @@
             [frontend.state :as state]
             [frontend.date :as date]
             [frontend.util :as util :refer-macros [profile] :refer [react]]
+            [frontend.util.marker :as marker]
             [clojure.string :as string]
             [frontend.config :as config]
             [datascript.core :as d]
@@ -188,7 +189,7 @@
         route-name (get-in match [:data :name])]
     (when (= route-name :page)
       (when-let [page-name (get-in match [:path-params :name])]
-        (and (util/marker? page-name)
+        (and (marker/marker? page-name)
              (string/upper-case page-name))))))
 
 (defn get-related-keys

+ 4 - 3
src/main/frontend/handler/editor.cljs

@@ -48,7 +48,8 @@
             [frontend.db.outliner :as outliner-db]
             [frontend.modules.outliner.tree :as tree]
             [frontend.debug :as debug]
-            [datascript.core :as d]))
+            [datascript.core :as d]
+            [frontend.util.marker :as marker]))
 
 ;; FIXME: should support multiple images concurrently uploading
 
@@ -521,7 +522,7 @@
 
 (defn- with-timetracking-properties
   [block value]
-  (let [new-marker (first (re-find util/bare-marker-pattern (or value "")))
+  (let [new-marker (first (re-find marker/bare-marker-pattern (or value "")))
         new-marker (if new-marker (string/lower-case (string/trim new-marker)))
         new-marker? (and
                      new-marker
@@ -638,7 +639,7 @@
                                  (let [marker (if (= :now (state/get-preferred-workflow))
                                                 "LATER"
                                                 "TODO")]
-                                   [(util/add-or-update-marker (string/triml content) format marker)  marker]))
+                                   [(marker/add-or-update-marker (string/triml content) format marker)  marker]))
           new-content (string/triml new-content)]
       (let [new-pos (commands/compute-pos-delta-when-change-marker
                      current-input content new-content marker (util/get-input-pos current-input))]

+ 0 - 58
src/main/frontend/util.cljc

@@ -1019,64 +1019,6 @@
          (if-let [c (gobj/get js/window "clipboardData")]
            [(.getData c "Text") (.getData c "Text")])))))
 
-(defn marker?
-  [s]
-  (contains?
-   #{"NOW" "LATER" "TODO" "DOING"
-     "DONE" "WAIT" "WAITING" "CANCELED" "CANCELLED" "STARTED" "IN-PROGRESS"}
-   (string/upper-case s)))
-
-(def marker-pattern
-  #"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
-
-(def bare-marker-pattern
-  #"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
-
-#?(:cljs
-   (defn add-or-update-marker
-     [content format marker]
-     (let [[re-pattern new-line-re-pattern]
-           (if (= :org format)
-             [#"\*+\s" #"\n\*+\s"]
-             [#"#+\s" #"\n#+\s"])
-           pos
-           (if-let [matches (seq (re-pos new-line-re-pattern content))]
-             (let [[start-pos content] (last matches)]
-               (+ start-pos (count content)))
-             (count (re-find re-pattern content)))
-           new-content
-           (str (subs content 0 pos)
-                (string/replace-first (subs content pos)
-                                      marker-pattern
-                                      (str marker " ")))]
-       new-content)))
-
-#?(:cljs
-   (defn add-or-update-priority
-     [content format priority]
-     (let [priority-pattern  #"(\[#[ABC]\])?\s?"
-           [re-pattern new-line-re-pattern]
-           (if (= :org format)
-             [#"\*+\s" #"\n\*+\s"]
-             [#"#+\s" #"\n#+\s"])
-           skip-hash-pos
-           (if-let [matches (seq (re-pos new-line-re-pattern content))]
-             (let [[start-pos content] (last matches)]
-               (+ start-pos (count content)))
-             (count (re-find re-pattern content)))
-           skip-marker-pos
-           (if-let [matches (seq (re-pos bare-marker-pattern (subs content skip-hash-pos)))]
-             (let [[start-pos content] (last matches)]
-               (+ start-pos (count content)))
-             0)
-           pos (+ skip-hash-pos skip-marker-pos)
-           new-content
-           (str (subs content 0 pos)
-                (string/replace-first (subs content pos)
-                                      priority-pattern
-                                      (str priority " ")))]
-       new-content)))
-
 (defn pp-str [x]
   (with-out-str (clojure.pprint/pprint x)))
 

+ 35 - 0
src/main/frontend/util/marker.cljs

@@ -0,0 +1,35 @@
+(ns frontend.util.marker
+  (:require [clojure.string :as string]
+            [frontend.util :as util]))
+
+(defn marker?
+  [s]
+  (contains?
+   #{"NOW" "LATER" "TODO" "DOING"
+     "DONE" "WAIT" "WAITING" "CANCELED" "CANCELLED" "STARTED" "IN-PROGRESS"}
+   (string/upper-case s)))
+
+(def marker-pattern
+  #"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)?\s?")
+
+(def bare-marker-pattern
+  #"^(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS){1}\s+")
+
+
+(defn add-or-update-marker
+  [content format marker]
+  (let [[re-pattern new-line-re-pattern]
+        (if (= :org format)
+          [#"\*+\s" #"\n\*+\s"]
+          [#"#+\s" #"\n#+\s"])
+        pos
+        (if-let [matches (seq (util/re-pos new-line-re-pattern content))]
+          (let [[start-pos content] (last matches)]
+            (+ start-pos (count content)))
+          (count (re-find re-pattern content)))
+        new-content
+        (str (subs content 0 pos)
+             (string/replace-first (subs content pos)
+                                   marker-pattern
+                                   (str marker " ")))]
+    new-content))

+ 29 - 0
src/main/frontend/util/priority.cljs

@@ -0,0 +1,29 @@
+(ns frontend.util.priority
+  (:require [clojure.string :as string]
+            [frontend.util :as util]
+            [frontend.util.marker :as marker]))
+
+(defn add-or-update-priority
+  [content format priority]
+  (let [priority-pattern  #"(\[#[ABC]\])?\s?"
+        [re-pattern new-line-re-pattern]
+        (if (= :org format)
+          [#"\*+\s" #"\n\*+\s"]
+          [#"#+\s" #"\n#+\s"])
+        skip-hash-pos
+        (if-let [matches (seq (util/re-pos new-line-re-pattern content))]
+          (let [[start-pos content] (last matches)]
+            (+ start-pos (count content)))
+          (count (re-find re-pattern content)))
+        skip-marker-pos
+        (if-let [matches (seq (util/re-pos marker/bare-marker-pattern (subs content skip-hash-pos)))]
+          (let [[start-pos content] (last matches)]
+            (+ start-pos (count content)))
+          0)
+        pos (+ skip-hash-pos skip-marker-pos)
+        new-content
+        (str (subs content 0 pos)
+             (string/replace-first (subs content pos)
+                                   priority-pattern
+                                   (str priority " ")))]
+    new-content))