Release 0.41.92
[vala-gnome.git] / libvaladoc / html / linkhelper.vala
blob7e3c9bda40aca4e9829e975dc96ca2b4019d17a3
1 /* linkhelper.vala
3 * Copyright (C) 2008-2012 Florian Brosch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Florian Brosch <flo.brosch@gmail.com>
24 public class Valadoc.Html.LinkHelper : Object {
25 protected Settings _settings = null;
27 public bool enable_browsable_check {
28 default = true;
29 get;
30 set;
33 public virtual string? get_package_link (Api.Package package, Settings settings) {
34 if (enable_browsable_check && !package.is_browsable (settings)) {
35 return null;
38 return Path.build_filename (package.name, "index.htm");
41 public string? get_relative_link (Documentation from, Documentation to, Settings settings) {
42 _settings = settings;
44 //TODO: find a better solution which does not require too much code ...
45 if (from is Api.Package) {
46 if (to is Api.Package) {
47 return from_package_to_package ((Api.Package) from, (Api.Package) to);
48 } else if (to is Api.Node) {
49 return from_package_to_node ((Api.Package) from, (Api.Node) to);
50 } else if (to is WikiPage) {
51 return from_package_to_wiki ((Api.Package) from, (WikiPage) to);
52 } else {
53 assert (true);
55 } else if (from is Api.Node) {
56 if (to is Api.Package) {
57 return from_node_to_package ((Api.Node) from, (Api.Package) to);
58 } else if (to is Api.Node) {
59 return from_node_to_node ((Api.Node) from, (Api.Node) to);
60 } else if (to is WikiPage) {
61 return from_node_to_wiki ((Api.Node) from, (WikiPage) to);
62 } else {
63 assert (true);
65 } else if (from is WikiPage) {
66 if (to is Api.Package) {
67 return from_wiki_to_package ((WikiPage) from, (Api.Package) to);
68 } else if (to is Api.Node) {
69 return from_wiki_to_node ((WikiPage) from, (Api.Node) to);
70 } else if (to is WikiPage) {
71 return from_wiki_to_wiki ((WikiPage) from, (WikiPage) to);
72 } else {
73 assert (true);
75 } else {
76 assert (true);
79 return null;
82 protected string translate_wiki_name (WikiPage page) {
83 var name = page.name;
84 return name.substring (0, name.last_index_of_char ('.')).replace ("/", ".") + ".htm";
90 protected virtual string? from_package_to_package (Api.Package from, Api.Package to) {
91 if (enable_browsable_check && !to.is_browsable(_settings)) {
92 return null;
95 if (from == to) {
96 return "#";
97 } else {
98 return Path.build_filename ("..", to.name, "index.htm");
102 protected virtual string? from_package_to_wiki (Api.Package from, WikiPage to) {
103 if (from.is_package) {
104 return Path.build_filename ("..", _settings.pkg_name, translate_wiki_name (to));
105 } else {
106 return translate_wiki_name (to);
110 protected virtual string? from_package_to_node (Api.Package from, Api.Node to) {
111 if (enable_browsable_check && (!to.is_browsable(_settings) || !to.package.is_browsable (_settings))) {
112 return null;
115 if (from == to.package) {
116 return Path.build_filename (to.get_full_name () + ".html");
117 } else {
118 return Path.build_filename ("..", to.package.name, to.get_full_name () + ".html");
124 protected virtual string? from_wiki_to_package (WikiPage from, Api.Package to) {
125 if (enable_browsable_check && !to.is_browsable(_settings)) {
126 return null;
129 if (to.is_package) {
130 return Path.build_filename ("..", to.name, "index.htm");
131 } else {
132 return "index.htm";
136 protected virtual string? from_wiki_to_wiki (WikiPage from, WikiPage to) {
137 return translate_wiki_name (to);
140 protected virtual string? from_wiki_to_node (WikiPage from, Api.Node to) {
141 if (enable_browsable_check && (!to.is_browsable(_settings) || !to.package.is_browsable (_settings))) {
142 return null;
145 if (to.package.is_package) {
146 return Path.build_filename ("..", to.package.name, to.get_full_name () + ".html");
147 } else {
148 return to.get_full_name () + ".html";
154 protected virtual string? from_node_to_package (Api.Node from, Api.Package to) {
155 if (enable_browsable_check && !to.is_browsable (_settings)) {
156 return null;
159 if (from.package == to) {
160 return "index.htm";
161 } else {
162 return Path.build_filename ("..", to.name, "index.htm");
166 protected virtual string? from_node_to_wiki (Api.Node from, WikiPage to) {
167 if (from.package.is_package) {
168 return Path.build_filename ("..", _settings.pkg_name, translate_wiki_name (to));
169 } else {
170 return translate_wiki_name (to);
174 protected virtual string? from_node_to_node (Api.Node from, Api.Node to) {
175 if (enable_browsable_check && (!to.is_browsable(_settings) || !to.package.is_browsable (_settings))) {
176 return null;
179 if (from.package == to.package) {
180 return Path.build_filename (to.get_full_name() + ".html");
181 } else {
182 return Path.build_filename ("..", to.package.name, to.get_full_name() + ".html");