Skip to content

Commit

Permalink
Wrap all tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Sep 10, 2018
1 parent ae446ef commit 371029d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ report.html
!.travis.yml
!src/collective
.*.cfg
.Python
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
- PLONE_VERSION=5.0
- PLONE_VERSION=5.1
before_install:
- pip install -r https://raw.githubusercontent.com/plone/buildout.coredev/5.1/requirements.txt
- pip install -r requirements.txt
install:
- sed -ie "s#test-5.1#test-$PLONE_VERSION#" buildout.cfg
- buildout annotate
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.4 (unreleased)
----------------

- Nothing changed yet.
- Wrap tile so it works with newer versions of Mosaic
[tomgross]


1.3 (2018-04-26)
Expand Down
4 changes: 4 additions & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ flake8-debugger = 1.4.0
plone.testing = 5.0.0
coverage = 4.0.3
python-coveralls = 2.7.0
plone.recipe.zope2instance = 4.4.0
zc.recipe.egg = 2.0.6
setuptools = 33.1.1
zc.buildout = 2.12.2
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setuptools==33.1.1
zc.buildout==2.12.2
6 changes: 4 additions & 2 deletions src/collective/handlebars/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def translate(self, msgid, domain=None, mapping=None, context=None,
target_language=target_language)

def _wrap_widget(self, render):
if render and render.startswith(u'<html><body>'):
return render
return ''.join([u'<html><body>', render, u'</body></html>'])


Expand All @@ -156,7 +158,7 @@ def __call__(self, *args, **kwargs):
class HandlebarsTile(Tile, HandlebarsMixin):

def __call__(self, *args, **kwargs):
return self.hbs_snippet()
return self._wrap_widget(self.hbs_snippet())


# BBB
Expand All @@ -166,6 +168,6 @@ def __call__(self, *args, **kwargs):
class HandlebarsPersistentTile(PersistentTile, HandlebarsMixin):

def __call__(self, *args, **kwargs):
return self.hbs_snippet()
return self._wrap_widget(self.hbs_snippet())

# EOF
1 change: 1 addition & 0 deletions src/collective/handlebars/tests/data/body_tile.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><custom src="{{src}}" alt="{{alt}}" /></body></html>
31 changes: 25 additions & 6 deletions src/collective/handlebars/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ def test_get_contents_default(self):

def test_get_hbs_template(self):
template = self.tile._get_hbs_template(self.template_path)
self.assertEqual(template({'src': 'foo', 'alt': 'bar'}).strip(),
u'<img src="foo" alt="bar">')
self.assertEqual(
template({'src': 'foo', 'alt': 'bar'}).strip(),
u'<img src="foo" alt="bar">'
)

def test_get_partial_key(self):
self.assertEqual(self.tile._get_partial_key(self.template_path),
Expand All @@ -237,7 +239,19 @@ def test_call_notemplate(self):
def test_call_with_template(self):
tile = DummyHbsTile(self.layer['portal'], self.layer['request'])
setattr(tile, 'index', DummyHbsTemplate(self.template_path))
self.assertEqual(tile().strip(), u'<img src="foo" alt="bar">')
self.assertEqual(
normalize(tile()),
u'<html><body><img src="foo" alt="bar"> </body></html>'
)

def test_call_with_body_template(self):
template_path = os.path.join(TEST_DATA__DIR, 'body_tile.hbs')
tile = DummyHbsTile(self.layer['portal'], self.layer['request'])
setattr(tile, 'index', DummyHbsTemplate(template_path))
self.assertEqual(
tile().strip(),
u'<html><body><custom src="foo" alt="bar" /></body></html>'
)


class TestHandlebarPersistentTile(unittest.TestCase):
Expand All @@ -262,8 +276,10 @@ def test_get_contents_default(self):

def test_get_hbs_template(self):
template = self.tile._get_hbs_template(self.template_path)
self.assertEqual(template({'src': 'foo', 'alt': 'bar'}).strip(),
u'<img src="foo" alt="bar">')
self.assertEqual(
template({'src': 'foo', 'alt': 'bar'}).strip(),
u'<img src="foo" alt="bar">'
)

def test_get_partial_key(self):
self.assertEqual(self.tile._get_partial_key(self.template_path),
Expand All @@ -276,4 +292,7 @@ def test_call_notemplate(self):
def test_call_with_template(self):
tile = DummyHbsTile(self.layer['portal'], self.layer['request'])
setattr(tile, 'index', DummyHbsTemplate(self.template_path))
self.assertEqual(tile().strip(), u'<img src="foo" alt="bar">')
self.assertEqual(
normalize(tile()),
u'<html><body><img src="foo" alt="bar"> </body></html>'
)

0 comments on commit 371029d

Please sign in to comment.