[valadoc] libvala/html: introduce new link helper



commit 2a9c5df1bee5cb745679d869d2c9992789b418ea
Author: Florian Brosch <flo brosch gmail com>
Date:   Tue Feb 23 13:39:36 2010 +0100

    libvala/html: introduce new link helper

 icons/devhelpstyle.css                          |   38 ++++
 src/doclets/devhelp/doclet.vala                 |   92 +----------
 src/doclets/htm/doclet.vala                     |   79 +---------
 src/doclets/valadoc.org/doclet.vala             |   76 +--------
 src/doclets/xml/doclet.vala                     |    1 +
 src/libvaladoc/Makefile.am                      |    1 +
 src/libvaladoc/documentation/documentation.vala |    5 +
 src/libvaladoc/documentation/wiki.vala          |   35 +++--
 src/libvaladoc/html/basicdoclet.vala            |   25 ++-
 src/libvaladoc/html/globals.vala                |   10 +-
 src/libvaladoc/html/htmlrenderer.vala           |    4 +-
 src/libvaladoc/html/linkhelper.vala             |  205 +++++++++++++++++++++++
 12 files changed, 302 insertions(+), 269 deletions(-)
---
diff --git a/icons/devhelpstyle.css b/icons/devhelpstyle.css
index 9e40478..fe69453 100644
--- a/icons/devhelpstyle.css
+++ b/icons/devhelpstyle.css
@@ -492,3 +492,41 @@ ul.no_bullet > li {
 	text-decoration: underline;
 }
 
+.box {
+}
+.box .headline {
+	background-color: #eeeeff;
+	border-color: #aaaaff;
+	border-style: solid;
+	border-width: 1px;
+	margin: auto;
+	width: 90%;
+	margin-top: 20px;
+}
+.box .text {
+	font-weight: bold;  
+	float: left;
+}
+.box .toggle {
+	text-align: right;
+	float: clear;
+}
+.box .content {
+	border-color: #aaaaff;
+	border-width: 0 1 1 1;
+	border-style: solid;
+	overflow: auto;
+	display: none;
+	margin: auto;
+	width: 90%;
+}
+.box .column {
+	float: left;
+	width: 33%;
+}
+
+.namespace_note {
+}
+.package_note {
+}
+
diff --git a/src/doclets/devhelp/doclet.vala b/src/doclets/devhelp/doclet.vala
index 6dfef15..da38805 100755
--- a/src/doclets/devhelp/doclet.vala
+++ b/src/doclets/devhelp/doclet.vala
@@ -26,83 +26,6 @@ using Valadoc.Html;
 using Gee;
 
 
