Skip to content

Commit 0d8578f

Browse files
Merge pull request #2 from cusyio/features/ISSUE-1
Issue-1: Customizations for collective.behavior.banner
2 parents 0d081e0 + 65d987b commit 0d8578f

File tree

8 files changed

+176
-1
lines changed

8 files changed

+176
-1
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Changelog
55
1.0.0 (unreleased)
66
------------------
77

8+
- ISSUE-1: Customizations for collective.behavior.banner
89
- Initial release.

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"lineage.registry",
6262
"lineage.themeselection",
6363
"plone.restapi",
64+
"z3c.jbot",
6465
],
6566
extras_require={
6667
"test": [

src/cusy/cms/browser/configure.zcml

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
xmlns:plone="http://namespaces.plone.org/plone"
55
i18n_domain="cusy.cms">
66

7+
<!-- Set overrides folder for Just-a-Bunch-Of-Templates product -->
8+
<include package="z3c.jbot" file="meta.zcml" />
9+
<browser:jbot
10+
directory="overrides"
11+
layer="cusy.cms.interfaces.ICusyCmsLayer"
12+
/>
13+
714
<!-- Publish static files -->
815
<plone:static
916
name="cusy.cms"
@@ -12,7 +19,7 @@
1219
/>
1320

1421
<!-- Adjust permission to only show the subsite switcher for editors.
15-
22+
1623
This might be a custom permission at some point.
1724
-->
1825
<browser:viewlet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<tal:block
2+
tal:define="banner view/find_banner|nothing"
3+
i18n:domain="collective.behavior.banner">
4+
5+
<aside id="portal-banner" class="banner" aria-labelledby="portal-banner-title" aria-describedby="portal-banner-description"
6+
tal:condition="python: banner"
7+
tal:define="has_image python:banner and 'banner_image' in banner;
8+
has_url python:banner and 'banner_url' in banner;
9+
has_fontcolor python:banner and 'banner_fontcolor' in banner;
10+
fontcolor python:has_fontcolor and banner['banner_fontcolor'] + ' !important' or '#4d4d4d';
11+
has_backgroundcolor python:banner and 'banner_backgroundcolor' in banner;
12+
backgroundcolor python:has_backgroundcolor and 'background:' + banner['banner_backgroundcolor'] + ' !important' or ''"
13+
tal:attributes="style backgroundcolor;">
14+
<div class="container">
15+
<div class="banner__container"
16+
tal:attributes="class python:'banner__container' if has_image else 'banner__container banner__container--no-image'">
17+
<picture class="banner__image-content"
18+
tal:condition="python:has_image"
19+
tal:define="banner_obj python: banner['banner_obj'];
20+
scales banner_obj/@@images;">
21+
<tal:sources tal:repeat="scale python: ['banner_lg', 'banner_md', 'banner_sm', 'banner_xs']">
22+
<source srcset="" media=""
23+
tal:define="srcset python: scales.scale('banner_image', scale=scale);
24+
srcset_attribute python: srcset.srcset_attribute();
25+
src_url python: srcset_attribute or srcset.url;
26+
dimensions python: scales.available_sizes.get(scale);
27+
width python: dimensions and dimensions[0] or None;"
28+
tal:condition="src_url"
29+
tal:attributes="srcset src_url;
30+
media python: '(min-width: {0}px)'.format(width)">
31+
</tal:sources>
32+
<img class="banner__image" src="" alt=""
33+
tal:replace="structure python:scales.tag('banner_image', scale=view.banner_scale(), css_class='banner__image', alt=banner['banner_alt'], title=None)" />
34+
</picture>
35+
36+
<div class="banner__video-content"
37+
tal:condition="python:has_url and not has_image">
38+
<embed
39+
tal:define="url banner/banner_url"
40+
tal:replace="structure python:view.getVideoEmbedMarkup(url)">Embed code</embed>
41+
</div>
42+
43+
<div class="banner__text-content">
44+
<p class="banner__title" id="portal-banner-title"
45+
tal:attributes="style string:color:${fontcolor}"
46+
tal:condition="python:'banner_title' in banner"
47+
tal:content="banner/banner_title">Title</p>
48+
49+
<p class="banner__description" id="portal-banner-description"
50+
tal:attributes="style string:color:${fontcolor}"
51+
tal:condition="python:'banner_description' in banner"
52+
tal:content="banner/banner_description">Description</p>
53+
54+
<p class="banner__link"
55+
tal:attributes="style string:color:${fontcolor}"
56+
tal:condition="python: 'banner_link' in banner">
57+
<a class="context" href=""
58+
tal:attributes="href banner/banner_link"
59+
tal:content="banner/banner_linktext">Link</a>
60+
</p>
61+
62+
<div class="banner__text"
63+
tal:attributes="style string:color:${fontcolor}"
64+
tal:condition="python:'banner_text' in banner"
65+
tal:content="structure banner/banner_text">Text</div>
66+
</div>
67+
</div>
68+
</div>
69+
</aside>
70+
<style>
71+
.banner__image {
72+
max-width: 100%;
73+
height: auto;
74+
position: relative;
75+
display: block;
76+
margin: 0 auto;
77+
width: 100%;
78+
}
79+
80+
.banner__title {
81+
font-size: 3em;
82+
}
83+
</style>
84+
</tal:block>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<registry>
3+
<!-- Please see registry/imaging.xml for the banner_scale setting. -->
4+
</registry>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<registry>
3+
<record name="plone.allowed_sizes">
4+
<value purge="False">
5+
<element>banner_xs 640:360</element>
6+
<element>banner_sm 960:540</element>
7+
<element>banner_md 1280:720</element>
8+
<element>banner_lg 1600:900</element>
9+
</value>
10+
</record>
11+
12+
<!-- Setting for collective.behavior.banner.
13+
14+
Needs to be placed here because of the dependency to the new scale defined in
15+
plone.allowed_sizes above.
16+
17+
All other settings regarding collective.behavior.banner are placed in registry/banner.xml.
18+
-->
19+
<record name="collective.behavior.banner.browser.controlpanel.IBannerSettingsSchema.banner_scale">
20+
<value>banner_md</value>
21+
</record>
22+
</registry>
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
"""Test banner settings."""
3+
4+
from cusy.cms import testing
5+
6+
import plone.api
7+
import unittest
8+
9+
10+
class TestBannerSettings(unittest.TestCase):
11+
"""Validate banner settings."""
12+
13+
layer = testing.INTEGRATION_TESTING
14+
15+
def setUp(self):
16+
"""Additional test setup."""
17+
self.portal = self.layer["portal"]
18+
19+
def test_banner_scale(self):
20+
"""Validate the 'banner_scale' setting."""
21+
setting = plone.api.portal.get_registry_record(
22+
"collective.behavior.banner.browser.controlpanel.IBannerSettingsSchema.banner_scale",
23+
)
24+
self.assertEqual(setting, "banner_md")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding: utf-8 -*-
2+
"""Test imaging settings."""
3+
4+
from cusy.cms import testing
5+
6+
import plone.api
7+
import unittest
8+
9+
10+
class TestImagingSettings(unittest.TestCase):
11+
"""Validate imaging settings."""
12+
13+
layer = testing.INTEGRATION_TESTING
14+
15+
def setUp(self):
16+
"""Additional test setup."""
17+
self.portal = self.layer["portal"]
18+
19+
def test_allowed_sizes(self):
20+
"""Validate the 'allowed_sizes' setting."""
21+
setting = plone.api.portal.get_registry_record(
22+
"plone.allowed_sizes",
23+
)
24+
expected = [
25+
"banner_xs 640:360",
26+
"banner_sm 960:540",
27+
"banner_md 1280:720",
28+
"banner_lg 1600:900",
29+
]
30+
for item in expected:
31+
self.assertIn(item, setting)
32+
self.assertTrue(len(setting) >= len(expected))

0 commit comments

Comments
 (0)