Permalink
Browse files

Simple templating system added.

  • Loading branch information...
1 parent 2cc73de commit 321a5d15900a270305dd72ccf2c9d3d075ffd04c @Chris00 Chris00 committed May 5, 2011
Showing with 280 additions and 20 deletions.
  1. +9 −0 .bzrignore
  2. +53 −0 Makefile
  3. +74 −0 OCAML.html
  4. +42 −0 OCAML.html.ml
  5. +23 −0 OCAML.html.mli
  6. +19 −0 _oasis
  7. +9 −0 _tags
  8. +34 −0 build.ml
  9. +1 −0 conf.ml
  10. +0 −20 index.html
  11. +16 −0 ocaml.css
View
@@ -0,0 +1,9 @@
+# OASIS / ocamlbuild -*-conf-unix-*-
+_build/
+_tags
+myocamlbuild.ml
+*.data
+setup.ml
+# Generated files
+OCAML.ml
+OCAML.mli
View
@@ -0,0 +1,53 @@
+PKGNAME = $(shell oasis query name)
+PKGVERSION = $(shell oasis query version)
+PKG_TARBALL = $(PKGNAME)-$(PKGVERSION).tar.gz
+
+WEB = forge.ocamlcore.org:/home/groups/ocamlweb/htdocs/
+
+DISTFILES = AUTHORS.txt INSTALL.txt README.txt _oasis \
+ Makefile myocamlbuild.ml setup.ml config.ml _tags \
+ $(wildward *.html)
+
+.PHONY: all byte native configure doc install uninstall reinstall upload-doc
+
+all: native
+ ./build.native
+ cp ocaml.css en
+ cp -a images/ en/
+
+byte native: configure
+ ocaml setup.ml -build
+
+configure: setup.ml
+ ocaml $< -configure
+
+setup.ml: _oasis
+ oasis setup
+
+doc install uninstall reinstall:
+ ocaml setup.ml -$@
+
+upload-doc: doc
+ scp -C -p -r _build/API.docdir/ $(WEB)
+
+# Make a tarball
+.PHONY: dist tar
+dist tar: $(DISTFILES)
+ mkdir $(PKGNAME)-$(PKGVERSION)
+ cp --parents -r $(DISTFILES) $(PKGNAME)-$(PKGVERSION)/
+ tar -zcvf $(PKG_TARBALL) $(PKGNAME)-$(PKGVERSION)
+ rm -rf $(PKGNAME)-$(PKGVERSION)
+
+
+.PHONY: svn
+svn:
+ bzr push svn+ssh://scm.ocamlcore.org/svnroot/ocamlweb/template
+
+.PHONY: clean distclean
+clean::
+ ocaml setup.ml -clean
+ $(RM) $(PKG_TARBALL)
+
+distclean:
+ ocaml setup.ml -distclean
+ $(RM) $(wildcard *.ba[0-9] *.bak *~ *.odocl) setup.log
View
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <!-- Set document compatibility mode to IE8Mode. -->
+ <meta http-equiv="X-UA-Compatible" content="IE=8" />
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title >OCaml portal | ${title}</title>
+ <meta name="author"
+ content="Christophe Troestler, Esther Baruk, Ashish Agarwal" />
+ <meta name="description" content="${description}" />
+ <meta name="keywords" content="${keywords}" />
+ <meta name="generator" content="OCaml" />
+
+ <link rel="shortcut icon"
+ href="${shortcut_icon}" />
+ <link rel="stylesheet" type="text/css" media="all"
+ href="${url_base}ocaml.css" />
+ <link ml:replace="stylesheet" />
+ <script ml:replace="javascript" ></script>
+
+ <meta property="og:title" content="${title}"/>
+ <meta property="og:type" content="non_profit" />
+
+ <meta name="robots" content="all" />
+ </head>
+ <body>
+ <div id="header">
+ <form class="search-box" method="get"
+ action="http://www.google.com/search">
+ <div>
+ <input type="text" name="q" value="${search_name}..."
+ onblur="if(this.value=='') this.value='${search_name}...';"
+ onfocus="if(this.value=='${search_name}...') this.value='';"
+ />
+ <button type="submit"
+ ><img src="${url_base}images/gosearch.gif"
+ alt="Search" /></button>
+ </div>
+ </form>
+ <img src="https://static.ocamlcore.org/official/images/logo-big.png"
+ alt="OCaml Community Logo"
+ width="64" height="64" />
+ <span class="name">OCaml</span>
+ <span class="slogan">Fun with an efficient and expressive language</span>
+ <span class="login">Login/Create an account</span>
+
+ <div class="menu" ml:content="menu" >
+ <ul><li>menu entry 1</li></ul>
+ </div>
+ </div>
+ <span class="navigation-bar">
+ <span ml:replace="navigation_bar">navigation bar</span>
+ </span>
+
+ <div id="main">
+
+ <div id="advertisements" ml:content="advertisements"
+ ml:strip="if empty">
+ Advertisements (if any).
+ <div class="news">news</div>
+ <div class="actions">actions</div>
+ </div>
+
+ <span ml:replace="main">Main text area.</span>
+ </div>
+
+
+ <!-- Footer -->
+ <div id="footer">
+
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,42 @@
+open Nethtml
+
+let concat_path p f =
+ if p = "" then f
+ else if p.[String.length p - 1] = '/' then p ^ f
+ else p ^ "/" ^ f
+
+let separation_arrow url_base =
+ Element("span", ["class", "separation"],
+ [Element("img", ["src", url_base ^ "images/right_arrow.png";
+ "alt", "&gt;"], [])])
+
+let rec transform_path sep p = match p with
+ | [] -> []
+ | [(a, _)] -> [sep; Data a]
+ | (a, rev) :: tl ->
+ let el = Element("a", ["href", rev], [Data a]) in
+ sep :: el :: transform_path sep tl
+
+let stylesheet tpl ?(rel_base=true) url =
+ Set.stylesheet tpl begin fun t ->
+ let url = if rel_base then concat_path (Get.url_base t) url else url in
+ let s = Element("link", ["rel", "stylesheet"; "type", "text/css";
+ "media","all"; "href", url],
+ []) in
+ [s]
+ end
+
+let javascript tpl ?(rel_base=true) url =
+ Set.javascript tpl begin fun t ->
+ let url = if rel_base then concat_path (Get.url_base t) url else url in
+ [Element("script", ["type", "text/javascript"; "src", url], [])]
+ end
+
+let navigation tpl path =
+ Set.navigation_bar tpl begin fun t ->
+ let sep = separation_arrow (Get.url_base t) in
+ transform_path sep path
+ end
+
+let navigation_of_path tpl ?(prefix=[]) p =
+ navigation tpl (prefix @ Template.Path.navigation p)
View
@@ -0,0 +1,23 @@
+(* @hide stylesheet *)
+val stylesheet : t -> ?rel_base:bool -> string -> t
+(** [stylesheet tpl url] add the CSS file given by [url] to the
+ stylesheet declarations. If [rel_base] is true (the default),
+ interpret [url] as a path relative to the base URL (as set in
+ [tpl]). *)
+
+(* @hide javascript *)
+val javascript : t -> ?rel_base:bool -> string -> t
+(** [javascript tpl url] add the javascript file given by [url] to the
+ headers of the page. If [rel_base] is [true] (the default),
+ interpret [url] as a path relative to the base URL (as set in
+ [tpl]). *)
+
+(* @hide navigation_bar *)
+val navigation : t -> (string * string) list -> t
+(** [navigation t nav] set the navigation bar from the information in
+ [nav]. The couples of [nav] are of the form [(text, URL)]. *)
+
+val navigation_of_path : t -> ?prefix:(string * string) list ->
+ Template.Path.t -> t
+(** [navigation_of_path t path] add a navigation bar based on the
+ [path]. *)
View
19 _oasis
@@ -0,0 +1,19 @@
+# -*-conf-*-
+OASISFormat: 0.2
+Name: web-portal
+Version: 0.5
+Synopsis: OCaml Web portal
+Description: Web portal for ocaml.org
+Authors: Christophe Troestler
+License: LGPL-3.0 with OCaml linking exception
+Plugins: META (0.2), StdFiles (0.2)
+Homepage: http://forge.ocamlcore.org/projects/ocamlweb/
+PostConfCommand: compile_template OCAML.html
+
+Executable build
+ Path: .
+ MainIs: build.ml
+ BuildDepends: template
+ CompiledObject: best
+ BuildTools: ocamlbuild
+ Install: true
View
9 _tags
@@ -0,0 +1,9 @@
+# OASIS_START
+# DO NOT EDIT (digest: 10ce862acd55154b3f596ff206436903)
+# Executable build
+<build.{native,byte}>: pkg_template
+<*.ml{,i}>: pkg_template
+# OASIS_STOP
+
+<**/*.ml>: annot
+
View
@@ -0,0 +1,34 @@
+open Printf
+open Nethtml
+module Path = Template.Path
+
+
+(* Settings common to all pages. *)
+let tpl = OCAML.search_name OCAML.empty "Search"
+let tpl = OCAML.shortcut_icon tpl
+ "https://static.ocamlcore.org/official/images/favicon.ico"
+
+let () =
+ let b = Template.Binding.make() in
+
+ let re_filter = Str.regexp "\\(menu\\|OCAML\\).*" in
+ let filter p = not(Str.string_match re_filter (Path.filename p) 0) in
+
+ let is_index = Str.regexp "index\\..+" in
+
+ let langs = ["en"] in
+ Template.iter_html ~filter ~langs "." begin fun lang p ->
+ printf "Processing %s\n" (Path.full p);
+ let tpl = OCAML.url_base tpl (Template.Path.to_base p) in
+ let page = Template.read (Path.full p) ~bindings:b in
+ let tpl = OCAML.title tpl (Template.title_of page) in
+ let body = Template.body_of page in
+ let body = Template.protect_emails body in
+ let tpl = OCAML.main tpl body in
+
+ (* let tpl = add_menu tpl lang p in *)
+
+ let tpl = OCAML.navigation_of_path tpl p in
+
+ OCAML.render tpl
+ end
View
@@ -0,0 +1 @@
+let email = "info@ocaml.org"
View
@@ -9,26 +9,6 @@
<link href="ocaml.css" media="all" type="text/css" rel="stylesheet">
</head>
<body>
- <div id="header">
- <form class="search-box" method="get"
- action="http://www.google.com/search">
- <div>
- <input type="text" name="q" value="${search_name}..."
- onblur="if(this.value=='') this.value='${search_name}...';"
- onfocus="if(this.value=='${search_name}...') this.value='';"
- />
- <button type="submit"
- ><img src="${url_base}images/gosearch.gif"
- alt="Search" ></button>
- </div>
- </form>
- <img src="https://static.ocamlcore.org/official/images/logo-big.png"
- alt="OCaml Community Logo"
- width="64" height="64" />
- <span class="name">OCaml</span>
- <span class="slogan">Fun with an efficient and expressive language</span>
- <span class="login">Login/Create an account</span>
- </div>
<div class="dynamic">
<p>Dynamic content</p>
View
@@ -49,6 +49,22 @@ body {
float: right;
}
+
+.navigation-bar {
+ font: 83% arial, helvetica, sans-serif; /* as the menu */
+}
+
+.navigation-bar a {
+ border: 0;
+ margin: 0;
+}
+
+.navigation-bar a:hover {
+ background-color: transparent;
+ border: 0;
+ text-decoration: underline;
+}
+
/* Main
**********************************************************************/

0 comments on commit 321a5d1

Please sign in to comment.