Skip to content

Commit

Permalink
Started the Templating module.
Browse files Browse the repository at this point in the history
  • Loading branch information
smondet committed Sep 29, 2009
1 parent c77b17f commit b6e4f98
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/app/dbw.ml
Expand Up @@ -5,7 +5,12 @@ open Dibrawi_std
let output_buffers html_name html_buffer err_buffer = (
ignore (Unix.system ("mkdir -p " ^ (Filename.dirname html_name)));
File.with_file_out html_name (fun o ->
Buffer.output_buffer o html_buffer
let html_content =
Dibrawi.Templating.html_default
~toc:"TOC TOC TOC"
~menu:"MENU MENU MENU"
~title:html_name (Buffer.contents html_buffer) in
output_string o html_content
);
let s = Buffer.contents err_buffer in
if s <> "" then (eprintf p"Errors for %s:\n%s\n" html_name s;);
Expand Down
6 changes: 4 additions & 2 deletions src/lib/dibrawi.ml
@@ -1,6 +1,8 @@

open Dibrawi_std

module Templating = Dibrawi_templating

module Info = struct
let version = 0
let version_string = sprintf p"The Dibrawi library, v %d" version
Expand Down Expand Up @@ -332,6 +334,7 @@ module Bibliography = struct
let bibtex = Sebib.BibTeX.str
end


module Brtx_transform = struct

(* TODO handle errors better *)
Expand All @@ -345,8 +348,7 @@ module Brtx_transform = struct
let url_hook =
Special_paths.rewrite_url ~from in
Bracetax.Transform.brtx_to_html
~writer ~doc:true ?title
?filename ~img_hook:url_hook ~url_hook ~input_char ();
~writer ?filename ~img_hook:url_hook ~url_hook ~input_char ();
(html_buffer, err_buffer)
)

Expand Down
163 changes: 163 additions & 0 deletions src/lib/dibrawi_templating.ml
@@ -0,0 +1,163 @@
open Dibrawi_std

type html_template =
?menu:string -> ?toc:string -> ?title:string -> ?footer:string -> string -> string

let html_default
?(menu="") ?(toc="") ?(title="") ?(footer="") content = (
let css =
"
div.sidepane {
position:fixed;
font-size: 80%;
/* float_on_right */
float: right;
width: 30%;
margin-left: 65%;
padding: 1em;
}
div.content {
margin-left: 5%;
border-right: 1px solid gray;
padding: 1em;
width: 55%;
}
body {
background-color:#ffffff;
color: black;
font-family: sans-serif;
min-width: 80em;
text-align: justify;
font-size: 80%;
}
div.p {
padding-bottom: 0em;
/* The debug border: */
/* border: thin silver solid; */
}
div.p + div.p { padding-top: 0.5em; }
div.header {
text-align: center;
/* border: #3E0C0C solid; */
padding-top: 2.1em;
padding-bottom: 2.05em;
margin-bottom: 3em;
}
h1 { font-size: 300%; font-variant: small-caps; }
div.authors { font-size: 150%; line-height: 200%; }
div.subtitle { font-size: 140%; font-style: italic; }
h2 { font-size: 180%; }
h3 { font-size: 150%; padding-top: 0.1em;padding-bottom: 0.05em;}
h4 { font-size: 130%; padding-top: 0.1em;padding-bottom: 0.05em;}
h5 { font-size: 105%; padding-top: 0.1em;padding-bottom: 0.05em;}
a {
text-decoration:none;
}
/* http://www.vision.to/add-a-small-icon-to-your-links-css-only.php */
a[href$='']:hover {text-decoration: underline;}
a[href$='.pdf']:hover {text-decoration: underline;}
a[href$=''] { color: #831825;}
a[href$='.pdf'] { color: #831825;}
tt {
font-family: monospace;
font-size: 120%;
color: #003300;
}
code, pre {
font-family: monospace;
/* letter-spacing: 1px; */
color: #003300;
}
pre {
/* border: dashed;
border-width: thin;
border-color: #dddddd;*/
position: relative;
/*background-color: #eeeeee;*/
left: 5%;
width: 70%;
clear: left;
/*padding-bottom: 1em;*/
}
ul, ol {
padding-top: 0em;
padding-bottom: 0em;
margin-top: 0em;
margin-bottom: 0em;
/* The debug border: */
/* border: thin silver solid; */
}
/*********** Tables ***********/
table.tablefigure {
margin-right:auto;
margin-left: auto;
border-collapse: collapse;
min-width: 80%;
margin-bottom: 1em;
}
caption.tablefigure {
/* margin-left:1em; */
/* min-width: 30%; */
caption-side:bottom;
}
/*caption.tablefigure:after { content: \" [\" attr(id) \"]\"; color: figid_color; }*/
div.tablefigure {
text-align: center;
font-size:90%;
border: thin #959595 solid;
margin: 0.5em;
padding: 0.5em;
/*float: right;
width: 50%;
margin-right: 0em;
padding: 0.5em;*/
}
"
in

sprintf p"\n\
<!DOCTYPE html\n\
PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
<!-- Generated with BraceTax -->\n\
<head>\n\
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n\
<title>%s</title>\n\
<style>\n\
%s\n\
</style>\n\
</head>\n\
<body>\n\
<div class=\"sidepane\">\n\
<b>%s</b><br/>\n\
%s\n\
<hr/>\n\
%s\n\
<hr/>\n\
%s\n\
</div>\n\
<div class=\"content\">\n\
%s\n\
</div>\n\
</body></html>\n\
"
title css title menu toc footer content
)

(* Generates a BIG closure !! *)
let load str = (
failwith "Templating.load not implemented"
)


1 change: 1 addition & 0 deletions src/lib/libdibrawi.mllib
@@ -1,2 +1,3 @@
Dibrawi_std
Dibrawi_templating
Dibrawi

0 comments on commit b6e4f98

Please sign in to comment.