Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: django pattern library #822

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
79 changes: 75 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ django-js-asset = "1.2.2"
django-meta = "1.7.0"
django-mptt = "0.11.0"
django-parler = "2.2"
django-pattern-library = "0.5.0"
django-polymorphic = "3.0.0"
django-sekizai = "2.0.0"
django-settings-export = "1.2.1"
Expand Down
54 changes: 54 additions & 0 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def gettext(s): return s
"img_file_src": "site_cms/img/favicons/favicon.ico"
}

import importlib
_SETTINGS = importlib.import_module('taccsite_cms.settings')

########################
# TACC: PORTAL
########################
Expand Down Expand Up @@ -473,6 +476,53 @@ def get_subdirs_as_module_names(path):
'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
]

########################
# PATTERN LIBRARY
########################

INSTALLED_APPS += [
'pattern_library'
]
# NOTE: To render the library, the following should be added to `urls.py`
"""
if apps.is_installed('pattern_library'):
urlpatterns += [
path('pattern-library/', include("pattern_library.urls')),
]
"""

try:
TEMPLATES[0]['OPTIONS']['builtins'].append('pattern_library.loader_tags')
except KeyError:
TEMPLATES[0]['OPTIONS']['builtins'] = ['pattern_library.loader_tags']

# To see the detailed error pages generated by Django
# SEE: https://torchbox.github.io/django-pattern-library/getting-started/
if _SETTINGS.DEBUG:
X_FRAME_OPTIONS = 'SAMEORIGIN'

PATTERN_LIBRARY = {
# Groups of templates for the pattern library navigation.
# - The keys are group titles
# - The values are lists of template name prefixes
# (that will be searched to populate the groups)
'SECTIONS': (
('components', ['patterns/components']),
('pages', ['patterns/pages']),
),

# Configure which files to detect as templates.
'TEMPLATE_SUFFIX': '.html',

# Set the template inside of which components should be rendered
# (so they may use page-level component dependencies like CSS)
'PATTERN_BASE_TEMPLATE_NAME': 'patterns/base.html',

# Any template in BASE_TEMPLATE_NAMES (or any that extends one from there)
# is considered a "page" and will be rendered as-is (without being wrapped)
'BASE_TEMPLATE_NAMES': ['patterns/base_page.html'],
}

########################
# IMPORT & EXPORT
########################
Expand All @@ -495,6 +545,10 @@ def get_subdirs_as_module_names(path):
None
# do nothing

########################
# EXPORT
########################

SETTINGS_EXPORT = [
'DEBUG',
'FEATURES',
Expand Down
14 changes: 14 additions & 0 deletions taccsite_cms/templates/patterns/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Component Base</title>
</head>
<body>
{% block content %}
{# pattern_library_rendered_pattern is where the pattern library will inject the rendered pattern. #}
{{ pattern_library_rendered_pattern }}
{% endblock %}
</body>
</html>
3 changes: 3 additions & 0 deletions taccsite_cms/templates/patterns/base_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends 'patterns/base.html' %}

{% block title %}Page{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<blockquote class="quote-block block--spacing">
<div class="quote-block__text">
<p class="quote-block__quote">{{ quote }}</p>
{% if attribution %}
<p class="quote-block__attribution">{{ attribution }}</p>
{% endif %}
</div>
</blockquote>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: Quote Block (Sample)
context:
quote: What is love?
attribution: Haddaway
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends 'patterns/base_page.html' %}

{% block content %}{{ page.body }}{% endblock %}
11 changes: 11 additions & 0 deletions taccsite_cms/templates/patterns/pages/test_page/test_page.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
context:
page:
body: >
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
7 changes: 7 additions & 0 deletions taccsite_cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import, print_function, unicode_literals

from cms.sitemaps import CMSSitemap
from django.apps import apps
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import include, url
Expand All @@ -10,6 +11,7 @@
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.views.static import serve
from django.urls import path
from taccsite_cms import remote_cms_auth as remote_cms_auth

from django.http import request
Expand Down Expand Up @@ -39,6 +41,11 @@
url(r'^', include('cms.urls')),
]

if apps.is_installed('pattern_library'):
urlpatterns.insert(0,
path('pattern-library/', include('pattern_library.urls'))
)

# This is only needed when using runserver.
if settings.DEBUG:
urlpatterns += [
Expand Down