Organizing tutorial
9 files changed, 41 insertions(+), 194 deletions(-)

M img/simple-world-with-source.png
M index.rst
M tutorial/rst-hints.rst => rst-hints.rst
M style/global.css
M tutorial.rst
M tutorial/index.rst => tutorial/1/index.rst
M tutorial/index.rst => tutorial/2/index.rst
M tutorial/show-body.js => tutorial/2/show-body.js
R tutorial/dss.py => 
M img/simple-world-with-source.png +0 -0

        
M index.rst +3 -1
@@ 39,7 39,7 @@ Getting started
 
 #.  **Write content**: Create a file called ``index.rst``. Write something in it:
 
-    .. include:: tutorial/index.rst
+    .. include:: tutorial/1/index.rst
         :literal:
 
 #.  **Add Dead Simple**: Download dss.py_ into the same folder as the page you just created

          
@@ 51,6 51,8 @@ Getting started
 #.  **View**: Browse to http://localhost:8000/
     
     .. image:: img/simple-world.png
+        :alt: Hello world page screenshot
+        :target: tutorial/1/index.html
 
 You now have a development server running; stop it anytime with ``Ctrl+C``, or leave it running 
 for the remainder of the tutorial.

          
M tutorial/rst-hints.rst => rst-hints.rst +0 -0

        
M style/global.css +12 -15
@@ 1,29 1,26 @@ 
 body {
     background-color: #eee;
+    position: absolute;
     margin: 0;
-    position: fixed;
     height: 100%;
     width: 100%;
-}
-body > .document {
-    width: 100%;
-    height: 100%;
+    max-height: 100%;
     overflow: auto;
 }
-body > .document > .section {
+body > .document {
     box-shadow: 1px 0 1px gray, -1px 0 1px gray;
-    padding: 1em;
+    padding: 0 20px 0 20px;
+    background-color: white;
     margin-left: auto;
     margin-right: auto;
-    background-color: white;
+    max-width: 1000px;
     min-height: 100%;
-    max-width: 1000px;
-    overflow-x: hidden;
+}
+h1.title {
+    margin-top: 0;
+    padding-top: 20px;
 }
 img {
-    position: relative;
-    opacity: 0.3;
+    border: thin solid gray;
+    max-width: 85%;
 }
-pre.page-source {
-    display: none;
-}

          
M tutorial.rst +15 -3
@@ 6,6 6,8 @@ From `getting started`_ , you should hav
 ``index.rst`` file. After running ``dss.py serve``, you should have gotten something like this:
 
 .. image:: img/simple-world.png
+    :alt: Hello world page screenshot
+    :target: tutorial/1/index.html
 
 Dead Simple saw a file with extension ``.rst`` in and translated that to html, which it served to
 the browser. If you look in the new ``_site`` folder, you'll now find an ``index.html`` generated by

          
@@ 17,12 19,22 @@ Adding JavaScript
 
 Beside ``index.rst``, add a file ``show-body.js``:
 
-.. include:: tutorial/show-body.js
+.. include:: tutorial/2/show-body.js
     :literal:
 
-Reloaded, the page should now bare its innards:
+When the page contains a node with class "tutorial," this script display's the page's html source.
+It does not take effect yet, however, because the ``index.rst`` file needs one modification. At the
+very top of the file, add the line::
+
+    .. class:: tutorial
+
+Make sure a blank line follows it.
+
+When you reload the page, its source should appear:
 
 .. image:: img/simple-world-with-source.png
+    :alt: Hello world page displaying source screenshot
+    :target: tutorial/2/index.html
 
-.. _getting started: index.html
+.. _getting started: index.html#getting-started
 .. _dss.py: dss.py

          
M tutorial/index.rst => tutorial/1/index.rst +0 -0

        
M tutorial/index.rst => tutorial/2/index.rst +2 -0
@@ 1,3 1,5 @@ 
+.. class:: tutorial
+
 Hello Simple World
 ==================
 

          
M tutorial/show-body.js => tutorial/2/show-body.js +9 -6
@@ 1,7 1,10 @@ 
 window.onload = function () {
-    var pre = document.createElement('pre')
-    pre.className = 'page-source'
-    // TODO: needs testing and adjustment in IE 8
-    pre.textContent = document.body.innerHTML
-    document.body.appendChild(pre)
-}
+    var rstDocs = document.getElementsByClassName('tutorial')
+    if (rstDocs.length) {
+        var pre = document.createElement('pre')
+        pre.className = 'page-source'
+        // TODO: needs testing and adjustment in IE 8
+        pre.textContent = rstDocs[0].innerHTML
+        document.body.appendChild(pre)
+    }
+}
  No newline at end of file

          
