]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Add Content.WikiLink
authorFlorian Brosch <flo.brosch@gmail.com>
Wed, 16 Feb 2011 17:12:25 +0000 (18:12 +0100)
committerFlorian Brosch <flo.brosch@gmail.com>
Wed, 16 Feb 2011 17:12:25 +0000 (18:12 +0100)
src/doclets/gtkdoc/commentconverter.vala
src/libvaladoc/Makefile.am
src/libvaladoc/content/contentfactory.vala
src/libvaladoc/content/contentvisitor.vala
src/libvaladoc/content/wikilink.vala [new file with mode: 0755]
src/libvaladoc/documentation/documentationparser.vala
src/libvaladoc/html/htmlrenderer.vala

index 881db2c2e42d66fec733508dfa7a2974e3edeadb..5a1486411b686083d7db59df5338eddf3d71ec67 100644 (file)
@@ -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);
index e5f91024a620c269d0cc991c5179a34fabd16443..bc693748050c3da3b21b9ceca221c4100e7f55dd 100644 (file)
@@ -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 \
index 323fb4794a3b25efa3da58c1ed5718d0d6d49dd7..55c44f7ac03a9c0bc5754fcc5cb1cfa16eb4931c 100755 (executable)
@@ -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 ());
        }
index aad3eb88d9a9511cb577ccad954e43d40aa55b56..bacffc3ddf017a573f03036f09e741bef35a93b2 100755 (executable)
@@ -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 (executable)
index 0000000..3833c47
--- /dev/null
@@ -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);
+       }
+}
index c2631613f77f32ee902846b7b858e3872985e007..8f0198dfc2d730a77d1ea307dfc68976b0794dd7 100644 (file)
@@ -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); }),
index 65a9a91538ba8841f9e3a5d05d8f9bd81c3c469f..5f54fb4f5739cb3f080fdf22671451d75cdde83a 100755 (executable)
@@ -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) {