Commits

Doug Hellmann committed 85e6305

update announcement; add more exampels to docs; tweak code to make it easier to read

Comments (0)

Files changed (3)

sqltable/announce.rst

 ============================
- sphinxcontrib.sqltable 1.0
+ sphinxcontrib-sqltable 1.0
 ============================
 
-What is sphinxcontrib.sqltable?
+What is sphinxcontrib-sqltable?
 ===============================
 
-`sphinxcontrib.sqltable`_ is a Sphinx_ extension that allows authors
+`sphinxcontrib-sqltable`_ is a Sphinx_ extension that allows authors
 to embed SQL statements in source documents and produce tabular output
 in rendered documents.
 
 What's New in 1.0
 ==================
 
-This is the first public release of sphinxcontrib.sqltable.
+This is the first public release of sphinxcontrib-sqltable.
 
 Installing
 ==========
 
 .. _Sphinx: http://sphinx.pocoo.org/
 
-.. _main documentation page: http://www.doughellmann.com/docs/sphinxcontrib.sqltable/
+.. _main documentation page: http://www.doughellmann.com/docs/sphinxcontrib-sqltable/
+
+.. _sphinxcontrib-sqltable: http://www.doughellmann.com/projects/sphinxcontrib-sqltable/

sqltable/docs/example.rst

  Examples
 ==========
 
-Given a SQLite database containing:
+The following examples use a SQLite database containing:
 
 .. literalinclude:: sampledata.sql
 
-this reStructuredText input:
+Local Connection String
+=======================
+
+Use the ``connection_string`` option to specify the database to be
+used for a single query.
 
 ::
 
 
    select name as 'Name', email as 'E-mail' from users
    order by Name asc
+
+Missing Connection String
+=========================
+
+Leaving out the ``connection_string`` option produces an error:
+
+::
+
+  .. sqltable:: List of Users
+
+     select name as 'Name', email as 'E-mail' from users
+     order by Name asc
+
+results in
+
+::
+
+  $ sphinx-build -b html -d _build/doctrees   . _build/html
+  Running Sphinx v1.1.2
+  Initializing SQLTable
+  loading pickled environment... done
+  building [html]: targets for 1 source files that are out of date
+  updating environment: 0 added, 1 changed, 0 removed
+  Connecting to sqlite:///sampledata.db                                           
+  Running query u"select name as 'Name', email as 'E-mail' from users\norder by Name asc"
+
+  .../docs/example.rst:45: ERROR: No connection_string or sqltable_connection_string was specified for sqltable

sqltable/sphinxcontrib/sqltable.py

         tgroup.extend(nodes.colspec(colwidth=col_width)
                       for col_width in col_widths)
 
-        # Add headers, if given.
-        if headers:
-            thead = nodes.thead()
-            tgroup += thead
-            row_node = nodes.row()
-            thead += row_node
-            row_node.extend(
-                nodes.entry(h, nodes.paragraph(text=h))
-                for h in headers
-                )
+        # Set the headers
+        thead = nodes.thead()
+        tgroup += thead
+        row_node = nodes.row()
+        thead += row_node
+        row_node.extend(
+            nodes.entry(h, nodes.paragraph(text=h))
+            for h in headers
+            )
 
         # The body of the table is made up of rows.
         # Each row contains a series of entries,
         # and each entry contains a paragraph of text.
-        tgroup += nodes.tbody(
-            '',
-            *[ nodes.row(
-                    '',
-                    *[nodes.entry(
-                            cell,
-                            nodes.paragraph(text=cell)
-                            )
-                      for cell in row]
-                    )
-               for row in table_data
-               ]
-            )
+        tbody = nodes.tbody()
+        tgroup += tbody
+        rows = []
+        for row in table_data:
+            trow = nodes.row()
+            for cell in row:
+                entry = nodes.entry()
+                para = nodes.paragraph(text=unicode(cell))
+                entry += para
+                trow += entry
+            rows.append(trow)
+        tbody.extend(rows)
 
         #print table
         return table