[Checkins] SVN: megrok.rendersource/ initial import

Christian Klinger cklinger at novareto.de
Wed Mar 10 04:18:31 EST 2010


Log message for revision 109885:
  initial import

Changed:
  A   megrok.rendersource/branches/
  A   megrok.rendersource/tags/
  A   megrok.rendersource/trunk/
  A   megrok.rendersource/trunk/CHANGES.txt
  A   megrok.rendersource/trunk/LICENSE.txt
  A   megrok.rendersource/trunk/README.txt
  A   megrok.rendersource/trunk/bootstrap.py
  A   megrok.rendersource/trunk/buildout.cfg
  A   megrok.rendersource/trunk/setup.py
  A   megrok.rendersource/trunk/src/
  A   megrok.rendersource/trunk/src/megrok/
  A   megrok.rendersource/trunk/src/megrok/__init__.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/
  A   megrok.rendersource/trunk/src/megrok/rendersource/__init__.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/configure.zcml
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftesting.zcml
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/__init__.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/__init__.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/base.rst
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/include.txt
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/index.pt
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/README.txt
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/grok.css
  A   megrok.rendersource/trunk/src/megrok/rendersource/ftests/tests_functional.py
  A   megrok.rendersource/trunk/src/megrok/rendersource/rest.py

-=-
Added: megrok.rendersource/trunk/CHANGES.txt
===================================================================
--- megrok.rendersource/trunk/CHANGES.txt	                        (rev 0)
+++ megrok.rendersource/trunk/CHANGES.txt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,16 @@
+Changes
+-------
+0.5 upgrade to grok version 1.1rc1
+    changed the project namespace from d2m.rendersource to megrok.rendersource
+
+0.4 support for include/raw/csv-table directives
+    input/output-encoding can be configured in the view.namespace method
+    added functional tests
+
+0.3 added template reloading when in developer mode
+    changed configure.zcml to support autoinclude
+
+0.2 added missing configure.zcml
+    added configurable styleheet (settings_overrides)
+
+0.1 Initial revision

Added: megrok.rendersource/trunk/LICENSE.txt
===================================================================
--- megrok.rendersource/trunk/LICENSE.txt	                        (rev 0)
+++ megrok.rendersource/trunk/LICENSE.txt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,55 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+   accompanying copyright notice, this list of conditions,
+   and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+   copyright notice, this list of conditions, and the
+   following disclaimer in the documentation and/or other
+   materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+   endorse or promote products derived from this software
+   without prior written permission from the copyright
+   holders.
+
+4. The right to distribute this software or to use it for
+   any purpose does not give you the right to use
+   Servicemarks (sm) or Trademarks (tm) of the copyright
+   holders. Use of them is covered by separate agreement
+   with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+   files to carry prominent notices stating that you changed
+   the files and the date of any change.
+
+Disclaimer
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+  AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+  NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+  NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+  DAMAGE.
+

Added: megrok.rendersource/trunk/README.txt
===================================================================
--- megrok.rendersource/trunk/README.txt	                        (rev 0)
+++ megrok.rendersource/trunk/README.txt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,42 @@
+Grok source renderers
+=====================
+
+First take on making the zope.app.render classes available from Grok templates.
+
+* RestructuredText: template files with '.rst' extension
+  
+  renders a complete HTML page, including embedded stylesheet (default)
+  or with a configurable external stylesheet
+
+
+Installation
+------------
+
+Add 'megrok.rendersource' to the 'install_requires' list in your packages 'setup.py'.
+Run buildout again.
+Template reloading is available in developer mode only:
+  add 'devmode on' to the 'zope.conf = ' line in your buildout.cfg
+ 
+
+Configuration
+-------------
+
+To configure the stylesheet used with your template, add a method 'namespace' 
+to your view class:: 
+
+	class Overview(grok.View):
+	
+	    def namespace(self):
+	        # compute the stylesheet path to the file inside the 'static' folder, 
+	        # eg. 'grok.css'
+	        stylesheet=self.static['grok.css']()
+	        # enable absolut URL handling, disable embedding 
+	        return {'settings_overrides': {'stylesheet': stylesheet,
+	                                       'stylesheet_path': None,
+	                                       'embed_stylesheet': 0,
+	                                       'input_encoding': 'utf-8',
+	                                       'output_encoding': 'utf-8',
+	                                       }}
+
+Other docutils related options can be added to the 'settings_overrides' 
+dictionary. CF grok_overview.txt for more info on the namespace method.

