Permalink
Browse files

Building renderers

  • Loading branch information...
1 parent cb9991f commit 3c493b0fcd9d63803c24021af59e9494b7ef1404 @VictorNicollet committed Sep 25, 2012
Showing with 34 additions and 1 deletion.
  1. +14 −0 ohmStatic/ohmStatic.ml
  2. +20 −1 ohmStatic/ohmStatic.mli
View
@@ -40,6 +40,20 @@ let canonical = function
let default_render _ ?css ?js ?head ?favicon ?body_classes ~title writer =
return (O.page ?css ?js ?head ?favicon ?body_classes ~title writer)
+let wrap template key ?css ?js ?head ?favicon ?body_classes ~title writer =
+ let! writer = ohm (template writer) in
+ return (O.page ?css ?js ?head ?favicon ?body_classes ~title writer)
+
+let prefixed_render ~default list key =
+ let page =
+ try snd (List.find (fun (prefix,_) -> BatString.starts_with key prefix) list)
+ with _ -> default
+ in
+ page key
+
+let with_context ctx page key ?css ?js ?head ?favicon ?body_classes ~title writer =
+ Run.with_context ctx (page key ?css ?js ?head ?favicon ?body_classes ~title writer)
+
let export ?(rename=canonical) ?(render=default_render) ?(public="/") ~server ~title site =
let files, endpoints, definitions =
View
@@ -51,13 +51,32 @@ type site = (string,item) BatPMap.t
*)
val canonical : key -> string
+(** Create a renderer from a wrapper template : the page contents are passed to the
+ wrapper template function, and then rendered with the vanilla [O.page]. *)
+val wrap :
+ (Ohm.Html.writer -> ('ctx, Ohm.Html.writer) Ohm.Run.t)
+ -> (key -> 'ctx Ohm.Html.ctxrenderer)
+
+(** Combine multiple renderers : select which renderer to use based on the prefix
+ of the key of the page being rendered. *)
+val prefixed_render :
+ default:(key -> 'ctx Ohm.Html.ctxrenderer)
+ -> (string * (key -> 'ctx Ohm.Html.ctxrenderer)) list
+ -> (key -> 'ctx Ohm.Html.ctxrenderer)
+
+(** Provide a context for rendering *)
+val with_context :
+ 'ctx
+ -> (key -> 'ctx Ohm.Html.ctxrenderer)
+ -> (key -> unit Ohm.Html.ctxrenderer)
+
(** Export a static site.
@param rename A function that provides the path of each item. By default,
{!val:canonical} is applied to the key.
@param server The server on which the site should run.
@param title The default title to be used, if no title is provided by the page.
@param render The function which is used to render the item. By default,
- this is the vanilla [Ohm.Html.print_page].
+ this is the vanilla [Ohm.page].
@param public The url prefix for files that are available for public download.
By default, this is ["/public"] and points to the [www/public] directory.
*)

0 comments on commit 3c493b0

Please sign in to comment.