
Contents:
Look Mom, no database
Nothing up my sleeves...
The automatic navigation decorations
The comments area at the bottom
The index of contents
Syntax highlighted code displays
Dynamic examples
Pop-up footnotes
Wasn't that easy?
;c)
Please look at the browser formatted page, noting the features (and trying them where they require interaction), then look at the configuration source listing for the page colorize?page=W1500.whyIsWhiffCool to see how incredibly easy it was to do all this cool stuff!
The basic problem with having database design automated is that you always need to change the design later -- and if your db-design automater says that they make changing the design easy, don't believe them. Usually when you need to change the design you have already populated the database with important information which has to be retrofitted back into the new database design, and in order to do this you have to understand everything about how the db-automator works, including such things as name mangling. It's not pretty.
Fixing the database later works much better when you put the database together carefully by hand in the first place and documented the database design in the process.
In spite of this rather pedantic attitude, it is easy to build complex, interactive web pages using WHIFF. Lets explore some of the features demonstrated on this page.
comments which
does a number of things.
comments
is turned off in the "production" deploy.
When I run the script in development mode I see a form
that allows me to add new subsections to the documentation
hierarchy, which automatically fills in the standard
document page components.
In the production deploy this feature is
not enabled. You can run the documentation in development mode
too using INSTALL/doc/servedocs.py, and if
you come up with a good subsection that you think I should add
let me know.
One of the services provided by the comments middleware
generates page navigation decorations for moving to other documentation
pages. The implementation of the navigation decorations examines
the files in the documentation directory, identifies the ancestors,
children, and siblings of this page, and formats the titles and summaries
of the related pages in two places -- there is a navigation pane
showing the titles of related page on the upper left, and towards the
bottom there is a summaries areas showing titles related pages with
summaries of subsections.
The configuration for this page explicitly imported this
functionality by putting the entire text of the page inside
a include invoking the comments middleware.
{{include "comments"}}
{{using title}} Whiff is cool because... {{/using}}
{{using summary}} This self-referential... {{/using}}
{{using body}} Please notice the... {{/using}}
{{/include}}
comments middleware did the rest.
comments middleware also automatically included
an input form for the reader (you) to comment on the page.
at the very bottom of the page.
The configuration for this page automatically got the
comment recording service when it
used the comments middleware. The storage mechanism for
the comment text is configured externally
as a resource by the WHIFF root module
configuration.
comments middleware or any
of the documentation pages.
heading and headings. The
headings middleware wraps the main content of the
page like this:
{{include "whiff_middleware/headings"}}
{{using headingsFormat}}
{{include "headers"/}}
{{/using}}
{{using text}}
This page is addressed to...
{{include "whiff_middleware/heading"}}
Look Mom, no database
{{/include}}
This page uses no...
{{include "whiff_middleware/heading"}}
Nothing up my sleeves
{{/include}}
The WHIFF design ...
{{/using}}
{{/include}}
headings
middleware establishes an environment data structure for collecting
headings to construct a table of contents. The heading
fragments both format the headings as HTML and record the heading
text in the table of contents data structure. The headers
application fragment formats the table of contents data structure
into a sequence of internal HTML links from the top of the page to
the relevant page header.
headings middleware implementation had
to be just a bit clever to get this to work.
Obviously, the heading middlewares must
execute before the headers application --
so the headings middleware evaluates its
text argument first and its
headersFormat argument later so that the
headersFormat argument can use the complete
table of contents data structure.
When headings delivers its HTML stream
response it delivers the formatted headers first followed
by the text.
To get the table of contents functionality this page included the relevant middlewares in appropriate positions -- no other explicit bookkeeping was needed.
"hello world python script"
def hello():
print "hello world"
if __name__=="__main__":
hello()
{{include "python"}}
"hello world python script"
def hello():
print "hello world"
if __name__=="__main__":
hello()
{{/include}}
python.whiff
to colorize the python code.
python.whiff
just passes the text to the pygments
middleware after configuring the pygments middleware for Python code.
Here is the configuration template source:
{{env whiff.content_type: "text/html"/}}
{{require page/}}
{{include "whiff_middleware/pygmentsColorize"
pygmentsCss.lexer: "python"}}
{{use page/}}
{{/include}}
bash and whiffhtml
which make colorizing other code examples just as easy.
"example"
middleware allows the view to switch between viewing the
configuration template, the
colorized generated HTML, and the formatted
HTML for a given example, for example like this:
| whiff source | generated page | formatted output |
|
temp content
|
||
example middleware is quite simple
{{include "example"}}
{{using targetName}}debugdump{{/using}}
{{using page}}
<h2>Environment entries:</h2>
<pre>
{{include "whiff_middleware/debugDump"/}}
</pre>
{{/using}}
{{/include}}
targetName is used by the javascript
generator and could be eliminated. It is there
for historical reasons at the moment.
footnote middleware
{{include "footnote"}}
Like this one.
{{/include}}
footnote middleware is surprisingly complex
because it wires together two HTML document object elements
with two event handlers. But this page need not concern itself
with any of that complexity. It just uses
the middleware and the footnote appears.
Now that you have read the formatted HTML version of the page look at the configuration source listing for the page colorize?page=W1500.whyIsWhiffCool to see how incredibly easy it was to do all this cool stuff!