diff options
author | Diana Whitten <hurgleburgler@gmail.com> | 2015-10-08 12:22:08 -0700 |
---|---|---|
committer | Diana Whitten <hurgleburgler@gmail.com> | 2015-12-03 16:07:00 +0000 |
commit | 053b5f30d7b2c4b5ba6d885dc28723744e5b22db (patch) | |
tree | 627e08e9deae4f4ca183d508b34dbb6e1848f289 /horizon/templatetags/horizon.py | |
parent | eae45b143cb7be538c11b1b1b51aa7dd4be2e23d (diff) | |
download | horizon-053b5f30d7b2c4b5ba6d885dc28723744e5b22db.tar.gz |
Horizon Dropdown now inherits from Bootstrap Theme
Horizon dropdowns now use proper Bootstrap markup to allow for theme
inheritance. It was noticed during this effort that Horizon was
using a mixture of <a> and <button> elements within dropdowns, and
having to override CSS so that their styles were shared. This
created unnecessary complexity in the CSS:
http://getbootstrap.com/components/#dropdowns
It was also noted that we were passing Bootstrap classes defined in
the Python code to the templates through a static string that was
concatenated within all the other needed attributes. This makes
overriding the templates with custom classes difficult. New logic was
added to allow classes to be separate. This more granular approach
was added to the table drop down templates.
Partially-Implements: blueprint horizon-theme-css-reorg
Partially-Implements: blueprint bootstrap-html-standards
Partial-bug: #1490207
Change-Id: Id82999e5db37035968d39361ba9be4ff87c26f66
Diffstat (limited to 'horizon/templatetags/horizon.py')
-rw-r--r-- | horizon/templatetags/horizon.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/horizon/templatetags/horizon.py b/horizon/templatetags/horizon.py index c8ef4f112..bca67bd45 100644 --- a/horizon/templatetags/horizon.py +++ b/horizon/templatetags/horizon.py @@ -19,6 +19,7 @@ from horizon.contrib import bootstrap_datepicker from django.conf import settings from django import template +from django.template import Node from django.utils.encoding import force_text from django.utils import translation from django.utils.translation import ugettext_lazy as _ @@ -26,10 +27,19 @@ from django.utils.translation import ugettext_lazy as _ from horizon.base import Horizon # noqa from horizon import conf - register = template.Library() +class MinifiedNode(Node): + def __init__(self, nodelist): + self.nodelist = nodelist + + def render(self, context): + return ' '.join( + force_text(self.nodelist.render(context).strip()).split() + ) + + @register.filter def has_permissions(user, component): """Checks if the given user meets the permissions requirements for @@ -198,3 +208,28 @@ def datepicker_locale(): locale_mapping = getattr(settings, 'DATEPICKER_LOCALES', bootstrap_datepicker.LOCALE_MAPPING) return locale_mapping.get(translation.get_language(), 'en') + + +@register.tag +def minifyspace(parser, token): + """Removes whitespace including tab and newline characters. Do not use this + if you are using a <pre> tag + + Example usage:: + + {% minifyspace %} + <p> + <a title="foo" + href="foo/"> + Foo + </a> + </p> + {% endminifyspace %} + + This example would return this HTML:: + + <p><a title="foo" href="foo/">Foo</a></p> + """ + nodelist = parser.parse(('endminifyspace',)) + parser.delete_first_token() + return MinifiedNode(nodelist) |