Skip to content

Commit 778191d

Browse files
author
Armaël Guéneau
committed
Add utility functions to read a template from a channel/file
1 parent 3b9a188 commit 778191d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/mustache.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ let parse_lx (lexbuf: Lexing.lexbuf) : Locs.t =
148148
Mustache_lexer.(handle_standalone mustache lexbuf)
149149

150150
let of_string s = parse_lx (Lexing.from_string s)
151+
let of_channel c = parse_lx (Lexing.from_channel c)
152+
let of_file f =
153+
let c = open_in f in
154+
let ret = of_channel c in
155+
close_in c;
156+
ret
151157

152158
(* Utility module, that helps looking up values in the json data during the
153159
rendering phase. *)
@@ -209,6 +215,8 @@ module Without_locations = struct
209215

210216
let parse_lx lexbuf = erase_locs (parse_lx lexbuf)
211217
let of_string s = erase_locs (of_string s)
218+
let of_channel c = erase_locs (of_channel c)
219+
let of_file f = erase_locs (of_file f)
212220

213221
let pp = pp
214222
let to_formatter = pp

lib/mustache.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ and partial =
4646
(** Read *)
4747
val parse_lx : Lexing.lexbuf -> t
4848
val of_string : string -> t
49+
val of_channel : in_channel -> t
50+
val of_file : string -> t
4951

5052
(** [pp fmt template] print a template as raw mustache to
5153
the formatter [fmt]. *)

0 commit comments

Comments
 (0)