Skip to content

Commit 137906f

Browse files
committed
Initial commit
0 parents  commit 137906f

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
*.py[cod]
2+
3+
# C extensions
4+
*.so
5+
6+
# Packages
7+
*.egg
8+
*.egg-info
9+
dist
10+
build
11+
eggs
12+
parts
13+
bin
14+
var
15+
sdist
16+
develop-eggs
17+
.installed.cfg
18+
lib
19+
lib64
20+
__pycache__
21+
22+
# Installer logs
23+
pip-log.txt
24+
25+
# Unit test / coverage reports
26+
.coverage
27+
.tox
28+
nosetests.xml
29+
30+
# Translations
31+
*.mo
32+
33+
# Mr Developer
34+
.mr.developer.cfg
35+
.project
36+
.pydevproject

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.SILENT:
2+
3+
test:
4+
python -m tomako.tests

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Tornado + Mako = tomako
2+
=======================
3+
4+
Tomako is a tiny library designed to provide integration between Mako and Tornado.

tomako/__init__.py

Whitespace-only changes.

tomako/loader.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding: utf-8
2+
import os
3+
4+
from mako.lookup import TemplateLookup
5+
from tornado.template import Loader
6+
7+
8+
class MakoLoader(Loader):
9+
def __init__(self, root_directory, **kwargs):
10+
super(MakoLoader, self).__init__(root_directory, **kwargs)
11+
path = os.path.abspath(root_directory)
12+
self._lookup = TemplateLookup(directories=path, input_encoding='utf-8',
13+
output_encoding='utf-8',
14+
default_filters=['decode.utf8'])
15+
16+
def _create_template(self, name):
17+
template = self._lookup.get_template(name)
18+
template.generate = template.render
19+
20+
return template

tomako/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tomako/tests/__main__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# coding: utf-8
2+
import unittest
3+
4+
from tomako.tests.mako_loader_test import *
5+
6+
7+
unittest.main()

tomako/tests/mako_loader_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding: utf-8
2+
import os
3+
import unittest
4+
5+
from tornado.escape import to_unicode
6+
7+
from tomako.loader import MakoLoader
8+
9+
10+
class MakoLoaderTest(unittest.TestCase):
11+
def setUp(self):
12+
path = os.path.join(os.path.dirname(__file__), "templates")
13+
self.loader = MakoLoader(path)
14+
15+
def test_mako_syntax_in_utf8_file(self):
16+
tmpl = self.loader.load("utf8.html")
17+
result = tmpl.generate(name='my friend')
18+
self.assertEqual(to_unicode(result).strip(), u"H\u00e9llo my friend")

tomako/tests/templates/utf8.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Héllo ${name}

0 commit comments

Comments
 (0)