cybertools/ajax/dojo/layout.py
helmutm e2e8370cf4 provide embedding of JavaScript, esp. Dojo
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3023 fd906abe-77d9-0310-91a1-e0d9ade77398
2008-12-02 12:41:01 +00:00

53 lines
1.8 KiB
Python

#
# Copyright (c) 2008 Helmut Merz - helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Embed Dojo using the cybertools.composer.layout procedure.
$Id$
"""
from cStringIO import StringIO
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
from cybertools.browser.renderer import RendererFactory
from cybertools.composer.layout.base import Layout, LayoutInstance
dojoRenderers = RendererFactory(ViewPageTemplateFile('macros.pt'))
dojo = Layout('js.dojo', 'page.js', renderer=dojoRenderers.dojo,
instanceName='dojo', order=0)
dojoRequire = Layout('js.dojo.require', 'page.js',
renderer=dojoRenderers.dojo_require,
instanceName='dojo', order=50)
class DojoLayoutInstance(LayoutInstance):
djConfig = "parseOnLoad: true, usePlainJson: true, locale: 'de'"
@Lazy
def content(self):
djInfo = self.view.request.annotations.get('ajax.dojo', {})
packages = djInfo.get('requirements', set())
out = StringIO()
for p in packages:
out.write('dojo.require(%s); ' % p)
return out.getvalue()