Commits

Anonymous committed f2b8931

Do not fail if the default templates are not here.
It is for example useful for previous installations of stone where the
org-template do not exist

Comments (0)

Files changed (2)

 
     (* Open the templates file once
        The result is an association list (template filename -> content) *)
-    let templates_str = List.map
-      (fun tpl -> (tpl, string_dump (folder /^ data /^ tpl)))
+    let try_string_dump s =
+      try Some (string_dump s)  with
+        Sys_error _ -> None in
+    let templates_str = map_some
+      (fun tpl -> option_map
+        (fun dump -> (tpl, dump))
+        (try_string_dump (folder /^ data /^ tpl)))
       (default_template
        :: org_template
        :: (List.map snd conf.Conf.pages_templates)) in
   done;
   path
 
+let rec map_some f = function
+  | [] -> []
+  | x::xs -> match f x with
+    | None -> map_some f xs
+    | Some y -> y::(map_some f xs)
+
+let option_map f = function
+  | None -> None
+  | Some x -> Some (f x)
+
 let (|>) x f = f x
 let (@@) f x = f x
 let (%) f g = fun x -> f (g x)