-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08ea5a3
commit d162544
Showing
3 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
(* Ohm is © 2012 Victor Nicollet *) | ||
|
||
open BatPervasives | ||
open Ohm | ||
open Ohm.Universal | ||
|
||
type key = string | ||
type renaming = key -> string | ||
type item = [ `Page of (renaming -> Ohm.Html.writer) | ||
| `File of string ] | ||
type page = < | ||
body : renaming -> Ohm.Html.writer ; | ||
css : renaming -> string list ; | ||
js : renaming -> string list ; | ||
head : renaming -> string ; | ||
bcls : string list ; | ||
title : string option ; | ||
> | ||
type item = [ `Page of page | `File ] | ||
type site = (string,item) BatPMap.t | ||
|
||
let export ?(rename=identity) ?(render=Html.print_page_ctx) ?(public="/public/") ~server ~title site = | ||
|
||
let endpoints, definitions = | ||
BatPMap.foldi begin fun key item (endpoints, definitions) -> | ||
match item with `File -> (endpoints,definitions) | `Page page -> | ||
let endpoint, define = Action.declare server (rename key) Action.Args.none in | ||
BatPMap.add key endpoint endpoints, | ||
(define,page) :: definitions | ||
end site (BatPMap.empty, []) | ||
in | ||
|
||
let url server key = | ||
try Action.url (BatPMap.find key endpoints) server () | ||
with Not_found -> public ^ key | ||
in | ||
|
||
List.iter begin fun (define,page) -> | ||
|
||
define begin fun req res -> | ||
|
||
let rename = url (req # server) in | ||
let body = page # body rename in | ||
let css = page # css rename in | ||
let js = page # js rename in | ||
let head = page # head rename in | ||
let bcls = page # bcls in | ||
let title = BatOption.default title (page # title) in | ||
|
||
let! page = ohm $ render ~css ~js ~head ~body_classes:bcls ~title body in | ||
return $ Action.page page res | ||
|
||
end | ||
end definitions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters