[valadoc] Fix support for tables



commit 9aa8652bb905724363028641c78be9f935543b18
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Mon Oct 12 12:33:20 2009 +0200

    Fix support for tables

 src/doclets/htmlhelpers/doclet/htmlrenderer.vala |   15 ++++++
 src/libvaladoc/Makefile.am                       |    1 +
 src/libvaladoc/content/contentfactory.vala       |    4 ++
 src/libvaladoc/content/contentvisitor.vala       |    3 +
 src/libvaladoc/content/table.vala                |   20 +++++---
 src/libvaladoc/content/tablerow.vala             |   53 ++++++++++++++++++++++
 src/libvaladoc/parser/documentationparser.vala   |    6 +-
 7 files changed, 91 insertions(+), 11 deletions(-)
---
diff --git a/src/doclets/htmlhelpers/doclet/htmlrenderer.vala b/src/doclets/htmlhelpers/doclet/htmlrenderer.vala
index 344b57c..f0df61e 100755
--- a/src/doclets/htmlhelpers/doclet/htmlrenderer.vala
+++ b/src/doclets/htmlhelpers/doclet/htmlrenderer.vala
@@ -233,9 +233,24 @@ public class Valadoc.Html.HtmlRenderer : ContentRenderer {
 	}
 
 	public override void visit_table (Table element) {
+		_stream.printf ("<table class=\"main_table\">");
+		element.accept_children (this);
+		_stream.printf ("</table>");
 	}
 
 	public override void visit_table_cell (TableCell element) {
+		_stream.printf ("<td class=\"main_table\"%s%s>",
+			element.colspan != 1 ? " colspan=\"%d\"".printf (element.colspan) : "",
+			element.rowspan != 1 ? " rowspan=\"%d\"".printf (element.rowspan) : ""
+		);
+		element.accept_children (this);
+		_stream.printf ("</td>");
+	}
+
+	public override void visit_table_row (TableRow element) {
+		_stream.printf ("<tr>");
+		element.accept_children (this);
+		_stream.printf ("</tr>");
 	}
 
 	public override void visit_taglet (Taglet element) {
diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am
index 9ebad31..7b4a1f3 100644
--- a/src/libvaladoc/Makefile.am
+++ b/src/libvaladoc/Makefile.am
@@ -97,6 +97,7 @@ libvaladoc_la_VALASOURCES = \
 	content/symbollink.vala \
 	content/table.vala \
 	content/tablecell.vala \
+	content/tablerow.vala \
 	content/taglet.vala \
 	content/text.vala \
 	parser/commentscanner.vala \
diff --git a/src/libvaladoc/content/contentfactory.vala b/src/libvaladoc/content/contentfactory.vala
index 5ce505c..2d83333 100755
--- a/src/libvaladoc/content/contentfactory.vala
+++ b/src/libvaladoc/content/contentfactory.vala
@@ -89,6 +89,10 @@ public class Valadoc.Content.ContentFactory : Object {
 		return (TableCell) configure (new TableCell ());
 	}
 
+	public TableRow create_table_row () {
+		return (TableRow) configure (new TableRow ());
+	}
+
 	public Taglet create_taglet (string name) {
 		return _modules.create_taglet (name);
 	}
diff --git a/src/libvaladoc/content/contentvisitor.vala b/src/libvaladoc/content/contentvisitor.vala
index 2a47608..2fb2fcc 100755
--- a/src/libvaladoc/content/contentvisitor.vala
+++ b/src/libvaladoc/content/contentvisitor.vala
@@ -65,6 +65,9 @@ public abstract class Valadoc.Content.ContentVisitor : Object {
 	public virtual void visit_table_cell (TableCell element) {
 	}
 
+	public virtual void visit_table_row (TableRow element) {
+	}
+
 	public virtual void visit_taglet (Taglet element) {
 	}
 
diff --git a/src/libvaladoc/content/table.vala b/src/libvaladoc/content/table.vala
index a5187d2..acb6754 100755
--- a/src/libvaladoc/content/table.vala
+++ b/src/libvaladoc/content/table.vala
@@ -25,27 +25,31 @@ using GLib;
 using Gee;
 
 public class Valadoc.Content.Table : ContentElement, Block {
-	public Gee.List<Gee.List<TableCell>> cells { get { return _cells; } }
+	public Gee.List<TableRow> rows { get { return _rows; } }
 
-	private Gee.List<Gee.List<TableCell>> _cells;
+	private Gee.List<TableRow> _rows;
 
 	internal Table () {
 		base ();
-		_cells = new ArrayList<Gee.List<TableCell>> ();
+		_rows = new ArrayList<TableRow> ();
 	}
 
 	public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) {
 		// Check the table consistency in term of row/column number
 
-		// Check individual cells
-		foreach (var row in _cells) {
-			foreach (var cell in row) {
-				cell.check (api_root, container, reporter);
-			}
+		// Check individual rows
+		foreach (var row in _rows) {
+			row.check (api_root, container, reporter);
 		}
 	}
 
 	public override void accept (ContentVisitor visitor) {
 		visitor.visit_table (this);
 	}
+
+	public override void accept_children (ContentVisitor visitor) {
+		foreach (TableRow element in _rows) {
+			element.accept (visitor);
+		}
+	}
 }
diff --git a/src/libvaladoc/content/tablerow.vala b/src/libvaladoc/content/tablerow.vala
new file mode 100755
index 0000000..e60cd46
--- /dev/null
+++ b/src/libvaladoc/content/tablerow.vala
@@ -0,0 +1,53 @@
+/* tablerow.vala
+ *
+ * Valadoc - a documentation tool for vala.
+ * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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 GLib;
+using Gee;
+
+public class Valadoc.Content.TableRow : ContentElement {
+	public Gee.List<TableCell> cells { get { return _cells; } }
+
+	private Gee.List<TableCell> _cells;
+
+	internal TableRow () {
+		base ();
+		_cells = new ArrayList<TableCell> ();
+	}
+
+	public override void check (Tree api_root, DocumentedElement? container, ErrorReporter reporter) {
+		// Check individual cells
+		foreach (var cell in _cells) {
+			cell.check (api_root, container, reporter);
+		}
+	}
+
+	public override void accept (ContentVisitor visitor) {
+		visitor.visit_table_row (this);
+	}
+
+	public override void accept_children (ContentVisitor visitor) {
+		foreach (TableCell element in _cells) {
+			element.accept (visitor);
+		}
+	}
+}
diff --git a/src/libvaladoc/parser/documentationparser.vala b/src/libvaladoc/parser/documentationparser.vala
index f0b70f3..91b25fb 100644
--- a/src/libvaladoc/parser/documentationparser.vala
+++ b/src/libvaladoc/parser/documentationparser.vala
@@ -379,7 +379,7 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 			})
 			.set_name ("Cell")
 			.set_start (() => { push (_factory.create_table_cell ()); })
-			.set_reduce (() => { ((ArrayList<TableCell>) peek ()).add ((TableCell) pop ()); });
+			.set_reduce (() => { ((TableRow) peek ()).cells.add ((TableCell) pop ()); });
 		Rule table_row =
 			Rule.seq ({
 				TokenType.DOUBLE_PIPE,
@@ -389,8 +389,8 @@ public class Valadoc.DocumentationParser : Object, ResourceLocator {
 				TokenType.EOL
 			})
 			.set_name ("Row")
-			.set_start (() => { push (new ArrayList<TableCell> ()); })
-			.set_reduce (() => { ((Table) peek ()).cells.add ((ArrayList<TableCell>) pop ()); });
+			.set_start (() => { push (_factory.create_table_row ()); })
+			.set_reduce (() => { ((Table) peek ()).rows.add ((TableRow) pop ()); });
 		Rule table =
 			Rule.seq ({
 				Rule.many ({



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