Added: megrok.rendersource/trunk/bootstrap.py
===================================================================
--- megrok.rendersource/trunk/bootstrap.py	                        (rev 0)
+++ megrok.rendersource/trunk/bootstrap.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,121 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+                          help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+                   action="store_true", dest="distribute", default=False,
+                   help="Use Distribute rather than Setuptools.")
+
+parser.add_option("-c", None, action="store", dest="config_file",
+                   help=("Specify the path to the buildout configuration "
+                         "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+    args += ['-c', options.config_file]
+
+if options.version is not None:
+    VERSION = '==%s' % options.version
+else:
+    VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+    import pkg_resources
+    if not hasattr(pkg_resources, '_distribute'):
+        to_reload = True
+        raise ImportError
+except ImportError:
+    ez = {}
+    if USE_DISTRIBUTE:
+        exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+                         ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+    else:
+        exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                             ).read() in ez
+        ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    if to_reload:
+        reload(pkg_resources)
+    else:
+        import pkg_resources
+
+if sys.platform == 'win32':
+    def quote(c):
+        if ' ' in c:
+            return '"%s"' % c # work around spawn lamosity on windows
+        else:
+            return c
+else:
+    def quote (c):
+        return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws  = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+    requirement = 'distribute'
+else:
+    requirement = 'setuptools'
+
+if is_jython:
+    import subprocess
+
+    assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+           quote(tmpeggs), 'zc.buildout' + VERSION],
+           env=dict(os.environ,
+               PYTHONPATH=
+               ws.find(pkg_resources.Requirement.parse(requirement)).location
+               ),
+           ).wait() == 0
+
+else:
+    assert os.spawnle(
+        os.P_WAIT, sys.executable, quote (sys.executable),
+        '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+        dict(os.environ,
+            PYTHONPATH=
+            ws.find(pkg_resources.Requirement.parse(requirement)).location
+            ),
+        ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)

Added: megrok.rendersource/trunk/buildout.cfg
===================================================================
--- megrok.rendersource/trunk/buildout.cfg	                        (rev 0)
+++ megrok.rendersource/trunk/buildout.cfg	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,15 @@
+[buildout]
+develop = .
+parts = interpreter test
+extends =  http://grok.zope.org/releaseinfo/grok-1.1rc1.cfg  
+versions = versions
+
+[interpreter]
+recipe = zc.recipe.egg
+eggs = megrok.rendersource
+interpreter = python
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = megrok.rendersource [test]
+defaults = ['--tests-pattern', '^f?tests$', '-v']


Property changes on: megrok.rendersource/trunk/buildout.cfg
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/setup.py
===================================================================
--- megrok.rendersource/trunk/setup.py	                        (rev 0)
+++ megrok.rendersource/trunk/setup.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,34 @@
+from setuptools import setup, find_packages
+
+version = '0.5'
+
+setup(name='megrok.rendersource',
+      version=version,
+      description="Grok source renderers",
+      long_description="""\
+""",
+      classifiers=[], 
+      keywords="",
+      author="d2m",
+      author_email="michael at d2m.at",
+      url="",
+      license="ZPL",
+      package_dir={'': 'src'},
+      namespace_packages=['megrok'],      
+      packages=find_packages('src'),
+      include_package_data=True,
+      zip_safe=False,
+      extras_require={'test': [
+          'zope.app.testing',
+          'zope.testbrowser',
+          'zope.app.zcmlfiles',
+          'zope.securitypolicy',
+          'zope.app.authentication',
+          ]},
+      install_requires=['setuptools',
+                        'grokcore.view',
+                        # -*- Extra requirements: -*-
+                        ],
+      entry_points = """
+      """,
+       )

Added: megrok.rendersource/trunk/src/megrok/__init__.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/__init__.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/__init__.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

Added: megrok.rendersource/trunk/src/megrok/rendersource/__init__.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/__init__.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/__init__.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,2 @@
+# package
+

