[valadoc] libvaladoc: Add Content.WikiLink
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] libvaladoc: Add Content.WikiLink
- Date: Thu, 24 Feb 2011 01:32:37 +0000 (UTC)
commit 04f58c9f9cc5257a26ce272c8e730d7730a24da7
Author: Florian Brosch <flo brosch gmail com>
Date: Wed Feb 16 18:12:25 2011 +0100
libvaladoc: Add Content.WikiLink
src/doclets/gtkdoc/commentconverter.vala | 9 ++++
src/libvaladoc/Makefile.am | 1 +
src/libvaladoc/content/contentfactory.vala | 4 ++
src/libvaladoc/content/contentvisitor.vala | 3 +
src/libvaladoc/content/wikilink.vala | 48 ++++++++++++++++++++
.../documentation/documentationparser.vala | 17 +++++--
src/libvaladoc/html/htmlrenderer.vala | 18 +++++++-
7 files changed, 95 insertions(+), 5 deletions(-)
---
diff --git a/src/doclets/gtkdoc/commentconverter.vala b/src/doclets/gtkdoc/commentconverter.vala
index 881db2c..5a14864 100644
--- a/src/doclets/gtkdoc/commentconverter.vala
+++ b/src/doclets/gtkdoc/commentconverter.vala
@@ -83,6 +83,15 @@ public class Gtkdoc.CommentConverter : ContentVisitor {
current_builder.append ("\n");
}
+ public override void visit_wiki_link (WikiLink link) {
+ // wiki pages are not supported right now
+ if (link.content.size > 0) {
+ link.accept_children (this);
+ } else {
+ current_builder.append (link.name);
+ }
+ }
+
public override void visit_link (Link link) {
current_builder.append_printf ("<ulink url=\"%s\">", link.url);
link.accept_children (this);
diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am
index e5f9102..bc69374 100644
--- a/src/libvaladoc/Makefile.am
+++ b/src/libvaladoc/Makefile.am
@@ -85,6 +85,7 @@ libvaladoc_la_VALASOURCES = \
content/inline.vala \
content/inlinetaglet.vala \
content/inlinecontent.vala \
+ content/wikilink.vala \
content/link.vala \
content/list.vala \
content/listitem.vala \
diff --git a/src/libvaladoc/content/contentfactory.vala b/src/libvaladoc/content/contentfactory.vala
index 323fb47..55c44f7 100755
--- a/src/libvaladoc/content/contentfactory.vala
+++ b/src/libvaladoc/content/contentfactory.vala
@@ -56,6 +56,10 @@ public class Valadoc.Content.ContentFactory : Object {
return (Link) configure (new Link ());
}
+ public WikiLink create_wiki_link () {
+ return (WikiLink) configure (new WikiLink ());
+ }
+
public List create_list () {
return (List) configure (new List ());
}
diff --git a/src/libvaladoc/content/contentvisitor.vala b/src/libvaladoc/content/contentvisitor.vala
index aad3eb8..bacffc3 100755
--- a/src/libvaladoc/content/contentvisitor.vala
+++ b/src/libvaladoc/content/contentvisitor.vala
@@ -37,6 +37,9 @@ public abstract class Valadoc.Content.ContentVisitor : Object {
public virtual void visit_link (Link element) {
}
+ public virtual void visit_wiki_link (WikiLink element) {
+ }
+
public virtual void visit_symbol_link (SymbolLink element) {
}
diff --git a/src/libvaladoc/content/wikilink.vala b/src/libvaladoc/content/wikilink.vala
new file mode 100755
index 0000000..3833c47
--- /dev/null
+++ b/src/libvaladoc/content/wikilink.vala
@@ -0,0 +1,48 @@
+/* link.vala
+ *
+ * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
+ *
+ * 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:
+ * Didier 'Ptitjes Villevalois <ptitjes free fr>
+ */
+
+using Gee;
+
+
+public class Valadoc.Content.WikiLink : InlineContent, Inline {
+ public WikiPage page { get; private set; }
+ public string name { get; set; }
+
+ internal WikiLink () {
+ base ();
+ }
+
+ public override void configure (Settings settings, ResourceLocator locator) {
+ }
+
+ public override void check (Api.Tree api_root, Api.Node container, ErrorReporter reporter, Settings settings) {
+ page = api_root.wikitree.search (name);
+ if (page == null) {
+ reporter.simple_warning ("%s does not exist".printf (name));
+ return ;
+ }
+ }
+
+ public override void accept (ContentVisitor visitor) {
+ visitor.visit_wiki_link (this);
+ }
+}
diff --git a/src/libvaladoc/documentation/documentationparser.vala b/src/libvaladoc/documentation/documentationparser.vala
index c263161..8f0198d 100644
--- a/src/libvaladoc/documentation/documentationparser.vala
+++ b/src/libvaladoc/documentation/documentationparser.vala
@@ -938,16 +938,25 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
Rule link =
Rule.seq ({
TokenType.DOUBLE_OPEN_BRACKET.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (true); }),
- TokenType.any_word ().action ((token) => { ((Link) peek ()).url = token.to_string (); }),
+ TokenType.any_word ().action ((token) => {
+ var url = token.to_string ();
+ if (url.has_suffix (".valadoc")) {
+ var link = _factory.create_wiki_link ();
+ link.name = url;
+ push (link);
+ } else {
+ var link = _factory.create_link ();
+ link.url = url;
+ push (link);
+ }
+ }),
Rule.option ({
TokenType.PIPE.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); }),
run
}),
TokenType.DOUBLE_CLOSED_BRACKET.action (() => { ((WikiScanner) _scanner).set_url_escape_mode (false); })
})
- .set_name ("Link")
- .set_start (() => { push (_factory.create_link ()); });
-
+ .set_name ("Link");
Rule source_code =
Rule.seq ({
TokenType.TRIPLE_OPEN_BRACE.action ((token) => { ((WikiScanner) _scanner).set_code_escape_mode (true); }),
diff --git a/src/libvaladoc/html/htmlrenderer.vala b/src/libvaladoc/html/htmlrenderer.vala
index 65a9a91..5f54fb4 100755
--- a/src/libvaladoc/html/htmlrenderer.vala
+++ b/src/libvaladoc/html/htmlrenderer.vala
@@ -53,7 +53,7 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
element.accept_children (this);
}
- private string get_url (Api.Node symbol) {
+ private string get_url (Documentation symbol) {
return linker.get_relative_link (_container, symbol, settings);
}
@@ -232,6 +232,22 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
writer.end_tag ("h%d".printf (element.level));
}
+ public override void visit_wiki_link (WikiLink element) {
+ if (element.page != null) {
+ writer.start_tag ("a", {"href", get_url (element.page)});
+ }
+
+ if (element.content.size > 0) {
+ element.accept_children (this);
+ } else {
+ writer.text (element.name.substring (0, element.name.last_index_of_char ('.')));
+ }
+
+ if (element.page != null) {
+ writer.end_tag ("a");
+ }
+ }
+
public override void visit_link (Link element) {
writer.start_tag ("a", {"href", element.url});
if (element.content.size > 0) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]