Skip to content

Commit

Permalink
Add option for setting the template rendering parameters.
Browse files Browse the repository at this point in the history
Do some PEP-8 clean-up and typo fixing along the way.
  • Loading branch information
Cito committed Feb 9, 2012
1 parent be9ba07 commit 2cf110e
Show file tree
Hide file tree
Showing 16 changed files with 678 additions and 378 deletions.
15 changes: 12 additions & 3 deletions .gitignore
@@ -1,7 +1,16 @@
*.pyc build/
TurboGears2.egg-info
dist/ dist/
*~
*.egg *.egg
build/ *.egg-info
*.pyc
*.pyo
*.swp
*.mak.py *.mak.py
*.DS_Store
.coverage .coverage
.idea
.noseids
.project
.pydevproject
.settings
8 changes: 6 additions & 2 deletions .hgignore
@@ -1,15 +1,19 @@


syntax: glob syntax: glob
*~ *~
*.egg
*.egg-info *.egg-info
*.mak.py *.mak.py
*.pyc *.pyc
*.pyo *.pyo
*.swp *.swp
*.DS_Store
.coverage .coverage
.idea
.noseids .noseids
*.egg .project
*.DS_Store .pydevproject
.settings


syntax: regexp syntax: regexp
^build ^build
Expand Down
39 changes: 30 additions & 9 deletions tests/test_stack/rendering/controllers/root.py
Expand Up @@ -2,6 +2,7 @@


from tg import expose, redirect, config, validate, override_template, response from tg import expose, redirect, config, validate, override_template, response
from tg.decorators import paginate, use_custom_format, with_trailing_slash from tg.decorators import paginate, use_custom_format, with_trailing_slash
from tg.render import render
from tg.controllers import TGController from tg.controllers import TGController
from tw.forms import TableForm, TextField, CalendarDatePicker, SingleSelectField, TextArea from tw.forms import TableForm, TextField, CalendarDatePicker, SingleSelectField, TextArea
from tw.api import WidgetsList from tw.api import WidgetsList
Expand All @@ -19,12 +20,14 @@ class fields(WidgetsList):




class GoodJsonObject(object): class GoodJsonObject(object):

def __json__(self): def __json__(self):
return {'Json':'Rocks'} return {'Json':'Rocks'}


class BadJsonObject(object): class BadJsonObject(object):
pass pass



class JsonController(TGController): class JsonController(TGController):


@expose('json') @expose('json')
Expand All @@ -48,6 +51,7 @@ def json_with_object(self):
def json_with_bad_object(self): def json_with_bad_object(self):
return dict(obj=BadJsonObject()) return dict(obj=BadJsonObject())



class RootController(TGController): class RootController(TGController):


j = JsonController() j = JsonController()
Expand All @@ -56,12 +60,28 @@ class RootController(TGController):
def index(self): def index(self):
return {} return {}


@expose('genshi:index_autodoctype.html') @expose('genshi:genshi_doctype.html')
def autodoctype(self): def auto_doctype(self):
return {}

@expose('genshi:genshi_doctype.html', content_type='text/html')
def auto_doctype_html(self):
return {}

@expose('genshi:genshi_doctype.html', content_type='application/xhtml+xml')
def auto_doctype_xhtml(self):
return {}

@expose('genshi:genshi_doctype.html', render_params=dict(doctype=None))
def explicit_no_doctype(self):
return {} return {}


@expose('genshi:index_autodoctype.html', content_type='application/xhtml+xml') @expose('genshi:genshi_doctype.html', render_params=dict(doctype='html'))
def autodoctype_xhtml_strict(self): def explicit_doctype_html(self):
return {}

@expose('genshi:genshi_doctype.html', render_params=dict(doctype='xhtml'))
def explicit_doctype_xhtml(self):
return {} return {}


@expose('genshi:genshi_form.html') @expose('genshi:genshi_form.html')
Expand Down Expand Up @@ -248,15 +268,16 @@ def template_override_multiple_content_type(self, override=False):
return dict(format='something', status="ok") return dict(format='something', status="ok")


@expose() @expose()
def manual_rendering(self, frompylons=False): def jinja2_manual_rendering(self, frompylons=False):
if frompylons: if frompylons:
from pylons.templating import render_jinja2 from pylons.templating import render_jinja2
return render_jinja2('jinja_inherits.html') return render_jinja2('jinja_inherits.html')
else: else:
from tg.render import render
return render({}, 'jinja', 'jinja_inherits.html') return render({}, 'jinja', 'jinja_inherits.html')


@expose() @expose()
def genshi_doctype_removal(self): def genshi_manual_rendering_with_doctype(self, doctype=None):
from tg.render import render response.content_type = 'text/html'
return render({}, 'genshi', 'index_autodoctype.html', doctype=None) response.charset = 'utf-8'
return render({}, 'genshi', 'genshi_doctype.html', doctype=doctype)

15 changes: 15 additions & 0 deletions tests/test_stack/rendering/templates/genshi_doctype.html
@@ -0,0 +1,15 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<meta http-equiv="content-type"
content="${response.content_type or 'none'}; charset=${response.charset or 'none'}" />
<title>TurboGears 2 doctype generation test</title>
</head>

<body>
<p>TurboGears 2 is a rapid web application development toolkit.</p>
<hr/>
<p py:content="'Rendered with Genshi.'">This is a Genshi template.</p>
</body>
</html>
15 changes: 0 additions & 15 deletions tests/test_stack/rendering/templates/index_autodoctype.html

This file was deleted.

0 comments on commit 2cf110e

Please sign in to comment.