Skip to content

Commit

Permalink
Clean up and refactor
Browse files Browse the repository at this point in the history
- move static directory inside browser module
- update tests
  • Loading branch information
hvelarde committed Sep 6, 2018
1 parent 03446c8 commit ff89815
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/collective/lazysizes/browser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
from collective.lazysizes.config import JS
from plone.app.layout.viewlets import ViewletBase


class ResourcesViewlet(ViewletBase):
"""This viewlet inserts static resources on page header."""

def js(self):
return self.site_url + '/' + JS
8 changes: 7 additions & 1 deletion src/collective/lazysizes/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="collective.lazysizes">

<browser:resourceDirectory
name="collective.lazysizes"
directory="static"
layer="collective.lazysizes.interfaces.ILazySizesLayer"
/>

<browser:viewlet
name="collective.lazysizes.resources"
manager="plone.app.layout.viewlets.interfaces.IHtmlHead"
class=".ResourcesViewlet"
template="../static/resources.pt"
template="static/resources.pt"
permission="zope2.Public"
/>

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions src/collective/lazysizes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

PROJECTNAME = 'collective.lazysizes'

JS = '++resource++collective.lazysizes/lazysizes.js'

IS_PLONE_5 = api.env.plone_version().startswith('5')
6 changes: 0 additions & 6 deletions src/collective/lazysizes/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
permission="collective.lazysizes.Setup"
/>

<browser:resourceDirectory
name="collective.lazysizes"
directory="static"
layer="collective.lazysizes.interfaces.ILazySizesLayer"
/>

<adapter
for="* .interfaces.ILazySizesLayer"
name="collective.lazysizes"
Expand Down
7 changes: 3 additions & 4 deletions src/collective/lazysizes/tests/test_resources_viewlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def get_viewlet(self, context, name='collective.lazysizes.resources'):
return viewlet[0]

def test_viewlet(self):
from collective.lazysizes.config import JS
html = etree.HTML(self.viewlet())
self.assertIn('async', html.xpath('//script')[0].attrib)
self.assertTrue(
html.xpath('//script')[0].attrib['src'],
'http://nohost/plone/' + JS)
regexp = r'lazysizes-[\da-f]{7}\.js$'
self.assertRegexpMatches(
html.xpath('//script')[0].attrib['src'], regexp)
4 changes: 2 additions & 2 deletions webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const gitCmd = 'git rev-list -1 HEAD --abbrev-commit $(pwd)'
const gitHash = childProcess.execSync(gitCmd).toString().substring(0, 7);

// clean up old resources
const path = `${__dirname}/../src/collective/lazysizes/static`
childProcess.execSync(`rm -f ${path}/lazysizes*`);
const path = `${__dirname}/../src/collective/lazysizes/browser/static`
childProcess.execSync(`rm -f ${path}/lazysizes-*`);

module.exports = {
entry: [
Expand Down

0 comments on commit ff89815

Please sign in to comment.