-namespace Valadoc.Devhelp {
-	public string? get_html_link ( Settings settings, Documentation element, Documentation? pos ) {
-		if ( element is Visitable ) {
-			if ( ((Visitable)element).is_visitor_accessible (settings) == false ) {
-				return null;
-			}
-		}
-
-		if ( element is Api.Node ) {
-			if ( ((Api.Node)element).package.is_visitor_accessible (settings) == false ) {
-				return null;
-			}
-		}
-
-		if ( pos == null || ((pos!=null)?(pos is WikiPage)? ((WikiPage)pos).name=="index.valadoc": false : false) ) {
-			if ( element is Package ) {
-				return Path.build_filename(((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename("..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				if ( pos == element ) {
-					return "#";
-				}
-				else {
-					string wikiname = ((WikiPage)element).name;
-					wikiname = wikiname.ndup ( wikiname.len()-8 );
-					wikiname = wikiname.replace("/", ".") + ".html";
-					return Path.build_filename( "content", wikiname );
-				}
-			}
-		}
-		else if ( pos is Api.Node ) {
-			if ( element is Package ) {
-				return Path.build_filename("..", ((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename( "..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				string wikiname = ((WikiPage)element).name;
-				wikiname = wikiname.ndup ( wikiname.len()-8 );
-				wikiname = wikiname.replace("/", ".")+".html";
-				if ( wikiname == "index.html" ) {
-					return Path.build_filename( "..", wikiname );
-				}
-				else {
-					return Path.build_filename( "..", "content", wikiname );
-				}
-			}
-		}
-		else if ( pos is WikiPage ) {
-			if ( element is Package ) {
-				return Path.build_filename("..", ((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename( "..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				string wikiname = ((WikiPage)element).name;
-				wikiname = wikiname.ndup ( wikiname.len()-8 );
-				wikiname = wikiname.replace("/", ".")+".html";
-
-				if ( wikiname == "index.html" ) {
-					return Path.build_filename("..", wikiname);
-				}
-				else {
-					return wikiname;
-				}
-			}
-		}
-		return null;
-	}
-}
-
-
 
 public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 	private const string css_path_wiki = "../devhelpstyle.css";
@@ -114,12 +37,12 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 
 	private ArrayList<Api.Node> nodes = new ArrayList<Api.Node> ();
 	private string package_dir_name = ""; // remove
-	private Api.Tree tree;
 
 	private Devhelp.MarkupWriter _devhelpwriter;
 
 	construct {
 		_renderer = new HtmlRenderer (this);
+		icon_directory = "";
 	}
 
 	private string get_path (Api.Node element) {
@@ -131,11 +54,8 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 	}
 
 	public override void process (Settings settings, Api.Tree tree) {
-		this.settings = settings;
-		this.tree = tree;
-
+		base.process (settings, tree);
 		DirUtils.create (this.settings.path, 0777);
-
 		write_wiki_pages (tree, css_path_wiki, js_path_wiki, Path.build_filename (this.settings.path, this.settings.pkg_name, "content"));
 		tree.accept (this);
 	}
@@ -152,7 +72,6 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 		string imgpath = GLib.Path.build_filename (path, "img");
 		string devpath = GLib.Path.build_filename (path, pkg_name + ".devhelp2");
 
-
 		WikiPage wikipage = null;
 		if (this.settings.pkg_name == package.name && this.tree.wikitree != null) {
 			wikipage = this.tree.wikitree.search ("index.valadoc");
@@ -169,6 +88,7 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 
 		_devhelpwriter.start_book (pkg_name+" Reference Manual", "vala", "index.htm", "", "", "");
 
+
 		GLib.FileStream file = GLib.FileStream.open (filepath, "w");
 		writer = new Html.MarkupWriter (file);
 		_renderer.set_writer (writer);
@@ -182,7 +102,6 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 		package.accept_all_children (this);
 		_devhelpwriter.end_chapters ();
 
-
 		_devhelpwriter.start_functions ();
 		foreach (Api.Node node in this.nodes) {
 			string typekeyword = "";
@@ -202,7 +121,7 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 				typekeyword = "struct";
 			}
 
-			_devhelpwriter.simple_tag ("keyword", {"type", typekeyword, "name", node.name, "link", get_html_link_imp (settings, node, null)});
+			_devhelpwriter.simple_tag ("keyword", {"type", typekeyword, "name", node.name, "link", get_link (node, node.package)});
 		}
 		_devhelpwriter.end_functions ();
 
@@ -287,9 +206,11 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 	}
 
 	public override void visit_error_code (ErrorCode item) {
+		process_node (item);
 	}
 
 	public override void visit_enum_value (Api.EnumValue item) {
+		process_node (item);
 	}
 
 	public override void visit_delegate (Delegate item) {
@@ -307,7 +228,6 @@ public class Valadoc.Devhelp.Doclet : Valadoc.Html.BasicDoclet {
 
 [ModuleInit]
 public Type register_plugin () {
-	Valadoc.Html.get_html_link_imp = Valadoc.Devhelp.get_html_link;
 	return typeof (Valadoc.Devhelp.Doclet);
 }
 
diff --git a/src/doclets/htm/doclet.vala b/src/doclets/htm/doclet.vala
index aaf2ccb..a9e5176 100755
--- a/src/doclets/htm/doclet.vala
+++ b/src/doclets/htm/doclet.vala
@@ -26,82 +26,6 @@ using Valadoc.Html;
 using Gee;
 
 
-namespace Valadoc {
-	public string? get_html_link ( Settings settings, Documentation element, Documentation? pos ) {
-		if ( element is Visitable ) {
-			if (! ((Visitable) element).is_visitor_accessible (settings)) {
-				return null;
-			}
-		}
-
-		if ( element is Api.Node ) {
-			if (! ((Api.Node) element).package.is_visitor_accessible (settings)) {
-				return null;
-			}
-		}
-
-		if ( pos == null || ((pos!=null)?(pos is WikiPage)? ((WikiPage)pos).name=="index.valadoc": false : false) ) {
-			if ( element is Package ) {
-				return Path.build_filename(((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename( ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				if ( pos == element ) {
-					return "#";
-				}
-				else {
-					string wikiname = ((WikiPage)element).name;
-					wikiname = wikiname.ndup ( wikiname.len()-8 );
-					wikiname = wikiname.replace("/", ".") + ".html";
-					return Path.build_filename( "content", wikiname );
-				}
-			}
-		}
-		else if ( pos is Api.Node ) {
-			if ( element is Package ) {
-				return Path.build_filename("..", ((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename( "..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				string wikiname = ((WikiPage)element).name;
-				wikiname = wikiname.ndup ( wikiname.len()-8 );
-				wikiname = wikiname.replace("/", ".")+".html";
-				if ( wikiname == "index.html" ) {
-					return Path.build_filename( "..", wikiname );
-				}
-				else {
-					return Path.build_filename( "..", "content", wikiname );
-				}
-			}
-		}
-		else if ( pos is WikiPage ) {
-			if ( element is Package ) {
-				return Path.build_filename("..", ((Package)element).name, "index.htm");
-			}
-			else if ( element is Api.Node ) {
-				return Path.build_filename( "..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html" );
-			}
-			else if ( element is WikiPage ) {
-				string wikiname = ((WikiPage)element).name;
-				wikiname = wikiname.ndup ( wikiname.len()-8 );
-				wikiname = wikiname.replace("/", ".")+".html";
-
-				if ( wikiname == "index.html" ) {
-					return Path.build_filename("..", wikiname);
-				}
-				else {
-					return wikiname;
-				}
-			}
-		}
-		return null;
-	}
-}
-
 
 public class Valadoc.HtmlDoclet : Valadoc.Html.BasicDoclet {
 	private const string css_path_package = "style.css";
@@ -122,7 +46,7 @@ public class Valadoc.HtmlDoclet : Valadoc.Html.BasicDoclet {
 	}
 
 	public override void process (Settings settings, Api.Tree tree) {
-		this.settings = settings;
+		base.process (settings, tree);
 
 		DirUtils.create (this.settings.path, 0777);
 		copy_directory (icons_dir, settings.path);
@@ -254,7 +178,6 @@ public class Valadoc.HtmlDoclet : Valadoc.Html.BasicDoclet {
 
 [ModuleInit]
 public Type register_plugin ( ) {
-	Valadoc.Html.get_html_link_imp = Valadoc.get_html_link;
 	return typeof ( Valadoc.HtmlDoclet );
 }
 
diff --git a/src/doclets/valadoc.org/doclet.vala b/src/doclets/valadoc.org/doclet.vala
index fb48291..0e184db 100755
--- a/src/doclets/valadoc.org/doclet.vala
+++ b/src/doclets/valadoc.org/doclet.vala
@@ -26,80 +26,10 @@ using Valadoc.Html;
 using Gee;
 
 
-namespace Valadoc.ValadocOrg {
-	public string? get_html_link (Settings settings, Documentation element, Documentation? pos) {
-		if (element is Visitable) {
-			if (((Visitable)element).is_visitor_accessible (settings) == false) {
-				return null;
-			}
-		}
-
-		if (element is Api.Node) {
-			if (((Api.Node)element).package.is_visitor_accessible (settings) == false) {
-				return null;
-			}
-		}
-
-		if ( pos == null || ((pos!=null)?(pos is WikiPage)? ((WikiPage)pos).name=="index.valadoc": false : false) ) {
-			if (element is Package) {
-				return Path.build_filename(((Package)element).name, "index.htm");
-			} else if ( element is Api.Node ) {
-				return Path.build_filename("..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html");
-			} else if (element is WikiPage) {
-				if (pos == element) {
-					return "#";
-				}
-				else {
-					string wikiname = ((WikiPage)element).name;
-					wikiname = wikiname.ndup (wikiname.len()-8);
-					wikiname = wikiname.replace ("/", ".") + ".html";
-					return Path.build_filename ("content", wikiname);
-				}
-			}
-		}
-		else if (pos is Api.Node) {
-			if (element is Package) {
-				return Path.build_filename("..", ((Package)element).name, "index.htm");
-			} else if (element is Api.Node) {
-				return Path.build_filename("..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html");
-			} else if ( element is WikiPage ) {
-				string wikiname = ((WikiPage)element).name;
-				wikiname = wikiname.ndup (wikiname.len()-8);
-				wikiname = wikiname.replace ("/", ".")+".html";
-				if ( wikiname == "index.html" ) {
-					return Path.build_filename ("..", wikiname);
-				} else {
-					return Path.build_filename ("..", "content", wikiname);
-				}
-			}
-		}
-		else if ( pos is WikiPage ) {
-			if ( element is Package ) {
-				return Path.build_filename ("..", ((Package)element).name, "index.htm");
-			} else if (element is Api.Node) {
-				return Path.build_filename ("..", ((Api.Node)element).package.name, ((Api.Node)element).full_name()+".html");
-			} else if (element is WikiPage) {
-				string wikiname = ((WikiPage) element).name;
-				wikiname = wikiname.ndup ( wikiname.len ()-8 );
-				wikiname = wikiname.replace ("/", ".")+".html";
-
-				if (wikiname == "index.html") {
-					return Path.build_filename ("..", wikiname);
-				} else {
-					return wikiname;
-				}
-			}
-		}
-		return null;
-	}
-}
-
-
 
 public class Valadoc.ValadocOrg.Doclet : Valadoc.Html.BasicDoclet {
 	private ArrayList<Api.Node> nodes = new ArrayList<Api.Node> ();
 	private string package_dir_name = ""; // remove
-	private Api.Tree tree;
 
 	construct {
 		_renderer = new ValadocOrg.HtmlRenderer (this);
@@ -114,8 +44,7 @@ public class Valadoc.ValadocOrg.Doclet : Valadoc.Html.BasicDoclet {
 	}
 
 	public override void process (Settings settings, Api.Tree tree) {
-		this.settings = settings;
-		this.tree = tree;
+		base.process (settings, tree);
 
 		DirUtils.create (this.settings.path, 0777);
 
@@ -133,8 +62,6 @@ public class Valadoc.ValadocOrg.Doclet : Valadoc.Html.BasicDoclet {
 		string path = GLib.Path.build_filename (this.settings.path, pkg_name);
 		string imgpath = GLib.Path.build_filename (path, "img");
 
-		chart_directory = Path.build_filename ("/doc/", pkg_name);
-
 		var rt = DirUtils.create (path, 0777);
 		rt = DirUtils.create (imgpath, 0777);
 
@@ -289,7 +216,6 @@ public class Valadoc.ValadocOrg.Doclet : Valadoc.Html.BasicDoclet {
 
 [ModuleInit]
 public Type register_plugin () {
-	Valadoc.Html.get_html_link_imp = Valadoc.ValadocOrg.get_html_link;
 	return typeof (Valadoc.ValadocOrg.Doclet);
 }
 
diff --git a/src/doclets/xml/doclet.vala b/src/doclets/xml/doclet.vala
index dfa63cc..731d04a 100755
--- a/src/doclets/xml/doclet.vala
+++ b/src/doclets/xml/doclet.vala
@@ -25,6 +25,7 @@ using Valadoc.Api;
 using Gee;
 
 
+
 public class Valadoc.Xml.Doclet : Api.Visitor, Valadoc.Doclet {
 	private Renderer _renderer = new Xml.Renderer ();
 	private Xml.MarkupWriter _writer;
diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am
index 4070c6e..13d387d 100644
--- a/src/libvaladoc/Makefile.am
+++ b/src/libvaladoc/Makefile.am
@@ -119,6 +119,7 @@ libvaladoc_la_VALASOURCES = \
 	taglets/tagletsince.vala \
 	taglets/tagletthrows.vala \
 	html/basicdoclet.vala \
+	html/linkhelper.vala \
 	html/globals.vala \
 	html/htmlmarkupwriter.vala \
 	html/htmlrenderer.vala \
diff --git a/src/libvaladoc/documentation/documentation.vala b/src/libvaladoc/documentation/documentation.vala
index ee4a5ca..a5e201b 100755
--- a/src/libvaladoc/documentation/documentation.vala
+++ b/src/libvaladoc/documentation/documentation.vala
@@ -23,6 +23,11 @@
 using Gee;
 
 public interface Valadoc.Documentation : Object {
+
+	public abstract Api.Package? package {
+		get;
+	}
+
 	public abstract string? get_filename ();
 }
 
diff --git a/src/libvaladoc/documentation/wiki.vala b/src/libvaladoc/documentation/wiki.vala
index d79383c..ed20fe0 100755
--- a/src/libvaladoc/documentation/wiki.vala
+++ b/src/libvaladoc/documentation/wiki.vala
@@ -43,11 +43,21 @@ public class Valadoc.WikiPage : Object, Documentation {
 		get;
 	}
 
+
+	public Api.Package? package {
+		get {
+			return _package;
+		}
+	}
+
+	private Api.Package _package;
+
 	public string? get_filename () {
 		return Path.get_basename(this.path);
 	}
 
-	public WikiPage (string name, string path) {
+	public WikiPage (string name, string path, Api.Package package) {
+		this._package = package;
 		this.name = name;
 		this.path = path;
 	}
@@ -81,7 +91,7 @@ public class Valadoc.WikiPageTree : Object {
 	}
 
 	public Collection<WikiPage> get_pages () {
-		return this.wikipages == null ? Collection.empty<WikiPage> () : this.wikipages.read_only_view;
+		return this.wikipages == null? Collection.empty<WikiPage> () : this.wikipages.read_only_view;
 	}
 
 	public WikiPage? search (string name) {
@@ -97,22 +107,22 @@ public class Valadoc.WikiPageTree : Object {
 		return null;
 	}
 
-	private void create_tree_from_path (DocumentationParser docparser, string path, string? nameoffset = null) throws GLib.FileError {
+	private void create_tree_from_path (DocumentationParser docparser, Api.Package package, string path, string? nameoffset = null) throws GLib.FileError {
 		Dir dir = Dir.open (path);
 
-		for (string? curname = dir.read_name(); curname!=null ; curname = dir.read_name()) {
+		for (string? curname = dir.read_name (); curname!=null ; curname = dir.read_name ()) {
 			string filename = Path.build_filename (path, curname);
-			if ( curname.has_suffix(".valadoc") && FileUtils.test(filename, FileTest.IS_REGULAR) ) {
-				WikiPage wikipage = new WikiPage( (nameoffset!=null)?Path.build_filename (nameoffset, curname):curname, filename );
+			if (curname.has_suffix (".valadoc") && FileUtils.test (filename, FileTest.IS_REGULAR)) {
+				WikiPage wikipage = new WikiPage ((nameoffset!=null)? Path.build_filename (nameoffset, curname) : curname, filename, package);
 				this.wikipages.add(wikipage);
 				wikipage.read ();
-			} else if (FileUtils.test(filename, FileTest.IS_DIR)) {
-				this.create_tree_from_path (docparser, filename, (nameoffset!=null)?Path.build_filename (nameoffset, curname):curname);
+			} else if (FileUtils.test (filename, FileTest.IS_DIR)) {
+				this.create_tree_from_path (docparser, package, filename, (nameoffset!=null)? Path.build_filename (nameoffset, curname) : curname);
 			}
 		}
 	}
 
-	public void create_tree (DocumentationParser docparser, Api.Package pkg) throws GLib.FileError {
+	public void create_tree (DocumentationParser docparser, Api.Package package) throws GLib.FileError {
 		try {
 			weak string path = this.settings.wiki_directory;
 			if (path == null) {
@@ -120,13 +130,12 @@ public class Valadoc.WikiPageTree : Object {
 			}
 
 			this.wikipages = new ArrayList<WikiPage> ();
-			this.create_tree_from_path (docparser, path);
+			this.create_tree_from_path (docparser, package, path);
 
 			foreach (WikiPage page in this.wikipages) {
-				page.parse (docparser, pkg);
+				page.parse (docparser, package);
 			}
-		}
-		catch (FileError err) {
+		} catch (FileError err) {
 			throw err;
 		}
 	}
diff --git a/src/libvaladoc/html/basicdoclet.vala b/src/libvaladoc/html/basicdoclet.vala
index ea400d9..636b4be 100755
--- a/src/libvaladoc/html/basicdoclet.vala
+++ b/src/libvaladoc/html/basicdoclet.vala
@@ -23,18 +23,29 @@
 using Valadoc.Content;
 using Valadoc.Api;
 
+
+
 public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 	public Settings settings { protected set; get; }
+	protected Api.Tree tree;
 	protected HtmlRenderer _renderer;
 	protected Html.MarkupWriter writer;
+	protected Html.LinkHelper linker;
 
 	protected string chart_directory = "img";
 	protected string icon_directory = "..";
 
-	public abstract void process (Settings settings, Api.Tree tree);
+	construct {
+		this.linker = LinkHelper.get_instance ();
+	}
+
+	public virtual void process (Settings settings, Api.Tree tree) {
+		this.settings = settings;
+		this.tree = tree;
+	}
 
-	protected string? get_link (Api.Node element, Api.Node? pos) {
-		return get_html_link (this.settings, element, pos);
+	protected string? get_link (Api.Node to, Api.Node from) {
+		return linker.get_relative_link (from, to, settings);
 	}
 
 	protected void write_navi_entry_html_template (string style, string content) {
@@ -318,7 +329,7 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 		foreach (Package pkg in tree.get_package_list()) {
 			if (pkg.is_visitor_accessible (settings)) {
 				writer.start_tag ("li", {"class", get_html_css_class (pkg)});
-				writer.link (get_link (pkg, null), pkg.name);
+				writer.link (linker.get_package_link (pkg, settings), pkg.name);
 				// brief description
 				writer.end_tag ("li");
 			}
@@ -344,7 +355,7 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 
 		WikiPage? wikiindex = (tree.wikitree == null)? null : tree.wikitree.search ("index.valadoc");
 		if (wikiindex != null) {
-			_renderer.set_container (null);
+			_renderer.set_container (wikiindex);
 			_renderer.render (wikiindex.documentation);
 		}
 
@@ -431,8 +442,8 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 
 		if (node.parent is Namespace) {
 			writer.simple_tag ("br");
-			this.write_namespace_note (node);
-			this.write_package_note (node);
+			write_namespace_note (node);
+			write_package_note (node);
 		}
 
 		if (node.has_children ({
diff --git a/src/libvaladoc/html/globals.vala b/src/libvaladoc/html/globals.vala
index b3df0f1..b38dd05 100755
--- a/src/libvaladoc/html/globals.vala
+++ b/src/libvaladoc/html/globals.vala
@@ -106,15 +106,6 @@ namespace Valadoc.Html {
 	public const string css_namespace_note = "namespace_note";
 	public const string css_package_note = "package_note";
 
-	public delegate string? HtmlLink (Settings settings, Documentation element, Documentation? pos);
-	public HtmlLink get_html_link_imp;
-
-	public string? get_html_link ( Settings settings, Documentation element, Documentation? pos ) {
-		if (get_html_link_imp == null) {
-			return null;
-		}
-		return get_html_link_imp(settings, element, pos);
-	}
 
 	public string get_html_type_link (Settings settings, Documentation element, Documentation? pos) {
 		string prefix = "";
@@ -133,6 +124,7 @@ namespace Valadoc.Html {
 		return prefix + "/" + ((Api.Node)element).full_name() + ".html" + tmp;
 	}
 
+
 	public string get_html_css_class (Valadoc.Api.Item element) {
 		if ( element is Api.Namespace ) {
 			return css_namespace;
diff --git a/src/libvaladoc/html/htmlrenderer.vala b/src/libvaladoc/html/htmlrenderer.vala
index 9af3413..07ae0dd 100755
--- a/src/libvaladoc/html/htmlrenderer.vala
+++ b/src/libvaladoc/html/htmlrenderer.vala
@@ -28,8 +28,10 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
 	protected BasicDoclet _doclet;
 	protected Documentation? _container;
 	protected unowned MarkupWriter writer;
+	protected LinkHelper linker;
 
 	public HtmlRenderer (BasicDoclet doclet) {
+		linker = LinkHelper.get_instance ();
 		_doclet = doclet;
 	}
 
@@ -50,7 +52,7 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
 	}
 
 	private string get_url (Api.Node symbol) {
-		return get_html_link (_doclet.settings, symbol, _container);
+		return linker.get_relative_link (_container, symbol, _doclet.settings);
 	}
 
 	private void write_symbol_link (Api.Node symbol, string? label) {
diff --git a/src/libvaladoc/html/linkhelper.vala b/src/libvaladoc/html/linkhelper.vala
new file mode 100644
index 0000000..91a03c2
--- /dev/null
+++ b/src/libvaladoc/html/linkhelper.vala
@@ -0,0 +1,205 @@
+/* linkhelper.vala
+ *
+ * Copyright (C) 2008-2009 Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	Florian Brosch <flo brosch gmail com>
+ */
+
+using Gee;
+
+
+
+public class Valadoc.Html.LinkHelper : Object {
+	private static LinkHelper _singleton;
+	private Settings _settings = null;
+
+	private LinkHelper () {
+	}
+
+	public static LinkHelper get_instance () {
+		if (_singleton == null) {
+			_singleton = new LinkHelper ();
+		}
+
+		return _singleton;
+	}
+
+	// done
+	public string? get_package_link (Api.Package package, Settings settings) {
+		if (!package.is_visitor_accessible (settings)) {
+			return null;
+		}
+
+		return Path.build_filename (package.name, "index.htm");
+	}
+
+	public string? get_relative_link (Documentation from, Documentation to, Settings settings) {
+		_settings = settings;
+
+		//TODO: find a better solution which does not require too much code ...
+		if (from is Api.Package) {
+			if (to is Api.Package) {
+				return from_package_to_package ((Api.Package) from, (Api.Package) to);
+			} else if (to is Api.Node) {
+				return from_package_to_node ((Api.Package) from, (Api.Node) to);
+			} else if (to is WikiPage) {
+				return from_package_to_wiki ((Api.Package) from, (WikiPage) to);
+			} else {
+				assert (true);
+			}
+		} else if (from is Api.Node) {
+			if (to is Api.Package) {
+				return from_node_to_package ((Api.Node) from, (Api.Package) to);
+			} else if (to is Api.Node) {
+				return from_node_to_node ((Api.Node) from, (Api.Node) to);
+			} else if (to is WikiPage) {
+				return from_node_to_wiki ((Api.Node) from, (WikiPage) to);
+			} else {
+				assert (true);
+			}
+		} else if (from is WikiPage) {
+			if (to is Api.Package) {
+				return from_wiki_to_package ((WikiPage) from, (Api.Package) to);
+			} else if (to is Api.Node) {
+				return from_wiki_to_node ((WikiPage) from, (Api.Node) to);
+			} else if (to is WikiPage) {
+				return from_wiki_to_wiki ((WikiPage) from, (WikiPage) to);
+			} else {
+				assert (true);
+			}
+		} else {
+			assert (true);
+		}
+
+		return null;
+	}
+
+	private string translate_wiki_name (WikiPage page) {
+		var name = page.name;
+
+		return name.ndup (name.pointer_to_offset (name.chr (-1, '.'))).replace ("/", ".") + ".html";
+	}
+
+
+
+
+	protected virtual string? from_package_to_package (Api.Package from, Api.Package to) {
+		if (!to.is_visitor_accessible(_settings)) {
+			return null;
+		}
+
+		if (from == to) {
+			return "#";
+		} else {
+			return Path.build_filename ("..", to.name, "index.htm");
+		}
+	}
+
+	protected virtual string? from_package_to_wiki (Api.Package from, WikiPage to) {
+		if (from.name == "index.valadoc") {
+			return Path.build_filename ("..", "index.html");
+		} else {
+			return Path.build_filename ("..", "content", translate_wiki_name (to));
+		}
+	}
+
+	protected virtual string? from_package_to_node (Api.Package from, Api.Node to) {
+		if (!to.is_visitor_accessible(_settings) || !to.package.is_visitor_accessible (_settings)) {
+			return null;
+		}
+
+		if (from == to.package) {
+			return Path.build_filename (to.full_name () + ".html");
+		} else {
+			return Path.build_filename ("..", to.package.name, to.full_name () + ".html");
+		}
+	}
+
+
+
+	protected virtual string? from_wiki_to_package (WikiPage from, Api.Package to) {
+		if (!to.is_visitor_accessible(_settings)) {
+			return null;
+		}
+
+		if (from.name == "index.valadoc") {
+			return Path.build_filename (to.name, "index.htm");
+		} else {
+			return Path.build_filename ("..", to.name, "index.htm");
+		}
+	}
+
+	protected virtual string? from_wiki_to_wiki (WikiPage from, WikiPage to) {
+		if (from == to) {
+			return "#";
+		} else if (from.name == "index.valadoc") {
+			return Path.build_filename ("content", translate_wiki_name (to));
+		} else if (to.name == "index.valadoc") {
+			return Path.build_filename ("..", "index.html");
+		} else {
+			return translate_wiki_name (to);
+		}
+	}
+
+	protected virtual string? from_wiki_to_node (WikiPage from, Api.Node to) {
+		if (!to.is_visitor_accessible(_settings) || !to.package.is_visitor_accessible (_settings)) {
+			return null;
+		}
+
+		if (from.name == "index.valadoc") {
+			return Path.build_filename (to.package.name, to.full_name() + ".html");
+		} else {
+			return Path.build_filename ("..", to.package.name, to.full_name() + ".html");
+		}
+	}
+
+
+
+	protected virtual string? from_node_to_package (Api.Node from, Api.Package to) {
+		if (!to.is_visitor_accessible (_settings)) {
+			return null;
+		}
+
+		if (from.package == to) {
+			return "index.htm";
+		} else {
+			return Path.build_filename ("..", to.name, "index.htm");
+		}
+	}
+
+	protected virtual string? from_node_to_wiki (Api.Node from, WikiPage to) {
+		if (to.name == "index.valadoc") {
+			return Path.build_filename ("..", "index.html");
+		} else {
+			return Path.build_filename ("..", "content", translate_wiki_name (to));
+		}
+	}
+
+	protected virtual string? from_node_to_node (Api.Node from, Api.Node to) {
+		if (!to.is_visitor_accessible(_settings) || !to.package.is_visitor_accessible (_settings)) {
+			return null;
+		}
+
+		if (from.package == to.package) {
+			return Path.build_filename (to.full_name() + ".html");
+		} else {
+			return Path.build_filename ("..", to.package.name, to.full_name() + ".html");
+		}
+	}
+ }
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]