Commits

Kirill Simonov committed 6f2bdf9

Cut output in tutorial examples; visible by default.

Comments (0)

Files changed (4)

doc/extensions/htsqldoc.py

             'plain': directives.flag,
             'error': directives.flag,
             'query': directives.path,
+            'hide': directives.flag,
+            'cut': directives.positive_int,
     }
 
     def run(self):
         env = self.state.document.settings.env
-        query = self.arguments[0].replace("\n", " ")
+        query = " ".join(line.strip()
+                         for line in self.arguments[0].split("\n"))
         query_node = nodes.literal_block(query, query)
         query_node['language'] = 'htsql'
         if not env.config.htsql_server:
         content_type, content = env.htsql_uris[uri]
         if 'plain' in self.options:
             content_type = 'text/plain'
-        result_node = build_result(self.content_offset, content_type, content)
+        result_node = build_result(self.content_offset, content_type, content,
+                                   self.options.get('cut'))
         query_container = nodes.container('', query_node,
                                           classes=['htsql-input'])
         result_container = nodes.container('', result_node,
                                            classes=['htsql-output'])
+        if 'hide' in self.options:
+            result_container['classes'].append('htsql-hide')
         return [query_container, result_container]
 
 
     return (content_type, content)
 
 
-def build_result(line, content_type, content):
+def build_result(line, content_type, content, cut=None):
     if content_type == 'application/json':
         data = loads(content)
+        if isinstance(data, dict):
+            data = [meta['title'] for meta in data['meta']] + data['data']
+        is_cut = False
+        if cut and len(data) > cut+1:
+            data = data[:cut+1]
+            is_cut = True
         size = len(data[0])
         widths = [1]*size
         for row in data:
                 else:
                     text_node = nodes.Text(unicode(value))
                 para_node += text_node
+        if is_cut:
+            row_node = nodes.row(classes=['htsql-cut'])
+            body_node += row_node
+            for idx in range(size):
+                entry_node = nodes.entry()
+                row_node += entry_node
+                para_node = nodes.paragraph()
+                entry_node += para_node
+                text_node = nodes.Text(u"\u2026")
+                para_node += text_node
         result_node = table_node
     else:
         result_node = nodes.literal_block(content, content)

doc/static/htsqldoc.css

 div.htsql-output {
   max-height: 10em;
   overflow: auto;
+}
+
+div.htsql-output table.docutils tr.htsql-cut td {
+  border-bottom: 0;
+}
+
+div.htsql-hide {
   display: none;
 }
 