Added: megrok.rendersource/trunk/src/megrok/rendersource/configure.zcml
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/configure.zcml	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/configure.zcml	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,8 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:grok="http://namespaces.zope.org/grok">
+
+  <include package="grokcore.view" file="meta-minimal.zcml" />
+  <include package="grokcore.view" />
+  <grok:grok package="." />
+
+</configure>

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftesting.zcml
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftesting.zcml	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftesting.zcml	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,46 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:grok="http://namespaces.zope.org/grok"
+   i18n_domain="grok"
+   package="megrok.rendersource"
+   >
+
+  <include package="zope.app.zcmlfiles" file="meta.zcml" />
+  <include package="zope.securitypolicy" file="meta.zcml" />
+
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.authentication" />
+
+
+  <include package="grokcore.view" file="meta.zcml" />
+  <include package="grokcore.view" />
+
+  <include package="megrok.rendersource" />
+  <grok:grok package="megrok.rendersource.ftests" />
+
+  <!-- Typical functional testing security setup -->
+  <securityPolicy
+      component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+      />
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User"
+      />
+  <grant
+      permission="zope.View"
+      principal="zope.anybody"
+      />
+
+  <principal
+      id="zope.mgr"
+      title="Manager"
+      login="mgr"
+      password="mgrpw"
+      />
+
+  <role id="zope.Manager" title="Site Manager" />
+  <grantAll role="zope.Manager" />
+  <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftesting.zcml
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/__init__.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/__init__.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/__init__.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1 @@
+# this directory is a package


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/__init__.py
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/__init__.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/__init__.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/__init__.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1 @@
+# this directory is a package


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/__init__.py
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,95 @@
+"""
+Do a functional doctest test on the app.
+========================================
+
+:Test-Layer: functional
+
+Let's first create an instance of Testme at the top level:
+
+   >>> root = getRootFolder()
+   >>> root['app'] = Application()
+
+
+Run tests in the testbrowser
+----------------------------
+
+The zope.testbrowser.browser module exposes a Browser class that
+simulates a web browser similar to Mozilla Firefox or IE.  We use that
+to test how our application behaves in a browser.  For more
+information, see http://pypi.python.org/pypi/zope.testbrowser.
+
+Create a browser and visit the instance you just created:
+
+   >>> from zope.testbrowser.testing import Browser
+   >>> browser = Browser()
+   >>> browser.handleErrors  = False
+   >>> browser.open('http://localhost/app')
+
+Check include/raw/csv-table directives:
+
+   >>> browser.open('http://localhost/app/base')
+   <?xml version="1.0" encoding="utf-8" ?>
+   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+   <head>
+   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+   <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
+   <title></title>
+   <link rel="stylesheet" href="http://localhost/&#64;&#64;/megrok.rendersource.ftests.directives/grok.css" type="text/css" />
+   </head>
+   <body>
+   <div class="document">
+   <p>start base-template</p>
+   <p>include file:</p>
+   <p>--included text--</p>
+   <p>raw-file:</p>
+   --included text--<p>csv-table:</p>
+   <table border="1" class="docutils">
+   <colgroup>
+   <col width="100%" />
+   </colgroup>
+   <tbody valign="top">
+   <tr><td>--included text--</td>
+   </tr>
+   </tbody>
+   </table>
+   <p>end base-template</p>
+   </div>
+   </body>
+   </html>
+
+Check some basic information about the page you visit:
+
+   >>> browser.url
+   'http://localhost/app/base'
+   >>> browser.headers.get('Status').upper()
+   '200 OK'
+
+"""
+
+import grokcore.component
+import grokcore.view
+import megrok.rendersource
+
+
+class Application(grokcore.component.Context):
+    pass
+
+
+class Index(grokcore.view.View):
+    grokcore.component.name('index.html')
+
+
+class Base(grokcore.view.View):
+    
+    def namespace(self):
+        # compute the stylesheet path to the file inside the 'static' folder, 
+        # eg. 'grok.css'
+        stylesheet=self.static['grok.css']()
+        # enable absolut URL handling, disable embedding 
+        return {'settings_overrides': {'stylesheet': stylesheet,
+                                       'stylesheet_path': None,
+                                       'embed_stylesheet': 0,
+                                       'input_encoding': 'utf-8',
+                                       'output_encoding': 'utf-8',
+                                       }}


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app.py
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/base.rst
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/base.rst	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/base.rst	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,17 @@
+start base-template
+
+include file:
+
+.. include:: include.txt
+
+raw-file:
+
+.. raw:: html
+   :file: include.txt
+   
+csv-table:
+
+.. csv-table::
+   :file: include.txt
+
+end base-template
\ No newline at end of file


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/base.rst
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/include.txt
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/include.txt	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/include.txt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1 @@
+--included text--
\ No newline at end of file


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/include.txt
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/index.pt
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/index.pt	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/index.pt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,11 @@
+<html>
+<head>
+</head>
+<body>
+  <h1>Congratulations!</h1>
+
+  <p>Your Grok application is up and running.
+  Edit <code>testme/app_templates/index.pt</code> to change
+  this page.</p>
+</body>
+</html>


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/app_templates/index.pt
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/README.txt
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/README.txt	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/README.txt	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,2 @@
+Put static files here, like javascript and css.  They will be
+available as static/<filename> in views.


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/README.txt
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/grok.css
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/grok.css	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/grok.css	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1 @@
+/* blank stylesheet */
\ No newline at end of file


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/directives/static/grok.css
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/ftests/tests_functional.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/ftests/tests_functional.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/ftests/tests_functional.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,61 @@
+import re
+import unittest
+import megrok.rendersource
+import os.path
+
+from pkg_resources import resource_listdir
+from zope.testing import doctest, renormalizing
+from zope.app.testing.functional import (HTTPCaller, getRootFolder,
+                                         FunctionalTestSetup, sync, ZCMLLayer)
+
+# Use Zope versions to get neat options like "-1" and "--udiff"
+from zope.testing.doctest import DocTestSuite, DocFileSuite
+
+ftesting_zcml = os.path.join(os.path.dirname(megrok.rendersource.__file__),
+                             'ftesting.zcml')
+FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer')
+
+def setUp(test):
+    FunctionalTestSetup().setUp()
+
+def tearDown(test):
+    FunctionalTestSetup().tearDown()
+
+checker = renormalizing.RENormalizing([
+    # Accommodate to exception wrapping in newer versions of mechanize
+    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
+    ])
+
+def suiteFromPackage(name):
+    files = resource_listdir(__name__, name)
+    suite = unittest.TestSuite()
+    for filename in files:
+        if not filename.endswith('.py'):
+            continue
+        if filename == '__init__.py':
+            continue
+
+        dottedname = 'megrok.rendersource.ftests.%s.%s' % (name, filename[:-3])
+        test = DocTestSuite(
+            dottedname, setUp=setUp, tearDown=tearDown,
+            checker=checker,
+            extraglobs=dict(http=HTTPCaller(),
+                            getRootFolder=getRootFolder,
+                            sync=sync),
+            optionflags=(doctest.ELLIPSIS+
+                         doctest.NORMALIZE_WHITESPACE+
+                         doctest.REPORT_NDIFF)
+            )
+        test.layer = FunctionalLayer
+
+        suite.addTest(test)
+    return suite
+
+def test_suite():
+    suite = unittest.TestSuite()
+    for name in ['directives']:
+        suite.addTest(suiteFromPackage(name))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: megrok.rendersource/trunk/src/megrok/rendersource/ftests/tests_functional.py
___________________________________________________________________
Added: svn:executable
   + *

