Skip to content

Commit 18da9e4

Browse files
committed
Serialize event body
1 parent 7a8827d commit 18da9e4

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/plan/serializer.janet

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33

44
(import ../date)
55

6-
(def task-body-indentation " ")
6+
(def body-indentation " ")
77

88
(defn- plan-title [plan]
99
(string "# " (plan :title)))
1010

1111
(defn- checkbox [done]
1212
(if done "[X]" "[ ]"))
1313

14-
(defn- serialize-event [event]
14+
(defn- serialize-event-title [event]
1515
(string "- " (event :title)))
1616

17+
(defn- serialize-event-body [event]
18+
(def body (event :body))
19+
(if (or (nil? body) (empty? body))
20+
""
21+
(string "\n"
22+
(string/join
23+
(map (fn [line] (string body-indentation line)) body)
24+
"\n"))))
25+
26+
(defn- serialize-event [event]
27+
(string
28+
(serialize-event-title event)
29+
(serialize-event-body event)))
30+
1731
(defn- task-mark [task]
1832
(if (task :missed-on)
1933
(string " (missed on " (date/format (task :missed-on) true) ")")
@@ -28,11 +42,12 @@
2842
""
2943
(string "\n"
3044
(string/join
31-
(map (fn [line] (string task-body-indentation line)) body)
45+
(map (fn [line] (string body-indentation line)) body)
3246
"\n"))))
3347

3448
(defn- serialize-task [task]
35-
(string (serialize-task-title task)
49+
(string
50+
(serialize-task-title task)
3651
(serialize-task-body task)))
3752

3853
(defn- plan-inbox [plan serialize-empty-inbox]

test/plan/serializer_test.janet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
:days @[(day/build-day (d/date 2020 8 3))
1616
(day/build-day (d/date 2020 8 2))
1717
(day/build-day (d/date 2020 8 1)
18-
@[(event/build-event "Talked to Mike")]
18+
@[(event/build-event "Talked to Mike" @["- He has a new car"])]
1919
@[(task/build-task "Develop photos" false)
2020
(task/build-task "Pay bills" true @["- Electricity" "- Water"])
2121
(task/build-missed-task "Organize photos" (d/date 2020 7 20))])
@@ -38,6 +38,7 @@
3838
## 2020-08-01, Saturday
3939
4040
- Talked to Mike
41+
- He has a new car
4142
- [ ] Develop photos
4243
- [X] Pay bills
4344
- Electricity

0 commit comments

Comments
 (0)