diff --git a/.gitignore b/.gitignore index efc9d26..0bcbf6a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ report.html !.travis.yml !src/collective .*.cfg +.Python diff --git a/.travis.yml b/.travis.yml index 155668e..abf4678 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGES.rst b/CHANGES.rst index 278f8d5..431a1cb 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) diff --git a/buildout.cfg b/buildout.cfg index 238bf72..7a1426d 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c16b9b0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +setuptools==33.1.1 +zc.buildout==2.12.2 diff --git a/src/collective/handlebars/browser/views.py b/src/collective/handlebars/browser/views.py index 79e9461..771c278 100644 --- a/src/collective/handlebars/browser/views.py +++ b/src/collective/handlebars/browser/views.py @@ -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''): + return render return ''.join([u'', render, u'']) @@ -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 @@ -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 diff --git a/src/collective/handlebars/tests/data/body_tile.hbs b/src/collective/handlebars/tests/data/body_tile.hbs new file mode 100644 index 0000000..8505b08 --- /dev/null +++ b/src/collective/handlebars/tests/data/body_tile.hbs @@ -0,0 +1 @@ + diff --git a/src/collective/handlebars/tests/test_views.py b/src/collective/handlebars/tests/test_views.py index abdfaac..7f2c1f2 100644 --- a/src/collective/handlebars/tests/test_views.py +++ b/src/collective/handlebars/tests/test_views.py @@ -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'bar') + self.assertEqual( + template({'src': 'foo', 'alt': 'bar'}).strip(), + u'bar' + ) def test_get_partial_key(self): self.assertEqual(self.tile._get_partial_key(self.template_path), @@ -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'bar') + self.assertEqual( + normalize(tile()), + u'bar ' + ) + + 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'' + ) class TestHandlebarPersistentTile(unittest.TestCase): @@ -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'bar') + self.assertEqual( + template({'src': 'foo', 'alt': 'bar'}).strip(), + u'bar' + ) def test_get_partial_key(self): self.assertEqual(self.tile._get_partial_key(self.template_path), @@ -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'bar') + self.assertEqual( + normalize(tile()), + u'bar ' + )