Added: megrok.rendersource/trunk/src/megrok/rendersource/rest.py
===================================================================
--- megrok.rendersource/trunk/src/megrok/rendersource/rest.py	                        (rev 0)
+++ megrok.rendersource/trunk/src/megrok/rendersource/rest.py	2010-03-10 09:18:31 UTC (rev 109885)
@@ -0,0 +1,64 @@
+import codecs
+import locale
+import os.path
+import grokcore.view
+import docutils.core
+import grokcore.component
+
+from docutils.writers.html4css1 import Writer
+from docutils.writers.html4css1 import HTMLTranslator
+from zope.app.renderer.rest import (
+    ReStructuredTextSourceFactory, ReStructuredTextToHTMLRenderer)
+from zope.app.appsetup.appsetup import getConfigContext
+
+
+class RSTToHTMLRenderer(ReStructuredTextToHTMLRenderer):
+    """ """
+
+    def render(self, settings_overrides={}):
+        # default settings for the renderer
+        overrides = {
+            'halt_level': 6,
+            'input_encoding': 'unicode',
+            'output_encoding': 'unicode',
+            'initial_header_level': 3,
+            }
+        overrides.update(settings_overrides)
+        writer = Writer()
+        writer.translator_class = HTMLTranslator
+        html = docutils.core.publish_file(
+            source_path=self.context,
+            writer=writer,
+            settings_overrides=overrides,
+            )
+        return html
+
+
+class RSTTemplateBase(grokcore.view.components.GrokTemplate):
+    
+    def __init__(self, string=None, filename=None, _prefix=None):
+        super(RSTTemplateBase, self).__init__(string=string, filename=filename, _prefix=_prefix)
+        self.string=string
+        self.filename=filename
+        self._prefix=_prefix
+        self._cooked=False
+                
+    def setFromFilename(self, filename, _prefix=None):
+        filename = os.path.join(_prefix, filename)
+        self._template = ReStructuredTextSourceFactory(filename)
+        
+    def render(self, view):
+        view.response.setHeader('Content-Type','text/html')
+        settings_overrides=self.getNamespace(view).get('settings_overrides',{})
+        if not(self._cooked) or getConfigContext().hasFeature('devmode'):
+            self.setFromFilename(self.filename, self._prefix)
+            self._cooked=RSTToHTMLRenderer(self._template, view.request).render(settings_overrides=settings_overrides)
+        return self._cooked
+    
+class RSTTemplateFactory(grokcore.component.GlobalUtility):
+
+    grokcore.component.implements(grokcore.view.interfaces.ITemplateFileFactory)
+    grokcore.component.name('rst')
+
+    def __call__(self, filename, _prefix=None):
+        return RSTTemplateBase(filename=filename, _prefix=_prefix)



More information about the checkins mailing list