Armin Ronacher | de478f6 | 2007-02-28 22:35:04 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Armin Ronacher | 5829306 | 2008-02-11 15:36:22 +0100 | [diff] [blame^] | 2 | """ |
| 3 | jinja |
| 4 | ~~~~~ |
| 5 | |
| 6 | Jinja is a `sandboxed`_ template engine written in pure Python. It |
| 7 | provides a `Django`_ like non-XML syntax and compiles templates into |
| 8 | executable python code. It's basically a combination of Django templates |
| 9 | and python code. |
| 10 | |
| 11 | Nutshell |
| 12 | -------- |
| 13 | |
| 14 | Here a small example of a Jinja template:: |
| 15 | |
| 16 | {% extends 'base.html' %} |
| 17 | {% block title %}Memberlist{% endblock %} |
| 18 | {% block content %} |
| 19 | <ul> |
| 20 | {% for user in users %} |
| 21 | <li><a href="{{ user.url|e }}">{{ user.username|e }}</a></li> |
| 22 | {% endfor %} |
| 23 | </ul> |
| 24 | {% endblock %} |
| 25 | |
| 26 | Philosophy |
| 27 | ---------- |
| 28 | |
| 29 | Application logic is for the controller but don't try to make the life |
| 30 | for the template designer too hard by giving him too few functionality. |
| 31 | |
| 32 | For more informations visit the new `jinja webpage`_ and `documentation`_. |
| 33 | |
| 34 | Note |
| 35 | ---- |
| 36 | |
| 37 | This is the Jinja 1.0 release which is completely incompatible with the |
| 38 | old "pre 1.0" branch. The old branch will still receive security updates |
| 39 | and bugfixes but the 1.0 branch will be the only version that receives |
| 40 | support. |
| 41 | |
| 42 | If you have an application that uses Jinja 0.9 and won't be updated in |
| 43 | the near future the best idea is to ship a Jinja 0.9 checkout together |
| 44 | with the application. |
| 45 | |
| 46 | The `Jinja tip`_ is installable via `easy_install` with ``easy_install |
| 47 | Jinja==dev``. |
| 48 | |
| 49 | .. _sandboxed: http://en.wikipedia.org/wiki/Sandbox_(computer_security) |
| 50 | .. _Django: http://www.djangoproject.com/ |
| 51 | .. _jinja webpage: http://jinja.pocoo.org/ |
| 52 | .. _documentation: http://jinja.pocoo.org/documentation/index.html |
| 53 | .. _Jinja tip: http://dev.pocoo.org/hg/jinja-main/archive/tip.tar.gz#egg=Jinja-dev |
| 54 | """ |
Armin Ronacher | 0830e25 | 2007-03-22 23:45:30 +0100 | [diff] [blame] | 55 | import os |
Armin Ronacher | d15a4dc | 2007-05-28 18:16:16 +0200 | [diff] [blame] | 56 | import sys |
Armin Ronacher | 0830e25 | 2007-03-22 23:45:30 +0100 | [diff] [blame] | 57 | import ez_setup |
| 58 | ez_setup.use_setuptools() |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 59 | |
| 60 | from distutils.command.build_ext import build_ext |
Armin Ronacher | bc3d2d8 | 2007-10-19 15:49:56 +0200 | [diff] [blame] | 61 | from distutils.errors import CCompilerError, DistutilsError |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 62 | from setuptools import setup, Extension, Feature |
Armin Ronacher | de478f6 | 2007-02-28 22:35:04 +0100 | [diff] [blame] | 63 | |
Armin Ronacher | 0830e25 | 2007-03-22 23:45:30 +0100 | [diff] [blame] | 64 | |
Armin Ronacher | e21ced2 | 2007-03-22 23:57:10 +0100 | [diff] [blame] | 65 | def list_files(path): |
| 66 | for fn in os.listdir(path): |
| 67 | if fn.startswith('.'): |
| 68 | continue |
| 69 | fn = os.path.join(path, fn) |
| 70 | if os.path.isfile(fn): |
| 71 | yield fn |
| 72 | |
| 73 | |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 74 | class optional_build_ext(build_ext): |
| 75 | |
Armin Ronacher | bc3d2d8 | 2007-10-19 15:49:56 +0200 | [diff] [blame] | 76 | def run(self): |
| 77 | try: |
| 78 | build_ext.run(self) |
| 79 | except DistutilsError, e: |
| 80 | self.compiler = None |
| 81 | self._setup_error = e |
| 82 | |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 83 | def build_extension(self, ext): |
| 84 | try: |
Armin Ronacher | bc3d2d8 | 2007-10-19 15:49:56 +0200 | [diff] [blame] | 85 | if self.compiler is None: |
| 86 | raise self._setup_error |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 87 | build_ext.build_extension(self, ext) |
| 88 | except CCompilerError, e: |
| 89 | print '=' * 79 |
| 90 | print 'INFORMATION' |
Armin Ronacher | d15a4dc | 2007-05-28 18:16:16 +0200 | [diff] [blame] | 91 | print ' the speedup extension could not be compiled, Jinja will' |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 92 | print ' fall back to the native python classes.' |
| 93 | print '=' * 79 |
Armin Ronacher | d15a4dc | 2007-05-28 18:16:16 +0200 | [diff] [blame] | 94 | except: |
| 95 | e = sys.exc_info()[1] |
| 96 | print '=' * 79 |
| 97 | print 'WARNING' |
| 98 | print ' could not compile optional speedup extension. This is' |
| 99 | print ' is not a real problem because Jinja provides a native' |
| 100 | print ' implementation of those classes but for best performance' |
| 101 | print ' you could try to reinstall Jinja after fixing this' |
| 102 | print ' problem: %s' % e |
| 103 | print '=' * 79 |
Armin Ronacher | ee2c18e | 2007-04-20 22:39:04 +0200 | [diff] [blame] | 104 | |
| 105 | |
Armin Ronacher | de478f6 | 2007-02-28 22:35:04 +0100 | [diff] [blame] | 106 | setup( |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 107 | name='Jinja', |
Armin Ronacher | 1c19919 | 2007-11-18 10:21:27 +0100 | [diff] [blame] | 108 | version='1.3', |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 109 | url='http://jinja.pocoo.org/', |
| 110 | license='BSD', |
| 111 | author='Armin Ronacher', |
| 112 | author_email='armin.ronacher@active-4.com', |
| 113 | description='A small but fast and easy to use stand-alone template ' |
| 114 | 'engine written in pure python.', |
Armin Ronacher | 5829306 | 2008-02-11 15:36:22 +0100 | [diff] [blame^] | 115 | long_description = __doc__, |
Armin Ronacher | e21ced2 | 2007-03-22 23:57:10 +0100 | [diff] [blame] | 116 | # jinja is egg safe. But because we distribute the documentation |
| 117 | # in form of html and txt files it's a better idea to extract the files |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 118 | zip_safe=False, |
| 119 | classifiers=[ |
Armin Ronacher | de478f6 | 2007-02-28 22:35:04 +0100 | [diff] [blame] | 120 | 'Development Status :: 5 - Production/Stable', |
| 121 | 'Environment :: Web Environment', |
| 122 | 'Intended Audience :: Developers', |
| 123 | 'License :: OSI Approved :: BSD License', |
| 124 | 'Operating System :: OS Independent', |
| 125 | 'Programming Language :: Python', |
Armin Ronacher | 8ebf1f9 | 2007-03-03 11:22:18 +0100 | [diff] [blame] | 126 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 127 | 'Topic :: Software Development :: Libraries :: Python Modules', |
| 128 | 'Topic :: Text Processing :: Markup :: HTML' |
| 129 | ], |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 130 | keywords=['python.templating.engines'], |
Armin Ronacher | 21dce51 | 2007-11-27 01:07:20 +0100 | [diff] [blame] | 131 | packages=['jinja', 'jinja.translators', 'jinja.contrib'], |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 132 | data_files=[ |
Armin Ronacher | 99e5baa | 2007-11-17 21:56:19 +0100 | [diff] [blame] | 133 | ('docs/html', list(list_files('docs/html'))), |
Armin Ronacher | 72bb257 | 2007-03-23 17:24:48 +0100 | [diff] [blame] | 134 | ('docs/txt', list(list_files('docs/src'))) |
Armin Ronacher | 0830e25 | 2007-03-22 23:45:30 +0100 | [diff] [blame] | 135 | ], |
Armin Ronacher | 2158091 | 2007-04-17 17:13:10 +0200 | [diff] [blame] | 136 | entry_points=''' |
| 137 | [python.templating.engines] |
| 138 | jinja = jinja.plugin:BuffetPlugin |
| 139 | ''', |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 140 | extras_require={'plugin': ['setuptools>=0.6a2']}, |
| 141 | features={ |
Armin Ronacher | a7804ef | 2007-06-15 18:03:21 +0200 | [diff] [blame] | 142 | 'speedups': Feature( |
| 143 | 'optional C-speed enhancements', |
Armin Ronacher | 825e522 | 2007-11-16 16:16:23 +0100 | [diff] [blame] | 144 | standard=True, |
| 145 | ext_modules=[ |
Armin Ronacher | a7804ef | 2007-06-15 18:03:21 +0200 | [diff] [blame] | 146 | Extension('jinja._speedups', ['jinja/_speedups.c']) |
| 147 | ] |
| 148 | ), |
| 149 | 'extended-debugger': Feature( |
| 150 | 'extended debugger', |
Armin Ronacher | 825e522 | 2007-11-16 16:16:23 +0100 | [diff] [blame] | 151 | standard=True, |
| 152 | ext_modules=[ |
Armin Ronacher | a7804ef | 2007-06-15 18:03:21 +0200 | [diff] [blame] | 153 | Extension('jinja._debugger', ['jinja/_debugger.c']) |
| 154 | ] |
| 155 | ) |
| 156 | }, |
Armin Ronacher | 015b0c9 | 2007-11-11 00:10:17 +0100 | [diff] [blame] | 157 | cmdclass={'build_ext': optional_build_ext} |
Armin Ronacher | de478f6 | 2007-02-28 22:35:04 +0100 | [diff] [blame] | 158 | ) |