[Checkins] SVN: Sandbox/ulif/grok-adminui/ Merged trunk into
admin-ui branch.
Uli Fouquet
uli at gnufix.de
Mon Aug 6 20:09:38 EDT 2007
Log message for revision 78643:
Merged trunk into admin-ui branch.
Changed:
U Sandbox/ulif/grok-adminui/INSTALL.txt
A Sandbox/ulif/grok-adminui/doc/examples/todolist/
U Sandbox/ulif/grok-adminui/doc/grok2html.py
U Sandbox/ulif/grok-adminui/doc/minitutorials/index.txt
U Sandbox/ulif/grok-adminui/doc/minitutorials/macros.txt
U Sandbox/ulif/grok-adminui/doc/minitutorials/searching.txt
A Sandbox/ulif/grok-adminui/doc/pygments_code_block_directive.py
U Sandbox/ulif/grok-adminui/doc/setup.py
-=-
Modified: Sandbox/ulif/grok-adminui/INSTALL.txt
===================================================================
--- Sandbox/ulif/grok-adminui/INSTALL.txt 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/INSTALL.txt 2007-08-07 00:09:37 UTC (rev 78643)
@@ -1,15 +1,15 @@
Preparing for grok development
------------------------------
-Grok is installed via buildout <http://cheeseshop.python.org/pypi/zc.buildout>.
+The Grok development sandbox is set up via `zc.buildout`_
-You need Python2.4 to use Grok.
+.. _zc.buildout: http://cheeseshop.python.org/pypi/zc.buildout
You may have setuptools already installed for your system Python. In
that case, you may need to upgrade it first because buildout requires
a very recent version::
- $ sudo easy_install-2.4 -U setuptools
+ $ sudo easy_install -U setuptools
If this command fails because easy_install is not available, there is
a good chance you do not have setuptools available for your system
@@ -18,17 +18,27 @@
Bootstrap the buildout environment::
- $ python2.4 bootstrap/bootstrap.py
+ $ python bootstrap/bootstrap.py
and run the buildout command::
$ bin/buildout
- [lots of stuff will be downloaded and installed locally here]
+ [lots of stuff will be downloaded and installed here]
+Note that if you have more than one sandbox for a Zope-based web
+application, it will probably make sense to share the eggs between the
+different sandboxes. You can tell zc.buildout to use a central eggs
+directory by creating ``~/.buildout/default.cfg`` with the following
+contents::
+
+ [buildout]
+ eggs-directory = /home/bruno/buildout-eggs
+
Running the demo applications
-----------------------------
-Start the instance:
+You can start Zope with the demo applications installed with the
+following command:
$ bin/zopectl fg
@@ -44,7 +54,10 @@
$ bin/test
-For functional tests we've set up a special test instance just for
-running the test from, which includes the minimum needed ZCML (so the
-tests run a tidbit faster).
+Generating the website files
+----------------------------
+Grok's tutorial documents for the website can easily be generated
+using the following script in ``bin``:
+
+ $ bin/grok2html /path/of/output/directory
Copied: Sandbox/ulif/grok-adminui/doc/examples/todolist (from rev 78642, grok/trunk/doc/examples/todolist)
Modified: Sandbox/ulif/grok-adminui/doc/grok2html.py
===================================================================
--- Sandbox/ulif/grok-adminui/doc/grok2html.py 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/doc/grok2html.py 2007-08-07 00:09:37 UTC (rev 78643)
@@ -1,6 +1,7 @@
import os
import codecs
import sys
+import urllib
import docutils.core
from docutils.writers.html4css1 import Writer
@@ -9,6 +10,9 @@
from zope.pagetemplate.pagetemplate import PageTemplate
from zope.pagetemplate.pagetemplatefile import PageTemplateFile
+# registers code-block directive using pygments.
+import pygments_code_block_directive
+
class ReStructuredTextToHTMLRenderer:
"""Convert from Restructured Text to HTML."""
@@ -44,16 +48,34 @@
def __init__(self, url, source, target):
self.url = url
self.target = target
- if os.path.isfile(target):
+ if os.path.isfile(target) and os.path.isfile(source):
if os.path.getmtime(source) < os.path.getmtime(target):
self.active = False
if os.path.isfile(source):
self.source = codecs.open(source,"r",'utf8').read()
+ elif source.startswith("http"):
+ print "Downloading %s" % source
+ try:
+ response = urllib.urlopen(source)
+ self.source = response.read()
+ except IOError, e:
+ if hasattr(e, 'reason'):
+ print 'We failed to reach a server.'
+ print 'Reason: ', e.reason
+ elif hasattr(e, 'code'):
+ print 'The server couldn\'t fulfill the request.'
+ print 'Error code:', e.code
+ self.source = u''
else:
self.source = source
srctxt = self.source.split('\n')
- title = srctxt[0]
- if title.startswith("====="): title = srctxt[1]
+ title = ''
+ count = 0
+ while title == '':
+ title = srctxt[count]
+ count += 1
+ if title.startswith("=====") or title.startswith(".."):
+ title = srctxt[count]
self.title = title
def set_rest_content(self):
@@ -153,6 +175,9 @@
rest_files.append(RestFile('macros',
os.path.join(source_dir, 'minitutorials', 'macros.txt'),
os.path.join(www_dir, 'minitutorials', 'macros.html')))
+ rest_files.append(RestFile('zc.buildout',
+ 'http://svn.zope.org/*checkout*/zc.buildout/trunk/doc/tutorial.txt',
+ os.path.join(www_dir, 'minitutorials', 'buildout.html')))
template = PageTemplateFile(os.path.join(source_dir, 'template.pt'))
create_html(rest_files, template)
Modified: Sandbox/ulif/grok-adminui/doc/minitutorials/index.txt
===================================================================
--- Sandbox/ulif/grok-adminui/doc/minitutorials/index.txt 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/doc/minitutorials/index.txt 2007-08-07 00:09:37 UTC (rev 78643)
@@ -16,8 +16,24 @@
want to use to search you objects before you perform the actual
search.
+ Author: Sebastian Ware
+
* `Macros With Grok </minitutorials/macros.html>`_:
Macros are a way to define a chunk of presentation in one template,
and share it in others. Changes to the macro are immediately
reflected in all templates, that use it.
+
+ Author: Uli Fouquet
+
+Buildout
+========
+
+Buildout is a python-based configuration-driven build tool for working with
+eggs.
+
+* `Buildout Tutorial </minitutorials/buildout.html>`_:
+
+ This is Jim Fulton's tutorial for using `buildout
+ <http://www.python.org/pypi/zc.buildout>`_ The original text document is
+ available at http://svn.zope.org/zc.buildout/trunk/doc/tutorial.txt.
Modified: Sandbox/ulif/grok-adminui/doc/minitutorials/macros.txt
===================================================================
--- Sandbox/ulif/grok-adminui/doc/minitutorials/macros.txt 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/doc/minitutorials/macros.txt 2007-08-07 00:09:37 UTC (rev 78643)
@@ -2,6 +2,8 @@
Mini-Howto: Macros with Grok
============================
+:Author: Uli Fouquet
+
Intended Audience:
* Python Developers
@@ -43,8 +45,10 @@
macros. Macros generally are attributes of the page template wherein they
are defined, but to get them rendered, we usually use views.
-We define a view ``MyMacros`` the usual way in ``app.py``::
+We define a view ``MyMacros`` the usual way in ``app.py``:
+.. code-block:: python
+
import grok
class Sample(grok.Application, grok.Container):
@@ -67,8 +71,10 @@
metal:define-slot=<slot-name>
-Let's define a very plain page macro::
+Let's define a very plain page macro:
+.. code-block:: html
+
<html metal:define-macro="mypage">
<head></head>
<body>
@@ -107,8 +113,10 @@
metal:use-macro="<macro-location>"
-Our ``app_templates/index.pt`` can be that simple::
+Our ``app_templates/index.pt`` can be that simple:
+.. code-block:: html
+
<html metal:use-macro="context/@@mymacros/mypage">
</html>
@@ -121,13 +129,15 @@
for.
When we fill the slots, we get different content rendered within
-the same macro. You can fill slots using
+the same macro. You can fill slots using::
metal:fill-slot="<slot-name>"
where the slot-name must be defined in the macro. Now, change
-``indext.pt`` to::
+``index.pt`` to:
+.. code-block:: html
+
<html metal:use-macro="context/@@mymacros/mypage">
<body>
<!-- slot 'mybody' was defined in the macro above -->
@@ -200,8 +210,10 @@
To define an 'all-purpose' macro, i.e. a macro, that can render
objects of (nearly) any type and thus be accessed from any
other page template, just set a very general context for your macro
-view::
+view:
+.. code-block:: python
+
from zope.interface import Interface
import grok
@@ -228,8 +240,10 @@
good style to provide this slots with your homegrown views as well.
To give your pages standard Zope3 look, you can do something like
-this in your page template::
+this in your page template:
+.. code-block:: html
+
<html metal:use-macro="context/@@standard_macros/page">
<head>
<title metal:fill-slot="title">
Modified: Sandbox/ulif/grok-adminui/doc/minitutorials/searching.txt
===================================================================
--- Sandbox/ulif/grok-adminui/doc/minitutorials/searching.txt 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/doc/minitutorials/searching.txt 2007-08-07 00:09:37 UTC (rev 78643)
@@ -2,6 +2,8 @@
Newbie Search Tutorial
======================
+:Author: Sebastian Ware
+
Introduction
------------
Grok supports the vanilla indexing services available in Zope 3 straight out of
@@ -28,7 +30,7 @@
in the "setup.py" script. The following directive indicates that zc.catalog
version 1.1.1 is required.
-::
+.. code-block:: python
install_requires=['setuptools',
'grok',
@@ -42,8 +44,9 @@
Example
-------
-::
+.. code-block:: python
+
# interfaces.py
class IProtonObject(Interface):
"""
@@ -51,7 +54,7 @@
"""
body = schema.Text(title=u'Body', required=False)
-::
+.. code-block:: python
# protonobject.py
class ProtonObject(grok.Model):
@@ -63,7 +66,7 @@
def __init__(self, body):
self.body = body
-::
+.. code-block:: python
# app.py
from hurry.query.query import Query, Text
Copied: Sandbox/ulif/grok-adminui/doc/pygments_code_block_directive.py (from rev 78642, grok/trunk/doc/pygments_code_block_directive.py)
===================================================================
--- Sandbox/ulif/grok-adminui/doc/pygments_code_block_directive.py (rev 0)
+++ Sandbox/ulif/grok-adminui/doc/pygments_code_block_directive.py 2007-08-07 00:09:37 UTC (rev 78643)
@@ -0,0 +1,177 @@
+#!/usr/bin/python
+
+# :Author: a Pygments author|contributor; Felix Wiemann; Guenter Milde
+# :Date: $Date: 2007-06-13 22:20:42 +1200 (Wed, 13 Jun 2007) $
+# :Copyright: This module has been placed in the public domain.
+#
+# This is a merge of `Using Pygments in ReST documents`_ from the pygments_
+# documentation, and a `proof of concept`_ by Felix Wiemann.
+#
+# ========== ===========================================================
+# 2007-06-01 Removed redundancy from class values.
+# 2007-06-04 Merge of successive tokens of same type
+# (code taken from pygments.formatters.others).
+# 2007-06-05 Separate docutils formatter script
+# Use pygments' CSS class names (like the html formatter)
+# allowing the use of pygments-produced style sheets.
+# 2007-06-07 Merge in the formatting of the parsed tokens
+# (misnamed as docutils_formatter) as class DocutilsInterface
+# 2007-06-08 Failsave implementation (fallback to a standard literal block
+# if pygments not found)
+# ========== ===========================================================
+#
+# ::
+
+"""Define and register a code-block directive using pygments
+"""
+
+# Requirements
+# ------------
+# ::
+
+from docutils import nodes
+from docutils.parsers.rst import directives
+try:
+ import pygments
+ from pygments.lexers import get_lexer_by_name
+ from pygments.formatters.html import _get_ttype_class
+except ImportError:
+ pass
+
+
+# Customisation
+# -------------
+#
+# Do not insert inline nodes for the following tokens.
+# (You could add e.g. Token.Punctuation like ``['', 'p']``.) ::
+
+unstyled_tokens = ['']
+
+# DocutilsInterface
+# -----------------
+#
+# This interface class combines code from
+# pygments.formatters.html and pygments.formatters.others.
+#
+# It does not require anything of docutils and could also become a part of
+# pygments::
+
+class DocutilsInterface(object):
+ """Parse `code` string and yield "classified" tokens.
+
+ Arguments
+
+ code -- string of source code to parse
+ language -- formal language the code is written in.
+
+ Merge subsequent tokens of the same token-type.
+
+ Yields the tokens as ``(ttype_class, value)`` tuples,
+ where ttype_class is taken from pygments.token.STANDARD_TYPES and
+ corresponds to the class argument used in pygments html output.
+
+ """
+
+ def __init__(self, code, language):
+ self.code = code
+ self.language = language
+
+ def lex(self):
+ # Get lexer for language (use text as fallback)
+ try:
+ lexer = get_lexer_by_name(self.language)
+ except ValueError:
+ # info: "no pygments lexer for %s, using 'text'"%self.language
+ lexer = get_lexer_by_name('text')
+ return pygments.lex(self.code, lexer)
+
+
+ def join(self, tokens):
+ """join subsequent tokens of same token-type
+ """
+ tokens = iter(tokens)
+ (lasttype, lastval) = tokens.next()
+ for ttype, value in tokens:
+ if ttype is lasttype:
+ lastval += value
+ else:
+ yield(lasttype, lastval)
+ (lasttype, lastval) = (ttype, value)
+ yield(lasttype, lastval)
+
+ def __iter__(self):
+ """parse code string and yield "clasified" tokens
+ """
+ try:
+ tokens = self.lex()
+ except IOError:
+ print "INFO: Pygments lexer not found, using fallback"
+ # TODO: write message to INFO
+ yield ('', self.code)
+ return
+
+ for ttype, value in self.join(tokens):
+ yield (_get_ttype_class(ttype), value)
+
+
+
+# code_block_directive
+# --------------------
+# ::
+
+def code_block_directive(name, arguments, options, content, lineno,
+ content_offset, block_text, state, state_machine):
+ """parse and classify content of a code_block
+ """
+ language = arguments[0]
+ # create a literal block element and set class argument
+ code_block = nodes.literal_block(classes=["code-block", language])
+
+ # parse content with pygments and add to code_block element
+ for cls, value in DocutilsInterface(u'\n'.join(content), language):
+ if cls in unstyled_tokens:
+ # insert as Text to decrease the verbosity of the output.
+ code_block += nodes.Text(value, value)
+ else:
+ code_block += nodes.inline(value, value, classes=[cls])
+
+ return [code_block]
+
+
+# Register Directive
+# ------------------
+# ::
+
+code_block_directive.arguments = (1, 0, 1)
+code_block_directive.content = 1
+directives.register_directive('code-block', code_block_directive)
+
+# .. _doctutils: http://docutils.sf.net/
+# .. _pygments: http://pygments.org/
+# .. _Using Pygments in ReST documents: http://pygments.org/docs/rstdirective/
+# .. _proof of concept:
+# http://article.gmane.org/gmane.text.docutils.user/3689
+#
+# Test output
+# -----------
+#
+# If called from the command line, call the docutils publisher to render the
+# input::
+
+if __name__ == '__main__':
+ from docutils.core import publish_cmdline, default_description
+ description = "code-block directive test output" + default_description
+ try:
+ import locale
+ locale.setlocale(locale.LC_ALL, '')
+ except:
+ pass
+ # Uncomment the desired output format:
+ publish_cmdline(writer_name='pseudoxml', description=description)
+ # publish_cmdline(writer_name='xml', description=description)
+ # publish_cmdline(writer_name='html', description=description)
+ # publish_cmdline(writer_name='latex', description=description)
+ # publish_cmdline(writer_name='newlatex2e', description=description)
+
+
+
Modified: Sandbox/ulif/grok-adminui/doc/setup.py
===================================================================
--- Sandbox/ulif/grok-adminui/doc/setup.py 2007-08-06 21:06:33 UTC (rev 78642)
+++ Sandbox/ulif/grok-adminui/doc/setup.py 2007-08-07 00:09:37 UTC (rev 78643)
@@ -4,7 +4,8 @@
name='grokdocs',
install_requires=['docutils',
'zope.pagetemplate',
- 'zope.app.renderer'
+ 'zope.app.renderer',
+ 'Pygments'
],
py_modules = ['grok2html'],
entry_points="""
More information about the Checkins
mailing list