Exemplo n.º 1
0
def getTheme(name, manifest=None, resources=None):
    if manifest is None:
        if resources is None:
            resources = getAllResources(
                MANIFEST_FORMAT,
                filter=isValidThemeDirectory
            )
        if name not in resources:
            return None
        manifest = resources[name] or {}

    title = manifest.get('title', None)
    if title is None:
        title = name.capitalize().replace('-', ' ').replace('.', ' ')
    description = manifest.get('description', None)
    rules = manifest.get('rules', None)
    if rules is None:
        rules = u"/++{0:s}++{1:s}/{2:s}".format(
            THEME_RESOURCE_NAME,
            name,
            RULE_FILENAME,
        )
    prefix = manifest.get('prefix', None)
    if prefix is None:
        prefix = u"/++{0:s}++{1:s}".format(THEME_RESOURCE_NAME, name)
    params = manifest.get('parameters', None) or {}
    doctype = manifest.get('doctype', None) or ""
    preview = manifest.get('preview', None)
    enabled_bundles = manifest.get('enabled-bundles', None) or ''
    enabled_bundles = enabled_bundles.split(',') if enabled_bundles else []
    disabled_bundles = manifest.get('disabled-bundles', None) or ''
    disabled_bundles = disabled_bundles.split(',') if disabled_bundles else []
    development_css = manifest.get('development-css', None) or ''
    development_js = manifest.get('development-js', None) or ''
    production_css = manifest.get('production-css', None) or ''
    production_js = manifest.get('production-js', None) or ''
    tinymce_content_css = manifest.get('tinymce-content-css', None) or ''
    tinymce_styles_css = manifest.get('tinymce-styles-css', None) or ''
    if isinstance(rules, str):
        rules = rules.decode('utf-8')
    if isinstance(prefix, str):
        prefix = prefix.decode('utf-8')
    return Theme(
        name,
        rules,
        title=title,
        description=description,
        absolutePrefix=prefix,
        parameterExpressions=params,
        doctype=doctype,
        preview=preview,
        enabled_bundles=enabled_bundles,
        disabled_bundles=disabled_bundles,
        development_css=development_css,
        development_js=development_js,
        production_css=production_css,
        production_js=production_js,
        tinymce_content_css=tinymce_content_css,
        tinymce_styles_css=tinymce_styles_css
    )
Exemplo n.º 2
0
def extractThemeInfo(zipfile, checkRules=True):
    """Return an ITheme based on the information in the given zipfile.

    Will throw a ValueError if the theme directory does not contain a single
    top level directory or the rules file cannot be found.

    Set checkRules=False to disable the rules check.
    """

    resourceName, manifestDict = extractManifestFromZipFile(
        zipfile, MANIFEST_FORMAT)

    rulesFile = None
    absolutePrefix = '/++%s++%s' % (THEME_RESOURCE_NAME, resourceName)
    title = None
    description = None
    parameters = {}
    doctype = ""
    preview = None

    if manifestDict is not None:
        rulesFile = manifestDict.get('rules', rulesFile)
        absolutePrefix = manifestDict['prefix'] or absolutePrefix
        title = manifestDict.get('title', None)
        description = manifestDict.get('title', None)
        parameters = manifestDict.get('parameters', {})
        doctype = manifestDict.get('doctype', "")
        preview = manifestDict.get('preview', None)

    if not rulesFile:
        if checkRules:
            try:
                zipfile.getinfo("%s/%s" % (
                    resourceName,
                    RULE_FILENAME,
                ))
            except KeyError:
                raise ValueError("Could not find theme name and rules file")
        rulesFile = u"/++%s++%s/%s" % (
            THEME_RESOURCE_NAME,
            resourceName,
            RULE_FILENAME,
        )

    return Theme(
        resourceName,
        rulesFile,
        title=title,
        description=description,
        absolutePrefix=absolutePrefix,
        parameterExpressions=parameters,
        doctype=doctype,
        preview=preview,
    )
Exemplo n.º 3
0
def getTheme(name, manifest=None, resources=None):
    if manifest is None:
        if resources is None:
            resources = getAllResources(MANIFEST_FORMAT,
                                        filter=isValidThemeDirectory)
        if name not in resources:
            return None
        manifest = resources[name]
    title = name.capitalize().replace('-', ' ').replace('.', ' ')
    description = None
    rules = u"/++%s++%s/%s" % (
        THEME_RESOURCE_NAME,
        name,
        RULE_FILENAME,
    )
    prefix = u"/++%s++%s" % (
        THEME_RESOURCE_NAME,
        name,
    )
    params = {}
    doctype = ""
    preview = None

    if manifest is not None:
        title = manifest['title'] or title
        description = manifest['description'] or description
        rules = manifest['rules'] or rules
        prefix = manifest['prefix'] or prefix
        params = manifest['parameters'] or params
        doctype = manifest['doctype'] or doctype
        preview = manifest['preview'] or preview

    if isinstance(rules, str):
        rules = rules.decode('utf-8')
    if isinstance(prefix, str):
        prefix = prefix.decode('utf-8')

    return Theme(
        name,
        rules,
        title=title,
        description=description,
        absolutePrefix=prefix,
        parameterExpressions=params,
        doctype=doctype,
        preview=preview,
    )
Exemplo n.º 4
0
def getThemeFromResourceDirectory(resourceDirectory):
    """Return a Theme object from a resource directory
    """

    name = resourceDirectory.__name__

    title = name.capitalize().replace('-', ' ').replace('.', ' ')
    description = None
    rules = u"/++%s++%s/%s" % (
        THEME_RESOURCE_NAME,
        name,
        RULE_FILENAME,
    )
    prefix = u"/++%s++%s" % (
        THEME_RESOURCE_NAME,
        name,
    )
    params = {}
    doctype = ""

    if resourceDirectory.isFile(MANIFEST_FILENAME):
        manifest = getManifest(resourceDirectory.openFile(MANIFEST_FILENAME),
                               MANIFEST_FORMAT)

        title = manifest['title'] or title
        description = manifest['description'] or description
        rules = manifest['rules'] or rules
        prefix = manifest['prefix'] or prefix
        params = manifest['parameters'] or params
        doctype = manifest['doctype'] or doctype

    if isinstance(rules, str):
        rules = rules.decode('utf-8')
    if isinstance(prefix, str):
        prefix = prefix.decode('utf-8')

    return Theme(
        name,
        rules,
        title=title,
        description=description,
        absolutePrefix=prefix,
        parameterExpressions=params,
        doctype=doctype,
    )