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
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
{
33 public virtual string?
get_package_link (Api
.Package package
, Settings settings
) {
34 if (enable_browsable_check
&& !package
.is_browsable (settings
)) {
38 return Path
.build_filename (package
.name
, "index.htm");
41 public string?
get_relative_link (Documentation from
, Documentation to
, 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
);
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
);
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
);
82 protected string translate_wiki_name (WikiPage page
) {
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
)) {
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
));
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
))) {
115 if (from
== to
.package
) {
116 return Path
.build_filename (to
.get_full_name () + ".html");
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
)) {
130 return Path
.build_filename ("..", to
.name
, "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
))) {
145 if (to
.package
.is_package
) {
146 return Path
.build_filename ("..", to
.package
.name
, to
.get_full_name () + ".html");
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
)) {
159 if (from
.package
== to
) {
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
));
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
))) {
179 if (from
.package
== to
.package
) {
180 return Path
.build_filename (to
.get_full_name() + ".html");
182 return Path
.build_filename ("..", to
.package
.name
, to
.get_full_name() + ".html");