doc/static/htsqldoc.js

 
 
 $(function () {
-    $('.htsql-input pre').prepend("<div class=\"htsql-toggle\">[+]</div>");
+    $('.htsql-input pre').each(function () {
+        $(this).prepend("<div class=\"htsql-toggle\">" +
+                        ($(this).parents('.htsql-input')
+                                .next('.htsql-output')
+                                .hasClass('htsql-hide') ? "[+]" : "[-]") +
+                        "</div>");
+    });
     $('.htsql-toggle').click(function () {
         var output = this;
         if ($(this).text() == '[+]') {
 choose columns for display (A2_):
 
 .. htsql:: /program{school, code, title}
+   :cut: 4
 
 .. _A2: http://demo.htsql.org/program{school,code,title}
 
 example, this request (A3_) returns departments in descending order:
 
 .. htsql:: /department{name-, school}
+   :cut: 4
 
 .. _A3:
     http://demo.htsql.org/department{name-,school}
 order on ``department`` and then descending on ``credits`` (A4_):
 
 .. htsql:: /course{department+, number, credits-, title}
+   :cut: 3
 
 .. _A4:
     http://demo.htsql.org
 
 .. htsql:: /course{department+ :as 'Dept Code', number :as 'No.',
                    credits-, title}
+   :cut: 3
 
 .. _A5:
     http://demo.htsql.org
 to link data accordingly (B1_):
 
 .. htsql:: /program{school.name, title}
+   :cut: 4
 
 .. _B1:
     http://demo.htsql.org
 list courses including school and department name (B2_):
 
 .. htsql:: /course{department.school.name, department.name, title}
+   :cut: 4
 
 .. _B2:
     http://demo.htsql.org
 of ``department``; the resulting request is equivalent (B3_):
 
 .. htsql:: /course{department{school.name, name}, title}
+   :cut: 4
+   :hide:
 
 .. _B3:
     http://demo.htsql.org
 ``department`` and all columns from its correlated ``school`` (B4_):
 
 .. htsql:: /department{*,school.*}
+   :cut: 4
 
 .. _B4:
     http://demo.htsql.org
 we write (C1_):
 
 .. htsql:: /department?school='eng'
+   :cut: 4
 
 .. _C1:
     http://demo.htsql.org
 of Arts" (``'ba'``) or "Bachelors of Science" (``'bs'``) degrees (C2_):
 
 .. htsql:: /program?degree={'ba','bs'}
+   :cut: 3
 
 .. _C2:
     http://demo.htsql.org
 grant a "Bachelor of Science" degree (C3_):
 
 .. htsql:: /program?school='bus'&degree!='bs'
+   :cut: 3
 
 .. _C3:
     http://demo.htsql.org
 
 .. htsql:: /course{department, number, title}
             ?credits<3&department.school='ns'
+   :cut: 4
 
 .. _C4:
     http://demo.htsql.org
 
 .. htsql:: /(course?credits<3&department.school='ns')
             {department, number, title}
+   :cut: 4
+   :hide:
 
 .. _C5:
     http://demo.htsql.org
 
 .. htsql:: /course{department{code,name},number,title+}?
             department.school='bus'/:csv
+   :hide:
 
 .. _E1:
     http://demo.htsql.org
 get correlated information for each course's department (RA1_):
 
 .. htsql:: /course{department.name, title}
+   :cut: 3
 
 .. _RA1:
     http://demo.htsql.org
 example shows the maximum course credits by department (RA3_):
 
 .. htsql:: /department{name, max(course.credits)}
+   :cut: 3
 
 .. _RA3:
     http://demo.htsql.org
 with ``program`` and ``department``, we can count them (RB1_):
 
 .. htsql:: /school{name, count(program), count(department)}
+   :cut: 4
 
 .. _RB1:
     http://demo.htsql.org
 the 400 level or above (RB2_):
 
 .. htsql:: /department{name, count(course?number>=400)}
+   :cut: 4
 
 .. _RB2:
     http://demo.htsql.org
 average number of courses each department offers (RB3_):
 
 .. htsql:: /school{name, avg(department.count(course))}
+   :cut: 4
 
 .. _RB3:
     http://demo.htsql.org
 school, departments offering 4 or more credits (RB4_):
 
 .. htsql:: /school{name, count(department?exists(course?credits>3))}
+   :cut: 4
 
 .. _RB4:
     http://demo.htsql.org
 example shows average credits from only high-level courses (RB5_):
 
 .. htsql:: /department{name, avg((course?number>400).credits)}
+   :cut: 4
 
 .. _RB5:
     http://demo.htsql.org
 ``course.credit`` statistics (RB6_, RB7_):
 
 .. htsql:: /department{code, min(course.credits), max(course.credits)}
+   :cut: 4
 
 .. htsql:: /department{code, sum(course.credits), avg(course.credits)}
+   :cut: 4
 
 .. _RB6:
     http://demo.htsql.org
 
 .. htsql:: /department{name, avg(course.credits)}
             ?every(course.credits=3)
+   :cut: 4
+   :hide:
 
 .. _RB8:
     http://demo.htsql.org
 records that contain the substring ``'lab'`` (PC2_):
 
 .. htsql:: /course?title~'lab'
+   :cut: 4
 
 .. _PC2:
     http://demo.htsql.org
 physics in the title (PC3_):
 
 .. htsql:: /course?title!~'lab'
+   :cut: 4
+   :hide:
 
 .. _PC3:
     http://demo.htsql.org
 
 
 .. htsql:: /course?title!='Organic Chemistry Laboratory I'
+   :cut: 4
+   :hide:
 
 .. _PC4:
     http://demo.htsql.org
 straightforward when used with numbers (PC5_):
 
 .. htsql:: /course{department,number,title}?number=101
+   :cut: 2
 
 .. _PC5:
     http://demo.htsql.org
 nor the "Studio Art" department (PC6_):
 
 .. htsql:: /course?department!={'arthis','stdart'}
+   :cut: 4
+   :hide:
 
 .. _PC6:
     http://demo.htsql.org
 than 3 credits (PC7_):
 
 .. htsql:: /course?credits>3
+   :cut: 2
 
 .. _PC7:
     http://demo.htsql.org
 that have three credits or more (PC8_):
 
 .. htsql:: /course?credits>=3
+   :cut: 4
+   :hide:
 
 .. _PC8:
     http://demo.htsql.org
 departments whose ``code`` follows ``'me'`` in the alphabet (PC9_):
 
 .. htsql:: /department?code>'me'
+   :cut: 4
 
 .. _PC9:
     http://demo.htsql.org
 ``false()``.   To skip non-academic ``department`` records (PA3_):
 
 .. htsql:: /department{code, name}?!is_null(school)
+   :cut: 4
 
 .. _PA3:
     http://demo.htsql.org
 anomalous number of credits (PA5_):
 
 .. htsql:: /course?credits>4|credits<3
+   :cut: 4
 
 .. _PA5:
     http://demo.htsql.org
 that have more than three credits (PA6_):
 
 .. htsql:: /course?(department='arthis'|department='stdart')&credits>3
+   :cut: 4
 
 .. _PA6:
     http://demo.htsql.org
 from ``'arthis'`` regardless of credits (PA7_):
 
 .. htsql:: /course?department='arthis'|department='stdart'&credits>3
+   :cut: 3
 
 .. _PA7:
     http://demo.htsql.org
 ``description`` (PA8_):
 
 .. htsql:: /course?description
+   :cut: 4
+   :hide:
 
 .. _PA8:
     http://demo.htsql.org
 a ``NULL`` for the field tested (WN3_):
 
 .. htsql:: /department?school!=='art'
+   :cut: 5
 
 .. _WN3:
     http://demo.htsql.org