Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for reading fragment tile titles from theme manifest
- Loading branch information
Showing
2 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
from ConfigParser import SafeConfigParser | ||
|
||
from plone.app.theming.interfaces import THEME_RESOURCE_NAME | ||
from plone.app.theming.plugins.utils import getPlugins | ||
from plone.resource.manifest import MANIFEST_FILENAME | ||
|
||
|
||
# This is copied from p.a.theming.plugins.utils to get uncached data | ||
# noinspection PyPep8Naming | ||
def getPluginSettings(themeDirectory, plugins=None): | ||
"""Given an IResourceDirectory for a theme, return the settings for the | ||
given list of plugins (or all plugins, if not given) provided as a list | ||
of (name, plugin) pairs. | ||
Returns a dict of dicts, with the outer dict having plugin names as keys | ||
and containing plugins settings (key/value pairs) as values. | ||
""" | ||
|
||
if plugins is None: | ||
plugins = getPlugins() | ||
|
||
# noinspection PyPep8Naming | ||
manifestContents = {} | ||
|
||
if themeDirectory.isFile(MANIFEST_FILENAME): | ||
parser = SafeConfigParser() | ||
fp = themeDirectory.openFile(MANIFEST_FILENAME) | ||
|
||
try: | ||
parser.readfp(fp) | ||
for section in parser.sections(): | ||
manifestContents[section] = {} | ||
|
||
for name, value in parser.items(section): | ||
manifestContents[section][name] = value | ||
|
||
finally: | ||
try: | ||
fp.close() | ||
except AttributeError: | ||
pass | ||
|
||
pluginSettings = {} | ||
for name, plugin in plugins: | ||
pluginSettings[name] = manifestContents.get("%s:%s" % (THEME_RESOURCE_NAME, name), {}) # noqa | ||
|
||
return pluginSettings |