You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/12/15 18:37:07 UTC
[11/15] allura git commit: [#5940] ticket:880 Logo and global bav
improvements
[#5940] ticket:880 Logo and global bav improvements
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/e64ab157
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/e64ab157
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/e64ab157
Branch: refs/heads/master
Commit: e64ab157fd7398e944ab48d168e1014798cd8c37
Parents: c94bdf3
Author: DeV1doR <de...@ukr.net>
Authored: Thu Dec 10 15:03:49 2015 +0200
Committer: Heith Seewald <he...@gmail.com>
Committed: Tue Dec 15 11:35:41 2015 -0600
----------------------------------------------------------------------
Allura/allura/lib/app_globals.py | 26 +++++++----
.../templates/jinja_master/theme_macros.html | 2 +-
Allura/allura/tests/functional/test_nav.py | 49 ++++++++++++++++++--
Allura/development.ini | 5 +-
4 files changed, 66 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/e64ab157/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 6c0cf78..f7392cd 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -607,25 +607,33 @@ class Globals(object):
@LazyProperty
def nav_logo(self):
- if not config.get('logo', False):
- return False
- logo = json.loads(config.get('logo'))
- image_path = logo.get('image_path', False)
- if not image_path:
+ logo = dict(
+ redirect_link=config.get('logo.link', False),
+ image_path=config.get('logo.path', False),
+ image_width=config.get('logo.width', False),
+ image_height=config.get('logo.height', False)
+ )
+ if not logo['redirect_link']:
+ logo['redirect_link'] = '/'
+
+ if not logo['image_path']:
+ log.warning('Image path not set for nav_logo')
return False
+
allura_path = os.path.dirname(os.path.dirname(__file__))
image_full_path = '%s/public/nf/images/%s' % (
- allura_path, image_path)
+ allura_path, logo['image_path'])
if not os.path.isfile(image_full_path):
+ log.warning('Could not find logo at: %s' % image_full_path)
return False
- if not logo.get('redirect_link', False):
- logo['redirect_link'] = '/'
path = 'images/%s' % logo['image_path']
return {
"image_path": self.forge_static(path),
- "redirect_link": logo['redirect_link']
+ "redirect_link": logo['redirect_link'],
+ "image_width": logo['image_width'],
+ "image_height": logo['image_height']
}
http://git-wip-us.apache.org/repos/asf/allura/blob/e64ab157/Allura/allura/templates/jinja_master/theme_macros.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/theme_macros.html b/Allura/allura/templates/jinja_master/theme_macros.html
index 2ca9fd5..25c3eb5 100644
--- a/Allura/allura/templates/jinja_master/theme_macros.html
+++ b/Allura/allura/templates/jinja_master/theme_macros.html
@@ -29,7 +29,7 @@ http://stackoverflow.com/questions/26582731/redefining-imported-jinja-macros
<div class="wrapper">
<div class="nav-logo">
{% if g.nav_logo %}
- <a class="link-left" href="{{ g.nav_logo['redirect_link'] }}"><img class="nav-logo" src="{{ g.nav_logo['image_path'] }}" /></a>
+ <a class="link-left" href="{{ g.nav_logo['redirect_link'] }}"><img class="nav-logo" style="{% if g.nav_logo['image_width'] %}width: {{g.nav_logo['image_width']}}px;{% endif %} {% if g.nav_logo['image_height'] %}height: {{ g.nav_logo['image_height'] }}px;{% endif %}" src="{{ g.nav_logo['image_path'] }}" /></a>
{% endif %}
</div>
<nav class="nav-left">
http://git-wip-us.apache.org/repos/asf/allura/blob/e64ab157/Allura/allura/tests/functional/test_nav.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_nav.py b/Allura/allura/tests/functional/test_nav.py
index a0fe530..78d8aa6 100644
--- a/Allura/allura/tests/functional/test_nav.py
+++ b/Allura/allura/tests/functional/test_nav.py
@@ -21,14 +21,19 @@ class TestNavigation(TestController):
self.nav_data = {
"title": "Link Test", "url": "http://example.com"}
self.logo_data = {
- "redirect_link": "/", "image_path": "test_image.png"}
+ "link": "/", "path": "test_image.png"}
+ self.width = 'width: %spx;'
+ self.height = 'height: %spx;'
g._Globals__shared_state.pop('global_nav', None)
g._Globals__shared_state.pop('nav_logo', None)
def _set_config(self):
return {
"global_nav": json.dumps([self.nav_data]),
- "logo": json.dumps(self.logo_data)
+ "logo.link": self.logo_data['link'],
+ "logo.path": self.logo_data['path'],
+ "logo.width": self.logo_data.get('width', ''),
+ "logo.height": self.logo_data.get('height', '')
}
def test_global_nav_links_present(self):
@@ -54,18 +59,52 @@ class TestNavigation(TestController):
def test_logo_present(self):
self.logo_data = {
- "redirect_link": "/", "image_path": "user.png"}
+ "link": "/", "path": "user.png"}
with h.push_config(config, **self._set_config()):
response = self.app.get('/')
nav_logo = response.html.find(*self.logo_pattern)
assert len(nav_logo.findAll('a')) == 1
- assert self.logo_data['image_path'] in nav_logo.a.img.get('src')
+ assert self.logo_data['path'] in nav_logo.a.img.get('src')
def test_logo_no_redirect_url_set_default(self):
self.logo_data = {
- "redirect_link": "", "image_path": "user.png"}
+ "link": "", "path": "user.png"}
with h.push_config(config, **self._set_config()):
response = self.app.get('/')
nav_logo = response.html.find(*self.logo_pattern)
assert len(nav_logo.findAll('a')) == 1
assert nav_logo.a.get('href') == '/'
+
+ def test_logo_image_width_and_height(self):
+ self.logo_data = {
+ "link": "", "path": "user.png",
+ "width": 20, "height": 20}
+ with h.push_config(config, **self._set_config()):
+ response = self.app.get('/')
+ nav_logo = response.html.find(*self.logo_pattern)
+ width = self.width % self.logo_data["width"]
+ height = self.height % self.logo_data["height"]
+ assert nav_logo.find(
+ 'img', style='%s %s' % (width, height)) is not None
+
+ def test_missing_logo_width(self):
+ self.logo_data = {
+ "link": "", "path": "user.png",
+ "height": 20}
+ with h.push_config(config, **self._set_config()):
+ response = self.app.get('/')
+ nav_logo = response.html.find(*self.logo_pattern)
+ height = self.height % self.logo_data["height"]
+ assert nav_logo.find(
+ 'img', style=' %s' % height) is not None
+
+ def test_missing_logo_height(self):
+ self.logo_data = {
+ "link": "/", "path": "user.png",
+ "width": 20}
+ with h.push_config(config, **self._set_config()):
+ response = self.app.get('/')
+ nav_logo = response.html.find(*self.logo_pattern)
+ width = self.width % self.logo_data["width"]
+ assert nav_logo.find(
+ 'img', style='%s ' % width) is not None
http://git-wip-us.apache.org/repos/asf/allura/blob/e64ab157/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index d9273bd..203428e 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -89,7 +89,10 @@ forgemail.url = http://localhost:8080
; Example: ../<static_path>/images/<logo_path>
; In default configuration you can place images under
; `Allura/allura/public/nf/images/` and specify file name below
-; logo = {"redirect_link": "/", "image_path": "sf10a.png"}
+; logo.link = /
+; logo.path = sf10a.png
+; logo.width = 78 ; in px
+; logo.height = 16 ; in px
; Used to uniquify references to static resources, can be a timestamp or any unique value
; This should be updated each time you deploy (or make significant changes, like new tools, new css)