[valadoc] new xml doclet



commit aeef9deb309a88f9f332b40b1f75bb17ff0ad60c
Author: Florian Brosch <flo brosch gmail com>
Date:   Sun Feb 7 22:04:54 2010 +0100

    new xml doclet

 src/doclets/Makefile.am              |    1 +
 src/doclets/xml/Makefile.am          |   59 +++++++++
 src/doclets/xml/doclet.vala          |  141 ++++++++++++++++++++++
 src/doclets/xml/xmlmarkupwriter.vala |   63 ++++++++++
 src/doclets/xml/xmlrenderer.vala     |  217 ++++++++++++++++++++++++++++++++++
 5 files changed, 481 insertions(+), 0 deletions(-)
---
diff --git a/src/doclets/Makefile.am b/src/doclets/Makefile.am
index 758d35e..15f033b 100644
--- a/src/doclets/Makefile.am
+++ b/src/doclets/Makefile.am
@@ -4,6 +4,7 @@ NULL =
 
 
 SUBDIRS = htm \
+          xml \
           devhelp \
           valadoc.org \
           $(NULL)
diff --git a/src/doclets/xml/Makefile.am b/src/doclets/xml/Makefile.am
new file mode 100644
index 0000000..da7528d
--- /dev/null
+++ b/src/doclets/xml/Makefile.am
@@ -0,0 +1,59 @@
+#src/Makefile.am
+
+
+libdoclet_VALASOURCES = \
+	xmlmarkupwriter.vala \
+	xmlrenderer.vala \
+	doclet.vala \
+	$(NULL)
+
+
+BUILT_SOURCES = libdoclet.vala.stamp
+
+
+libdoclet.vala.stamp: $(libdoclet_VALASOURCES)
+	$(VALAC) -C --vapidir $(top_srcdir)/src/vapi/ --vapidir ../../libvaladoc --pkg valadoc-1.0 --pkg vala-1.0 --pkg gee-1.0 --basedir . --save-temps $^
+	touch $@
+
+
+docletdir = $(libdir)/valadoc/plugins/xml
+
+
+doclet_LTLIBRARIES = libdoclet.la
+
+
+libdoclet_la_SOURCES = \
+	libdoclet.vala.stamp \
+	$(libdoclet_VALASOURCES:.vala=.c) \
+	$(libdoclet_VALASOURCES:.vala=.h) \
+	$(NULL)
+
+
+
+AM_CFLAGS =  -g \
+	-DPACKAGE_ICONDIR=\"$(datadir)/valadoc/icons/\" \
+	-I ../../libvaladoc/ \
+	$(GLIB_CFLAGS) \
+	$(LIBGEE_CFLAGS) \
+	$(LIBVALA_CFLAGS) \
+	$(NULL)
+
+
+libdoclet_la_LDFLAGS = -module -avoid-version -no-undefined
+
+
+libdoclet_la_LIBADD = \
+	../../libvaladoc/libvaladoc.la \
+	$(GLIB_LIBS)  \
+	$(LIBGEE_LIBS) \
+	$(LIBVALA_LIBS) \
+	$(NULL)
+
+
+EXTRA_DIST = $(libdoclet_VALASOURCES)  libdoclet.vala.stamp 
+
+
+MAINTAINERCLEANFILES = \
+	$(libdoclet_la_SOURCES) \
+	$(NULL)
+
diff --git a/src/doclets/xml/doclet.vala b/src/doclets/xml/doclet.vala
new file mode 100755
index 0000000..e496c57
--- /dev/null
+++ b/src/doclets/xml/doclet.vala
@@ -0,0 +1,141 @@
+/* doclet.vala
+ *
+ * Copyright (C) 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 Valadoc;
+using Valadoc.Api;
+using Gee;
+
+
+public class Valadoc.Xml.Doclet : Api.Visitor, Valadoc.Doclet {
+	private Renderer _renderer = new Xml.Renderer ();
+	private Xml.MarkupWriter _writer;
+	private Settings settings;
+	private Api.Tree tree;
+
+	public void process (Settings settings, Api.Tree tree) {
+		this.settings = settings;
+		this.tree = tree;
+
+		DirUtils.create (settings.path, 0777);
+		tree.accept (this);
+	}
+
+
+	private void process_node (Api.Node node, string tagname) {
+		_writer.start_tag (tagname, {"name", node.name});
+		var doctree = node.documentation;
+
+		if (doctree != null) {
+			_writer.start_tag ("documentation");
+			_renderer.set_filestream (_writer);
+			_renderer.set_container (node);
+			_renderer.render (doctree);
+			_writer.end_tag ("documentation");
+		}
+
+		// avoid exceptions and signal childs
+		if (node is Class || node is Struct || node is Enum || node is ErrorDomain || node is Namespace) {
+			node.accept_all_children (this);
+		}
+
+		_writer.end_tag (tagname);
+	}
+
+	public override void visit_tree (Api.Tree tree) {
+		tree.accept_children (this);
+	}
+
+	public override void visit_package (Package package) {
+		string path = GLib.Path.build_filename (this.settings.path, package.name);
+		DirUtils.create (path, 0777);
+
+		GLib.FileStream file = GLib.FileStream.open (Path.build_filename (path, "documentation.xml"), "w");
+		_writer = new Xml.MarkupWriter (file);
+
+		_writer.start_tag ("package", {"name", package.name});
+		package.accept_all_children (this);
+		_writer.end_tag ("package");
+
+		file = null;
+	}
+
+	public override void visit_namespace (Namespace ns) {
+		process_node (ns, "namespace");
+	}
+
+	public override void visit_interface (Interface item) {
+		process_node (item, "interface");
+	}
+
+	public override void visit_class (Class item) {
+		process_node (item, "class");
+	}
+
+	public override void visit_struct (Struct item) {
+		process_node (item, "struct");
+	}
+
+	public override void visit_error_domain (ErrorDomain item) {
+		process_node (item, "error-domain");
+	}
+
+	public override void visit_enum (Enum item) {
+		process_node (item, "enum");
+	}
+
+	public override void visit_property (Property item) {
+		process_node (item, "property");
+	}
+
+	public override void visit_constant (Constant item) {
+		process_node (item, "constant");
+	}
+
+	public override void visit_field (Field item) {
+		process_node (item, "field");
+	}
+
+	public override void visit_error_code (ErrorCode item) {
+		process_node (item, "error-code");
+	}
+
+	public override void visit_enum_value (Api.EnumValue item) {
+		process_node (item, "enum-value");
+	}
+
+	public override void visit_delegate (Delegate item) {
+		process_node (item, "delegate");
+	}
+
+	public override void visit_signal (Api.Signal item) {
+		process_node (item, "signal");
+	}
+
+	public override void visit_method (Method item) {
+		process_node (item, "method");
+	}
+}
+
+[ModuleInit]
+public Type register_plugin () {
+	return typeof (Valadoc.Xml.Doclet);
+}
diff --git a/src/doclets/xml/xmlmarkupwriter.vala b/src/doclets/xml/xmlmarkupwriter.vala
new file mode 100644
index 0000000..9a10c7e
--- /dev/null
+++ b/src/doclets/xml/xmlmarkupwriter.vala
@@ -0,0 +1,63 @@
+/* xmlmarkupwriter.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>
+ */
+
+public class Valadoc.Xml.MarkupWriter : Valadoc.MarkupWriter {
+	public MarkupWriter (FileStream stream) {
+		base (stream);
+	}
+
+	protected override bool inline_element (string name) {
+		return name != "package"
+			&& name != "namespace"
+			&& name != "interface"
+			&& name != "class"
+			&& name != "struct"
+			&& name != "error-domain"
+			&& name != "enum"
+			&& name != "property"
+			&& name != "constant"
+			&& name != "field"
+			&& name != "error-code"
+			&& name != "enum-value"
+			&& name != "delegate"
+			&& name != "signal"
+			&& name != "method"
+			&& name != "taglets"
+			&& name != "table"
+			&& name != "table-cell"
+			&& name != "table-row"
+			&& name != "taglet"
+			&& name != "list"
+			&& name != "list-item"
+			&& name != "paragraph"
+			&& name != "headline";
+	}
+
+	protected override bool content_inline_element (string name) {
+		return name == "embedded"
+			|| name == "link"
+			|| name == "inline-taglet"
+			|| name == "run"
+			|| name == "source-code"
+			|| name == "br";
+	}
+}
diff --git a/src/doclets/xml/xmlrenderer.vala b/src/doclets/xml/xmlrenderer.vala
new file mode 100755
index 0000000..1d8d8e5
--- /dev/null
+++ b/src/doclets/xml/xmlrenderer.vala
@@ -0,0 +1,217 @@
+/* xmlrenderer.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 Valadoc.Content;
+
+public class Valadoc.Xml.Renderer : ContentRenderer {
+	private Documentation? _container;
+	private Xml.MarkupWriter _writer;
+
+	public void set_container (Documentation? container) {
+		_container = container;
+	}
+
+	public void set_filestream (Xml.MarkupWriter writer) {
+		_writer = writer;
+	}
+
+	public override void render (ContentElement element) {
+		element.accept (this);
+	}
+
+	public override void render_children (ContentElement element) {
+		element.accept_children (this);
+	}
+
+	private delegate void TagletWrite (Taglet taglet);
+
+	private void write_taglets (Gee.List<Taglet> taglets, TagletWrite write) {
+		foreach (var taglet in taglets) {
+			write (taglet);
+		}
+	}
+
+	public override void visit_comment (Comment element) {
+		Gee.List<Taglet> taglets;
+
+		element.accept_children (this);
+		_writer.start_tag ("taglets");
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.Since));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				var since = taglet as Taglets.Since;
+				_writer.simple_tag ("taglet", {"name", "since", "version", since.version});
+			});
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.Deprecated));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				_writer.simple_tag ("taglet", {"name", "deprecated"});
+			});
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.Param));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				var param = taglet as Taglets.Param;
+				_writer.start_tag ("taglet", {"name", "param", "parameter", param.parameter_name});
+				param.accept_children (this);
+				_writer.end_tag ("taglet");
+			});
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.Return));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				var param = taglet as Taglets.Return;
+				_writer.start_tag ("taglet", {"name", "return"});
+				param.accept_children (this);
+				_writer.end_tag ("taglet");
+			});
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.Throws));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				var exception = taglet as Taglets.Throws;
+				_writer.start_tag ("taglet", {"name", "throw", "type", exception.error_domain_name});
+				exception.accept_children (this);
+				_writer.end_tag ("taglet");
+			});
+
+		taglets = element.find_taglets ((Api.Node) _container, typeof (Taglets.See));
+		write_taglets (
+			taglets,
+			(taglet) => {
+				var see = taglet as Taglets.See;
+				_writer.simple_tag ("taglet", {"name", "see", "type", see.symbol.full_name ()});
+			});
+
+		_writer.end_tag ("taglets");
+	}
+
+	public override void visit_embedded (Embedded element) {
+		var caption = element.caption;
+		_writer.simple_tag ("embedded", {"url", element.url, "caption", (caption == null)? "" : caption});
+	}
+
+	public override void visit_headline (Headline element) {
+		_writer.start_tag ("headline", {"level", element.level.to_string ()});
+		element.accept_children (this);
+		_writer.end_tag ("headline");
+	}
+
+	public override void visit_link (Link element) {
+		_writer.start_tag ("link", {"url", element.url});
+		if (element.content.size > 0) {
+			element.accept_children (this);
+		} else {
+			_writer.text (element.url);
+		}
+		_writer.end_tag ("link");
+	}
+
+	public override void visit_symbol_link (SymbolLink element) {
+		_writer.simple_tag ("inline-taglet", {"name", "symbol-link", "type", element.symbol.full_name ()});
+	}
+
+	public override void visit_list (Content.List element) {
+		_writer.start_tag ("list", {"bullet-type", element.bullet.to_string ()});
+		element.accept_children (this);
+		_writer.end_tag ("list");
+	}
+
+	public override void visit_list_item (ListItem element) {
+		_writer.start_tag ("list-item");
+		element.accept_children (this);
+		_writer.end_tag ("list-item");
+	}
+
+	public override void visit_page (Page element) {
+		element.accept_children (this);
+	}
+
+	public override void visit_paragraph (Paragraph element) {
+		_writer.start_tag ("paragraph");
+		element.accept_children (this);
+		_writer.end_tag ("paragraph");
+	}
+
+	public override void visit_run (Run element) {
+		if(element.style == Run.Style.BOLD || element.style == Run.Style.ITALIC ||
+		   element.style == Run.Style.UNDERLINED || element.style == Run.Style.MONOSPACED ||
+		   element.style == Run.Style.STROKE) {
+
+			_writer.start_tag ("run", {"style", element.style.to_string ()});
+			element.accept_children (this);
+			_writer.end_tag ("run");
+		} else {
+			element.accept_children (this);
+		}
+	}
+
+	public override void visit_source_code (SourceCode element) {
+		_writer.start_tag ("source-code", {"language", element.language.to_string ()});
+		_writer.text (element.code);
+		_writer.end_tag ("source-code");
+	}
+
+	public override void visit_table (Table element) {
+		_writer.start_tag ("table");
+		element.accept_children (this);
+		_writer.end_tag ("table");
+	}
+
+	public override void visit_table_cell (TableCell element) {
+		_writer.start_tag ("table-cell", {"colspan", element.colspan.to_string (),
+										  "rowspan", element.rowspan.to_string (),
+										  "horizontal-align", (element.horizontal_align == null)? null : element.horizontal_align.to_string (),
+										  "vertical-align", (element.vertical_align == null)? null : element.vertical_align.to_string ()});
+		element.accept_children (this);
+		_writer.end_tag ("table-cell");
+	}
+
+	public override void visit_table_row (TableRow element) {
+		_writer.start_tag ("table-row");
+		element.accept_children (this);
+		_writer.end_tag ("table-row");
+	}
+
+	public override void visit_taglet (Taglet element) {
+	}
+
+	public override void visit_text (Text element) {
+		unowned string from = element.content;
+		unowned string to;
+
+		while ((to = from.chr (-1, '\n')) != null) {
+			_writer.text (from.substring (0, from.pointer_to_offset(to)));
+			_writer.simple_tag ("br");
+			from = to.offset(1);
+		}
+		_writer.text (from);
+	}
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]