diff --git a/Makefile b/Makefile index 44930ec..e124a85 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ OCB_FLAGS = -use-ocamlfind -I src # -I lib OCB = ocamlbuild $(OCB_FLAGS) -PKGS = opium.unix,omd,str,batteries,tyxml,lens,ptime,ptime.clock.os,re.str,lens.ppx_deriving,mustache +PKGS = toml,opium.unix,omd,str,batteries,tyxml,lens,ptime,ptime.clock.os,re.str,lens.ppx_deriving,mustache all: web diff --git a/src/html.ml b/src/html.ml index bd6ec80..8645700 100644 --- a/src/html.ml +++ b/src/html.ml @@ -31,7 +31,7 @@ let logarion_text ?text_tpl:(tpl=None) ymd = let of_ymd ?text_tpl:(tpl=None) lgrn ymd = logarion_page Ymd.(ymd.meta.title ^ " by " ^ ymd.meta.author.name) - Logarion.(lgrn.title) + Logarion.Configuration.(lgrn.title) (logarion_text ~text_tpl:tpl ymd) |> to_string @@ -41,7 +41,7 @@ let article_link (file, meta) = ] let of_file_meta_pairs ?listing_tpl:(tpl=None) lgrn file_meta_pairs = - let t = Logarion.(lgrn.title) in + let t = Logarion.Configuration.(lgrn.title) in logarion_page t t (div [ h2 [pcdata "Articles"]; @@ -55,31 +55,34 @@ let form lgrn ymd = let input_set title name value = p [ label [ span [pcdata title]; input ~a:[a_name name; a_value value] () ] ] in + let either a b = if a <> "" then a else b in logarion_page "Compose" "Article composition" Ymd.(div [ - form - ~a:[a_method `Post; a_action (uri_of_string "/post"); a_accept_charset ["utf-8"];] - [ - fieldset - ~legend:(legend [pcdata "Article"]) + form + ~a:[a_method `Post; a_action (uri_of_string "/post"); a_accept_charset ["utf-8"];] [ - input_set "Title" "title" ymd.meta.title; - input_set "Author name" "name" ymd.meta.author.name; - input_set "Author email" "email" ymd.meta.author.email; - input_set "Topics" "topics" (String.concat ", " ymd.meta.topics); - input_set "Categories" "categories" (String.concat ", " ymd.meta.categories); - input_set "Keywords" "keywords" (String.concat ", " ymd.meta.keywords); - input_set "Series" "series" (String.concat ", " ymd.meta.series); - input_set "Abstract" "abstract" ymd.meta.abstract; - p [ - label [ - span [pcdata"Text"]; - textarea ~a:[a_name "body"] (pcdata ymd.body); + fieldset + ~legend:(legend [pcdata "Article"]) + [ + input_set "Title" "title" ymd.meta.title; + input_set "Author name" "name" + (either ymd.meta.author.name Logarion.Configuration.(lgrn.owner)); + input_set "Author email" "email" + (either ymd.meta.author.email Logarion.Configuration.(lgrn.email)); + input_set "Topics" "topics" (String.concat ", " ymd.meta.topics); + input_set "Categories" "categories" (String.concat ", " ymd.meta.categories); + input_set "Keywords" "keywords" (String.concat ", " ymd.meta.keywords); + input_set "Series" "series" (String.concat ", " ymd.meta.series); + input_set "Abstract" "abstract" ymd.meta.abstract; + p [ + label [ + span [pcdata"Text"]; + textarea ~a:[a_name "body"] (pcdata ymd.body); + ]; ]; - ]; - p [ button ~a:[a_button_type `Submit] [pcdata "Submit"] ]; + p [ button ~a:[a_button_type `Submit] [pcdata "Submit"] ]; + ] ] - ] - ]) + ]) |> to_string diff --git a/src/logarion.ml b/src/logarion.ml index 57d4124..384343e 100644 --- a/src/logarion.ml +++ b/src/logarion.ml @@ -1,4 +1,21 @@ -type logarion = { title : string } +module Configuration = struct + type t = { + title : string; + owner : string; + email : string; + } + + let of_filename fn = + let result = Toml.Parser.from_filename fn in + match result with + | `Error (str, loc) -> { title = ""; owner = ""; email = "" } + | `Ok tbl -> + let str_of key_name = + let open TomlLenses in + let value_option = get tbl (key "general" |-- table |-- key key_name |-- string) in + match value_option with Some v -> v | None -> "" in + { title = str_of "title"; owner = str_of "owner"; email = str_of "email" } +end let load_file f = let ic = open_in f in diff --git a/src/web.ml b/src/web.ml index 2fdccf8..06417dc 100644 --- a/src/web.ml +++ b/src/web.ml @@ -16,7 +16,7 @@ let html_response h = `Html h |> respond' let ymd_or_error y = match y with Some (path, meta) -> Logarion.of_file ("ymd/" ^ path) | None -> Ymd.blank_ymd -let lgrn = Logarion.({ title = "Test" }) +let lgrn = Logarion.Configuration.of_filename "logarion.toml" let () = let (>>=) = Lwt.(>>=)