+# Nitdoc base page
+abstract class NitdocPage
+
+ var dot_dir: nullable String
+ var source: nullable String
+ var ctx: NitdocContext
+
+ init(ctx: NitdocContext) do
+ self.ctx = ctx
+ end
+
+ protected fun head do
+ append("<meta charset='utf-8'/>")
+ append("<script type='text/javascript' src='scripts/jquery-1.7.1.min.js'></script>")
+ append("<script type='text/javascript' src='scripts/ZeroClipboard.min.js'></script>")
+ append("<script type='text/javascript' src='quicksearch-list.js'></script>")
+ append("<script type='text/javascript' src='scripts/base64.js'></script>")
+ append("<script type='text/javascript' src='scripts/github.js'></script>")
+ append("<script type='text/javascript' src='scripts/js-facilities.js'></script>")
+ append("<link rel='stylesheet' href='styles/main.css' type='text/css' media='screen'/>")
+ var title = ""
+ if ctx.opt_custom_title.value != null then
+ title = " | {ctx.opt_custom_title.value.to_s}"
+ end
+ append("<title>{self.title}{title}</title>")
+ end
+
+ protected fun menu do
+ if ctx.opt_custom_menu_items.value != null then
+ append(ctx.opt_custom_menu_items.value.to_s)
+ end
+ end
+
+ protected fun title: String is abstract
+
+ protected fun header do
+ append("<header>")
+ append("<nav class='main'>")
+ append("<ul>")
+ menu
+ append("</ul>")
+ append("</nav>")
+ append("</header>")
+ end
+
+ protected fun content is abstract
+
+ protected fun footer do
+ if ctx.opt_custom_footer_text.value != null then
+ append("<footer>{ctx.opt_custom_footer_text.value.to_s}</footer>")
+ end
+ end
+
+ # Generate a clickable graphviz image using a dot content
+ protected fun generate_dot(dot: String, name: String, alt: String) do
+ var output_dir = dot_dir
+ if output_dir == null then return
+ var file = new OFStream.open("{output_dir}/{name}.dot")
+ file.write(dot)
+ file.close
+ sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}")
+ append("<article class='graph'>")
+ append("<img src='{name}.png' usemap='#{name}' style='margin:auto' alt='{alt}'/>")
+ append("</article>")
+ var fmap = new IFStream.open("{output_dir}/{name}.map")
+ append(fmap.read_all)
+ fmap.close
+ end
+
+ # Add a (source) link for a given location
+ protected fun show_source(l: Location): String
+ do
+ if source == null then
+ return "({l.file.filename.simplify_path})"
+ else
+ # THIS IS JUST UGLY ! (but there is no replace yet)
+ var x = source.split_with("%f")
+ source = x.join(l.file.filename.simplify_path)
+ x = source.split_with("%l")
+ source = x.join(l.line_start.to_s)
+ x = source.split_with("%L")
+ source = x.join(l.line_end.to_s)
+ return " (<a target='_blank' title='Show source' href=\"{source.to_s}\">source</a>)"
+ end
+ end
+
+ # Render the page as a html string
+ protected fun render do
+ append("<!DOCTYPE html>")
+ append("<head>")
+ head
+ append("</head>")
+ append("<body>")
+ header
+ append("<div class='page'>")
+ content
+ append("</div>")
+ footer
+ append("</body>")
+ end
+
+ # Append a string to the page
+ fun append(s: String) do out.write(s)
+
+ # Save html page in the specified file
+ fun save(file: String) do
+ self.out = new OFStream.open(file)
+ render
+ self.out.close
+ end
+ private var out: nullable OFStream
+end
+
+# The overview page