]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvala/html: introduce new link helper
authorFlorian Brosch <flo.brosch@gmail.com>
Tue, 23 Feb 2010 12:39:36 +0000 (13:39 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Tue, 23 Feb 2010 12:39:36 +0000 (13:39 +0100)
12 files changed:
icons/devhelpstyle.css
src/doclets/devhelp/doclet.vala
src/doclets/htm/doclet.vala
src/doclets/valadoc.org/doclet.vala
src/doclets/xml/doclet.vala
src/libvaladoc/Makefile.am
src/libvaladoc/documentation/documentation.vala
src/libvaladoc/documentation/wiki.vala
src/libvaladoc/html/basicdoclet.vala
src/libvaladoc/html/globals.vala
src/libvaladoc/html/htmlrenderer.vala
src/libvaladoc/html/linkhelper.vala [new file with mode: 0644]

index 9e40478d7374d93a24c0bfc79df9873e1ab67d77..fe69453c25e2d8f56806e7404aafa3e7a1b7c50b 100644 (file)
@@ -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 {
+}
+
index 6dfef1552a7a918954e963f7bbc3113830127278..da38805b50915eb7a51b020560fcb06b0851fa76 100755 (executable)
@@ -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);
 }
 
index aaf2ccb97170f6709ba641eec1cace760bd6e7c3..a9e5176477755c232ac1478d7dcf48a21648daf4 100755 (executable)
@@ -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 );
 }
 
index fb48291e7a04927dacab34063a9b8e52e6026c72..0e184db8518b592f94bc525e4935870eb8d1ec08 100755 (executable)
@@ -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);
 }
 
index dfa63ccfd7398e0af34ca6a05c2e2c4a3030599c..731d04a89f784693ccfe8be27d67d90adc0e0b0e 100755 (executable)
@@ -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;
index 4070c6e7731e9900efc2aa3a52941f55d254cf42..13d387ded16b6035c1f30dd6ffe2fc9ae5f552ca 100644 (file)
@@ -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 \
index ee4a5ca073eb0f7c739bf43f30f5466262d7548f..a5e201b3172fb305d3af1005824672cf1ede89d8 100755 (executable)
 using Gee;
 
 public interface Valadoc.Documentation : Object {
+
+       public abstract Api.Package? package {
+               get;
+       }
+
        public abstract string? get_filename ();
 }
 
index d79383cfb19247ba121972e2ff87cb7c3ffb42ee..ed20fe04c1b368ca329616fa55365b223ff2e7fb 100755 (executable)
@@ -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;
                }
        }
index ea400d9ca047d8d91643e1ff0bd85fd9b2b9a2bc..636b4be29a2d0921da78d2433d8899992b30f67d 100755 (executable)
 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 ({
index b3df0f19d67710c07dc9a70486888e25d15fff4d..b38dd059e7ce8e5fa6a6a207220c7ae9ffb519a0 100755 (executable)
@@ -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;
index 9af34132f07f6c30d13556feff9bb258a5c623c3..07ae0dd0aa0d11548358a7fdc315095bf5766e1f 100755 (executable)
@@ -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 (file)
index 0000000..91a03c2
--- /dev/null
@@ -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");
+               }
+       }
+ }
+