Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: c0818c1fd17b3e2407b30b36d6e6b83336640a8b
Timestamp: Sun, 27 Sep 2020 18:11:54 +0000 (4 years ago)

+16 -38 +/-3 browse
clean up note interface
1diff --git a/lib/cmd.ml b/lib/cmd.ml
2index 6bd614b..ad06508 100644
3--- a/lib/cmd.ml
4+++ b/lib/cmd.ml
5 @@ -72,9 +72,9 @@ note cat -encoding json
6 ~f:(fun note ->
7 print_endline
8 ( match encoding with
9- | Json -> Ezjsonm.to_string (Note.to_json note)
10- | Yaml -> Yaml.to_string_exn (Note.to_json note)
11- | Raw -> In_channel.read_all (Note.get_path note) ))
12+ | Json -> Note.Encoding.to_string ~style:`Json note
13+ | Yaml -> Note.Encoding.to_string ~style: `Yaml note
14+ | Raw -> Note.Encoding.to_string ~style: `Raw note ))
15 notes]
16
17 let config_show =
18 diff --git a/lib/note.ml b/lib/note.ml
19index 7abefc9..edb619f 100644
20--- a/lib/note.ml
21+++ b/lib/note.ml
22 @@ -159,6 +159,14 @@ let of_string ~data slug =
23 let markdown = Omd.of_string data in
24 { frontmatter; markdown; slug }
25
26+ module Encoding = struct
27+ let to_string ~style t =
28+ match style with
29+ | `Raw -> In_channel.read_all (get_path t)
30+ | `Json -> Ezjsonm.to_string (to_json t)
31+ | `Yaml -> Yaml.to_string_exn (to_json t)
32+ end
33+
34 module Filter = struct
35 type strategy = Keys | Fulltext
36
37 @@ -269,8 +277,7 @@ module Display = struct
38 List.iter
39 ~f:(fun cell -> print_endline (fst (List.nth_exn cell 0)))
40 cells
41- | `Fixed ->
42- List.iter ~f:print_endline (apply (fixed_spacing cells) cells)
43+ | `Fixed -> List.iter ~f:print_endline (apply (fixed_spacing cells) cells)
44 | `Wide ->
45 List.iter ~f:print_endline
46 (apply (fix_right (fixed_spacing cells)) cells)
47 diff --git a/lib/note.mli b/lib/note.mli
48index 0d5e4d0..ddf0aa2 100644
49--- a/lib/note.mli
50+++ b/lib/note.mli
51 @@ -6,47 +6,18 @@ val build : ?tags:string list -> ?content:string -> title:string -> Slug.t -> t
52 val get_title : t -> string
53 (** access the title of a note *)
54
55- val get_tags : t -> string list
56- (** access tags in the frontmatter of a note *)
57-
58 val get_path : t -> string
59 (** access the absolute path of a note *)
60
61- val tokenize : t -> string list
62- (** split each word from the note into a list of string tokens *)
63-
64- val get_data : t -> Ezjsonm.t
65- (** Extract arbitrarily nested data in the note's markdown document.
66- Currently this will only support code blocks of json or ymal but it may
67- be expanded. For example a markdown document such as:
68-
69- # Title
70- foo bar
71-
72- ## Code Examples
73-
74- ```json
75- {"fuu": [{"bar": ["baz", "qux"]}]}
76- ```
77- ```yaml
78- hello: world
79- ```
80-
81- will return an Ezjsonm.value list in the order they are declared, e.g.
82-
83- [
84- {"fuu": [{"bar": ["baz", "qux"]}]},
85- {"hello": "world"},
86- ]
87- *)
88-
89 val to_string : t -> string
90 (** convert a note into a string *)
91
92 val of_string : data:string -> Slug.t -> t
93 (** decode a note from a string *)
94
95- val to_json : t -> [> Ezjsonm.t ]
96+ module Encoding : sig
97+ val to_string : style:[< `Raw | `Json | `Yaml ] -> t -> string
98+ end
99
100 module Filter : sig
101 type strategy = Keys | Fulltext
102 @@ -61,5 +32,5 @@ module Display : sig
103
104 type row = cell list
105
106- val to_stdout : style:[<`Fixed | `Simple | `Wide] -> t list -> unit
107+ val to_stdout : style:[< `Fixed | `Simple | `Wide ] -> t list -> unit
108 end