Skip to content

Commit

Permalink
Add another demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmachado committed Sep 7, 2012
1 parent 1360e34 commit 181eb08
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -26,6 +26,8 @@ directory of your app:
$ torneira --port 8888 --settings settings.py

In the directory `demos/simple_app/` there is a minimal app already configured.
If you want to see a more complex app that uses more available features, take a
look at `demos/more_complex_app`.

Contributing
------------
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions demo/more_complex_app/handlers.py
@@ -0,0 +1,23 @@
# coding: utf-8
from tornado.web import asynchronous
from torneira import __version__
from torneira.handler import TorneiraHandler
from torneira.template import MakoMixin


class MainHandler(TorneiraHandler, MakoMixin):
def index(self):
return self.render_to_template('index.html')

def simple(self):
return "You can use self.write or just returns the contents"

def as_json(self):
return {'json_response': [1, 2, 3]}

@asynchronous
def async(self):
context = {'version': __version__}
content = self.render_to_template('async.html', **context)
self.write(content)
self.finish()
12 changes: 12 additions & 0 deletions demo/more_complex_app/settings.py
@@ -0,0 +1,12 @@
import os
from functools import partial


ROOT_URLS = 'more_complex_app.urls'
DEBUG = True

join = partial(os.path.join, os.path.dirname(__file__))

TEMPLATE_DIRS = (
join('templates'),
)
12 changes: 12 additions & 0 deletions demo/more_complex_app/templates/async.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample Torneira App</title>
</head>
<body>
<h1>Async Handler</h1>

<p>This is a template rendered on an async request.</p>
</body>
</html>
19 changes: 19 additions & 0 deletions demo/more_complex_app/templates/index.html
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample Torneira App</title>
</head>
<body>
<h1>Torneira</h1>

<p>This is a simple template, rendered using <a href="http://www.makotemplates.org/">Mako template engine</a></p>

<ul>
<li><a href="/">This page</a></li>
<li><a href="/simple">Simple response - no template!</a></li>
<li><a href="/async">Async handler + mako template</a></li>
<li><a href="/json">We can speak JSON too!</a></li>
</ul>
</body>
</html>
12 changes: 12 additions & 0 deletions demo/more_complex_app/urls.py
@@ -0,0 +1,12 @@
# coding: utf-8
from tornado.web import url

from more_complex_app.handlers import MainHandler


urls = (
url(r'/', MainHandler, {'action': 'index'}),
url(r'/simple', MainHandler, {'action': 'simple'}),
url(r'/json', MainHandler, {'action': 'as_json'}),
url(r'/async', MainHandler, {'action': 'async'}),
)

0 comments on commit 181eb08

Please sign in to comment.