Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve iconsresolver for mockup usage #3368

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Products/CMFPlone/browser/icons.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# -*- coding: utf-8 -*-
from lxml import etree
from OFS.Image import File
from plone.registry.interfaces import IRegistry
from Products.Five.browser import BrowserView
from Products.CMFCore.interfaces import ISiteRoot
from zExceptions import NotFound
from zope.component import adapter
from zope.component import getUtility
from zope.component.hooks import getSite
from zope.interface import implementer
from zope.interface import Interface
from zope.location.interfaces import LocationError
from zope.traversing.interfaces import ITraversable
from zope.publisher.interfaces import IPublishTraverse
from zExceptions import NotFound

Expand Down Expand Up @@ -58,21 +52,39 @@ def _strip_id(svgtree, cfg):

SVG_MODIFER['strip_id'] = _strip_id


@implementer(IPublishTraverse)
class IconsView(BrowserView):

prefix = "plone.icon."
defaulticon = "++plone++icons/plone.svg"

def publishTraverse(self, request, name):
self.name = name
def publishTraverse(self, request, part):
"""Subpath detection

- "@@iconsresolver/plone-copy" delivers the file.
- "@@iconsresolver/get_file/plone-copy" delivers the file too.
- "@@iconsresolver/get_url/plone-copy" delivers url to the file.
- "@@iconsresolver/get_tag/plone-copy" delivers image tag or the SVG data.
- "@@iconsresolver/get_tag/plone-copy?class=my-css-info&alt=Plone-Copy-Icon" delivers image tag or the SVG data.
"""
breakpoint()
jensens marked this conversation as resolved.
Show resolved Hide resolved
variety = getattr(self, "variety", None)
if variety is None and part in ["get_tag", 'get_url', 'get_file']:
self.variety = part
return self
if variety is None:
self.variety = "get_file"
self.name = part
return self

def __call__(self):
name = getattr(self, "name", None)
if name is None:
raise NotFound("No name were given as subpath.")
if self.variety == "get_tag":
return self.tag(self.name, tag_class=self.request.get("class", ""), tag_alt=self.request.get("alt", ""))
elif self.variety == "get_url":
return self.url(self.name)
fileobj = self._iconfile(self.lookup(self.name))
return fileobj(REQUEST=self.request, RESPONSE=self.request.response)

Expand Down