Ejemplo n.º 1
0
def use_amd_version(setup_tool):
    """Use AMD version of Lazysizes."""
    if IS_PLONE_5:
        return  # upgrade step not supported under Plone 5

    portal_js = api.portal.get_tool('portal_javascripts')
    if OLD_JS in portal_js.getResourceIds():
        portal_js.renameResource(OLD_JS, NEW_JS)
        assert NEW_JS in portal_js.getResourceIds()
        logger.info('lazysizes was upgraded; using now the AMD module')
Ejemplo n.º 2
0
def use_amd_version(setup_tool):
    """Use AMD version of Lazysizes."""
    if IS_PLONE_5:
        return  # upgrade step not supported under Plone 5

    portal_js = api.portal.get_tool('portal_javascripts')
    if OLD_JS in portal_js.getResourceIds():
        portal_js.renameResource(OLD_JS, NEW_JS)
        assert NEW_JS in portal_js.getResourceIds()
        logger.info('lazysizes was upgraded; using now the AMD module')
Ejemplo n.º 3
0
def remove_respimg_polyfill(setup_tool):
    """Remove respimg polyfill plugin."""
    if IS_PLONE_5:
        record = 'plone.bundles/plone-legacy.resources'
        resources = api.portal.get_registry_record(record)
        id_ = 'resource-collective-lazysizes-ls-respimg-min-js'
        if id_ in resources:
            resources.remove(id_)
            api.portal.set_registry_record(record, resources)
            assert id_ not in api.portal.get_registry_record(record)  # nosec

    # we run this code in Plone 5 also "just in case"
    portal_js = api.portal.get_tool('portal_javascripts')
    if JS in portal_js.getResourceIds():
        portal_js.unregisterResource(JS)
        assert JS not in portal_js.getResourceIds()  # nosec
        logger.info('respimg polyfill plugin was removed')
Ejemplo n.º 4
0
def use_amd_version(setup_tool):
    """Use AMD version of Lazysizes."""
    if IS_PLONE_5:
        logger.warn('Upgrade step not supported under Plone 5')
        return

    portal_js = api.portal.get_tool('portal_javascripts')
    resource_ids = portal_js.getResourceIds()
    if OLD_JS in resource_ids:
        # XXX: https://github.com/collective/collective.lazysizes/issues/46
        if NEW_JS not in resource_ids:
            # profile version 4: not registered, rename the script
            portal_js.renameResource(OLD_JS, NEW_JS)
        else:
            # earlier version: already registered, remove the old script
            portal_js.unregisterResource(OLD_JS)
        logger.info('lazysizes was upgraded; using now the AMD module')

    assert OLD_JS not in portal_js.getResourceIds()  # nosec
    assert NEW_JS in portal_js.getResourceIds()  # nosec
Ejemplo n.º 5
0
def cook_javascript_resources(context):  # pragma: no cover
    """Cook JavaScripts resources."""
    js_tool = api.portal.get_tool('portal_javascripts')
    js_tool.cookResources()
    logger.info('JavaScripts resources were cooked')