provide embedding of JavaScript, esp. Dojo
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3023 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
4fe222a015
commit
e2e8370cf4
6 changed files with 127 additions and 12 deletions
|
@ -1,24 +1,42 @@
|
|||
<!-- $Id$ -->
|
||||
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/browser"
|
||||
xmlns:zope="http://namespaces.zope.org/zope"
|
||||
i18n_domain="zope">
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
xmlns:zope="http://namespaces.zope.org/zope">
|
||||
|
||||
<resourceDirectory name="ajax.dojo" directory="dojo" />
|
||||
<!-- resources -->
|
||||
|
||||
<page
|
||||
<browser:resourceDirectory name="ajax.dojo" directory="dojo" />
|
||||
|
||||
<!-- layouts -->
|
||||
|
||||
<zope:utility
|
||||
component="cybertools.ajax.dojo.layout.dojo"
|
||||
provides="cybertools.composer.layout.interfaces.ILayout"
|
||||
name="js.dojo" />
|
||||
|
||||
<zope:utility
|
||||
component="cybertools.ajax.dojo.layout.dojoRequire"
|
||||
provides="cybertools.composer.layout.interfaces.ILayout"
|
||||
name="js.dojo.require" />
|
||||
|
||||
<zope:adapter
|
||||
for="*"
|
||||
name="dojo"
|
||||
factory="cybertools.ajax.dojo.layout.DojoLayoutInstance" />
|
||||
|
||||
<!-- views -->
|
||||
|
||||
<browser:page
|
||||
for="*"
|
||||
name="ajax.dojo"
|
||||
template="macros.pt"
|
||||
permission="zope.Public"
|
||||
/>
|
||||
permission="zope.Public" />
|
||||
|
||||
<page
|
||||
<browser:page
|
||||
for="*"
|
||||
name="ajax.inner.html"
|
||||
template="../innerHtml.pt"
|
||||
permission="zope.ManageContent"
|
||||
/>
|
||||
permission="zope.ManageContent" />
|
||||
|
||||
</configure>
|
||||
|
|
53
ajax/dojo/layout.py
Normal file
53
ajax/dojo/layout.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
# 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()
|
|
@ -1,8 +1,24 @@
|
|||
<metal:def define-macro="main">
|
||||
<!-- $Id$ -->
|
||||
|
||||
<metal:def define-macro="main">
|
||||
<script type="text/javascript" src="ajax.dojo/dojo.js"
|
||||
tal:attributes="src context/++resource++ajax.dojo/dojo/dojo.js;
|
||||
djConfig macro/djConfig|nothing">
|
||||
</script>
|
||||
|
||||
</metal:def>
|
||||
|
||||
|
||||
<metal:js define-macro="dojo">
|
||||
<script type="text/javascript"
|
||||
src="/@@/ajax.dojo/dojo/dojo.js"
|
||||
tal:attributes="djConfig view/context/djConfig|nothing">
|
||||
</script>
|
||||
</metal:js>
|
||||
|
||||
|
||||
<metal:js define-macro="dojo_require"
|
||||
tal:define="layout view/context/template">
|
||||
<script type="text/javascript" language="JavaScript"
|
||||
tal:content="view/context/content">
|
||||
</script>
|
||||
</metal:js>
|
||||
|
|
|
@ -206,6 +206,7 @@ class ICategory(Interface):
|
|||
shops = Attribute(u'The shops providing this category.')
|
||||
accessories = Attribute(u'Accessories for this category.')
|
||||
|
||||
|
||||
# customers
|
||||
|
||||
class ICustomer(Interface):
|
||||
|
|
|
@ -70,6 +70,13 @@ class Layout(Template):
|
|||
self.regionName = regionName
|
||||
for k, v in kw.items():
|
||||
setattr(self, k, v)
|
||||
#self.register()
|
||||
|
||||
def register(self):
|
||||
existing = component.queryUtility(ILayout, name=self.name)
|
||||
if existing:
|
||||
raise ValueError('Layout %s has already been registered.' % self.name)
|
||||
component.provideUtility(self, provides=ILayout, name=self.name)
|
||||
|
||||
|
||||
class LayoutInstance(object):
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
<metal:css use-macro="view/renderer" />
|
||||
</tal:css>
|
||||
|
||||
<tal:js repeat="view view/layouts/js">
|
||||
<metal:js use-macro="view/renderer" />
|
||||
</tal:js>
|
||||
|
||||
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"
|
||||
tal:attributes="href string:${view/page/resourceBase}${layout/favicon}" />
|
||||
|
||||
|
@ -37,6 +41,22 @@
|
|||
</metal:css>
|
||||
|
||||
|
||||
<metal:js define-macro="js"
|
||||
tal:define="layout view/context/template">
|
||||
<script type="text/javascript"
|
||||
tal:attributes="src string:${view/page/resourceBase}${layout/resource});">
|
||||
</script>
|
||||
</metal:js>
|
||||
|
||||
|
||||
<metal:js define-macro="js-execute"
|
||||
tal:define="layout view/context/template">
|
||||
<script type="text/javascript" language="JavaScript"
|
||||
tal:content="layout/content">
|
||||
</script>
|
||||
</metal:js>
|
||||
|
||||
|
||||
<metal:image define-macro="image"
|
||||
tal:define="layout view/context/template">
|
||||
<img tal:attributes="src string:${view/page/resourceBase}${layout/src};
|
||||
|
|
Loading…
Add table
Reference in a new issue