R tutorial/dss.py =>  +0 -169
@@ 1,169 0,0 @@ 
-#!/usr/bin/env python
-import argparse
-import fnmatch
-import os
-from os import path
-import re
-import shutil
-from SimpleHTTPServer import SimpleHTTPRequestHandler
-import SocketServer
-import string
-
-from docutils.core import publish_parts
-
-# TODO: ie http-equiv tag
-default_template = string.Template('''<!DOCTYPE html>
-<html><head>
-    $favicon
-    $title
-    $stylesheet
-    $scripts
-</head><body>
-    $content
-</body></html>
-''')
-
-def _prune_dirs(dirs):
-    for dirname in dirs:
-        if dirname[0] == '.' or dirname =='_site':
-            dirs.remove(dirname)
-
-class DeadSimpleSite:
-
-    def __init__(self, source):
-        self.source = path.abspath(source)
-        self.target = path.join(self.source, '_site')
-
-    def _clean(self):
-        for root, dirs, files in os.walk(self.target, topdown=False):
-            for filename in files:
-                target = path.join(root, filename)
-                relpath = path.relpath(target, self.target)
-                if relpath[0] == '.' and filename != '.htaccess':
-                    break
-                source = path.join(self.source, relpath)
-                if path.exists(source) or path.exists(re.sub(r'\.html$', '.rst', source)):
-                    continue
-                os.remove(target)
-            if path.relpath(root, self.target)[0] != '.' and len(os.listdir(root)) == 0:
-                os.rmdir(root)
-
-    def _render(self, source, template):
-        relpath = path.relpath(source, self.source)
-        depth = len(re.split(r'[/\\]', relpath)) - 1
-        html_root = depth * '../'
-        style_tag = '<link rel="stylesheet" href="%sstyle/global.css">' % html_root \
-            if path.exists(path.join(self.source, 'style/global.css')) else ''
-        script_tags = '\n'.join(['<script src="%s%s"></script>' % (html_root, script)
-            for script in self._scripts()])
-        favicon_tag = '<link rel="shortcut icon" href="favicon.ico">' \
-            if path.exists(path.join(self.source, 'favicon.ico')) else ''
-        with open(source) as source_file:
-            parts = publish_parts(
-                source=source_file.read(),
-                source_path=source,
-                writer_name='html',
-                # TODO: smart quotes on
-                settings_overrides={'doctitle_xform': False})
-        return template.substitute(
-            content = parts['html_body'],
-            favicon = favicon_tag,
-            title = '<title>%s</title>' % parts['title'],
-            root = html_root,
-            stylesheet = style_tag,
-            scripts = script_tags)
-
-    def _scripts(self):
-        scripts = []
-        for root, dirs, files in self._walk_source():
-            # TODO: this walks the output directory - that's bad
-            for script in fnmatch.filter(files, '*.js'):
-                if script[0] == '.':
-                    continue
-                script_path = path.join(root, script)
-                relpath = path.relpath(script_path, self.source)
-                # TODO: in *.nix, files can have a backslash in their names... deal with that?
-                scripts.append(relpath.replace('\\', '/')) # for Windows
-        return scripts
-
-    def _walk_source(self):
-        for root, dirs, files in os.walk(self.source):
-            for dirname in dirs:
-                if dirname[0] == '.' or dirname == '_site':
-                    dirs.remove(dirname)
-            yield root, dirs, [f for f in files if f[0] != '.' or f == '.htaccess']
-
-    def compile(self):
-        self._clean()
-        for root, dirs, files in self._walk_source():
-            rel = path.relpath(root, self.source)
-            if not path.exists(path.join(self.target, rel)):
-                os.makedirs(path.join(self.target, rel))
-            rst = {path.splitext(f)[0] for f in files if path.splitext(f)[1] == '.rst'}
-            for rst_name in rst:
-                source = path.join(root, rst_name + '.rst')
-                template_path = path.join(root, rst_name + '.html')
-                target = path.join(self.target, rel, rst_name + '.html')
-                ancestor = rel
-                while not path.exists(template_path):
-                    template_path = path.join(self.source, ancestor, '__template__.html')
-                    if not ancestor:
-                        break
-                    ancestor = path.dirname(ancestor)
-                if path.exists(template_path):
-                    with open(template_path) as template_in:
-                        template = string.Template(template_in.read())
-                else:
-                    template = default_template
-                with open(target, 'w') as html_out:
-                    html_out.write(self._render(source, template))
-            for filename in files:
-                source = path.join(root, filename)
-                target = path.join(self.target, rel, filename)
-                if path.splitext(filename)[1] in ['.rst', '.html']:
-                    if path.splitext(filename)[0] in rst:
-                        continue
-                if filename == '__template__.html':
-                    continue
-                shutil.copy2(source, target)
-
-    def serve(self, port=8000):
-        class LiveSiteHandler(SimpleHTTPRequestHandler):
-
-            def do_GET(self):
-                if self.path.startswith('/_site/'):
-                    self.send_error(403)
-                else:
-                    DeadSimpleSite('.').compile()
-                    self.path = '/_site' + self.path
-                    SimpleHTTPRequestHandler.do_GET(self)
-
-        server = SocketServer.TCPServer(('', port), LiveSiteHandler)
-        server.serve_forever()
-
-def cli(args=None):
-
-    def serve(parsed):
-        DeadSimpleSite(parsed.directory).serve(parsed.port)
-
-    def compile(parsed):
-        DeadSimpleSite(parsed.directory).compile()
-    
-    parser = argparse.ArgumentParser(description='Dead Simple Site generator')
-    parser.add_argument('-d', '--directory', help='folder containing site source files', default='.')
-    subs = parser.add_subparsers(title='subcommands')
-
-    parser_serve = subs.add_parser('serve', help='serve the site for development')
-    parser_serve.add_argument('-p', '--port', type=int, default=8000)
-    parser_serve.set_defaults(func=serve)
-
-    parser_compile = subs.add_parser('compile', help='build the site')
-    parser_compile.set_defaults(func=compile)
-    
-    parser_publish = subs.add_parser('publish', help='publish to Github pages')
-    
-    parsed = parser.parse_args(args)
-    parsed.func(parsed)
-
-if __name__ == '__main__':
-    cli()