Skip to content

Commit

Permalink
rewrite manifest from copied theme with relative paths also
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Sep 11, 2015
1 parent ee82bff commit aab9939
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
1.2.11 (unreleased)
-------------------

- Nothing changed yet.
- rewrite manifest from copied theme with relative paths also
[vangheem]


1.2.10 (2015-09-08)
Expand Down
17 changes: 17 additions & 0 deletions src/plone/app/theming/tests/another-theme/manifest.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[theme]
title = Another test theme
description = Another theme for testing
doctype = <!DOCTYPE html>
prefix = ++theme++another-test-theme
rules = ++theme++another-test-theme/rules.xml

enabled-bundles = plone
disabled-bundles = foobar

development-css = ++theme++another-theme/less/barceloneta.plone.less
production-css = ++theme++another-theme/less/barceloneta-compiled.css
tinymce-content-css = ++theme++another-theme/less/barceloneta-compiled.css

development-js = ++theme++another-theme/script.js
production-js = ++theme++another-theme/script.min.js

7 changes: 7 additions & 0 deletions src/plone/app/theming/tests/another-theme/rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<rules
xmlns="http://namespaces.plone.org/diazo"
xmlns:css="http://namespaces.plone.org/diazo/css"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

</rules>
1 change: 1 addition & 0 deletions src/plone/app/theming/tests/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<plone:static directory="resources" type="theme" />
<plone:static directory="secondary-theme" name="secondary-theme" type="theme" />
<plone:static directory="another-theme" name="another-theme" type="theme" />

<browser:page
for="*"
Expand Down
43 changes: 43 additions & 0 deletions src/plone/app/theming/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,49 @@ def test_createThemeFromTemplate_custom_prefix(self):
self.assertEqual(theme.development_js, expected_dev_js)
self.assertEqual(theme.production_js, expected_prod_js)

def test_createThemeFromTemplate_rel_path(self):
from plone.app.theming.utils import createThemeFromTemplate
from plone.app.theming.utils import getAvailableThemes
from plone.app.theming.utils import getTheme
from plone.app.theming.interfaces import THEME_RESOURCE_NAME
from plone.app.theming.interfaces import RULE_FILENAME
title = "copy of test theme with custom prefix"
description = "test theme creation"
themeName = createThemeFromTemplate(title, description,
baseOn="another-theme")
titles = [theme.title for theme in getAvailableThemes()]
self.assertTrue(title in titles)

theme = getTheme(themeName)
expected_prefix = u"/++%s++%s" % (THEME_RESOURCE_NAME,
title.replace(" ", "-"))
self.assertEqual(theme.absolutePrefix, expected_prefix)

expected_rules = u"/++%s++%s/%s" % (THEME_RESOURCE_NAME,
title.replace(" ", "-"),
RULE_FILENAME)
self.assertEqual(theme.rules, expected_rules)

self.assertEqual(theme.enabled_bundles, ['plone'])
self.assertEqual(theme.disabled_bundles, ['foobar'])

expected_dev_css = u"++%s++%s/less/barceloneta.plone.less" % (
THEME_RESOURCE_NAME, title.replace(" ", "-"))
expected_prod_css = u"++%s++%s/less/barceloneta-compiled.css" % (
THEME_RESOURCE_NAME, title.replace(" ", "-"))
expected_tinymce = u"++%s++%s/less/barceloneta-compiled.css" % (
THEME_RESOURCE_NAME, title.replace(" ", "-"))
self.assertEqual(theme.development_css, expected_dev_css)
self.assertEqual(theme.production_css, expected_prod_css)
self.assertEqual(theme.tinymce_content_css, expected_tinymce)

expected_dev_js = u"++%s++%s/script.js" % (
THEME_RESOURCE_NAME, title.replace(" ", "-"))
expected_prod_js = u"++%s++%s/script.min.js" % (
THEME_RESOURCE_NAME, title.replace(" ", "-"))
self.assertEqual(theme.development_js, expected_dev_js)
self.assertEqual(theme.production_js, expected_prod_js)


class TestUnit(unittest.TestCase):

Expand Down
6 changes: 3 additions & 3 deletions src/plone/app/theming/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ def createThemeFromTemplate(title, description, baseOn='template'):
val = manifest.get('theme', var_path)
if not val:
continue
template_prefix = '/++%s++%s/' % (THEME_RESOURCE_NAME, baseOn)
if val.startswith(template_prefix):
template_prefix = '++%s++%s/' % (THEME_RESOURCE_NAME, baseOn)
if template_prefix in val:
# okay, fix
val = val.replace(template_prefix, '/++%s++%s/' % (THEME_RESOURCE_NAME, themeName))
val = val.replace(template_prefix, '++%s++%s/' % (THEME_RESOURCE_NAME, themeName))
manifest.set('theme', var_path, val)

manifestContents = StringIO()
Expand Down

0 comments on commit aab9939

Please sign in to comment.