Skip to content

Remove forced patterns #83

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

Merged
merged 12 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions pattern_library/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
import importlib
from functools import wraps

default_app_config = 'pattern_library.apps.PatternLibraryAppConfig'
settings = None

default_app_config = 'pattern_library.apps.PatternLibraryAppConfig'

def uses_settings(func):
@wraps(func)
def wrapped():
global settings
if settings is None:
settings = importlib.import_module('django.conf').settings
return func()
return wrapped
DEFAULT_SETTINGS = {
'BASE_TEMPLATE_NAME': 'patterns/base.html',
'TEMPLATE_SUFFIX': '.html',
'SECTIONS': (
('atoms', ['patterns/atoms']),
('molecules', ['patterns/molecules']),
('organisms', ['patterns/organisms']),
('templates', ['patterns/templates']),
('pages', ['patterns/pages']),
),
}


@uses_settings
def get_pattern_template_dir():
return settings.PATTERN_LIBRARY_TEMPLATE_DIR
def get_from_settings(attr):
from django.conf import settings

library_settings = DEFAULT_SETTINGS.copy()
library_settings.update(getattr(settings, 'PATTERN_LIBRARY', {}))

@uses_settings
def get_pattern_template_prefix():
return getattr(settings, 'PATTERN_LIBRARY_TEMPLATE_PREFIX', 'patterns')
return library_settings.get(attr)


@uses_settings
def get_pattern_template_suffix():
return getattr(settings, 'PATTERN_LIBRARY_TEMPLATE_SUFFIX', '.html')
return get_from_settings('TEMPLATE_SUFFIX')


@uses_settings
def get_pattern_base_template_name():
return getattr(settings, 'PATTERN_LIBRARY_BASE_TEMPLATE_NAME', 'patterns/base.html')
return get_from_settings('BASE_TEMPLATE_NAME')


def get_pattern_types():
return ['atoms', 'molecules', 'organisms', 'templates', 'pages']
def get_sections():
return get_from_settings('SECTIONS')


def get_pattern_context_var_name():
Expand Down
2 changes: 1 addition & 1 deletion pattern_library/monkey_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def node_render(context):
# Render pattern, if raw string is not defined
template_name = tag_config['template_name']
request = context.get('request')
result = render_pattern(request, template_name)
result = render_pattern(request, template_name, allow_non_patterns=True)
tag_overridden = True

# TODO: Allow objects with the __str__ method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ export function toggleNavItems() {
headings.forEach(heading => {
heading.addEventListener('click', e => {
e.target.classList.toggle('is-open');
e.target.nextElementSibling.classList.toggle('is-open');
for ( const element of e.target.parentNode.childNodes ) {
if ( element.nodeName === "UL" ){
element.classList.toggle('is-open');
}
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
font-size: 13px;
color: $mid-grey;
display: none;
padding-left: 10px;

&.is-open {
display: block;
Expand Down Expand Up @@ -68,5 +69,3 @@
}
}
}


26 changes: 3 additions & 23 deletions pattern_library/templates/pattern_library/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,15 @@ <h1 class="header__title">
<div class="sidebar__search-results" id="js-pattern-search-results-container"></div>
<nav class="sidebar__nav" id="sidebar-nav">
<ul class="list">
{% for pattern_type, pattern_type_groups in pattern_templates.items %}
{% for pattern_type_group, pattern_templates in pattern_templates.template_groups.items %}
<li class="list__item">
<h2 class="list__item-heading js-toggle-pattern">
<svg class="list__item-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 160">
<path d="M88 80l-48 48 16 16 64-64-64-64-16 16 48 48z" />
</svg>
{{ pattern_type|title }}
{{ pattern_type_group|title }}
</h2>
<ul class="list list--child">
{% for group_name, pattern_templates in pattern_type_groups.items %}
<li class="list__item">
<h3 class="list__item-heading list__item-heading--small list__item-heading--light js-toggle-pattern">
<svg class="list__item-icon list__item-icon--small" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 160">
<path d="M88 80l-48 48 16 16 64-64-64-64-16 16 48 48z" />
</svg>
{{ group_name }}
</h3>
<ul class="list list--grandchild">
{% for template in pattern_templates %}
<li class="list__item">
<a class="list__item-link" href="{% url 'pattern_library:display_pattern' template.origin.template_name %}" id="{{ template.origin.template_name }}">
{{ template.pattern_name }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% include "pattern_library/pattern_group.html" with groups=pattern_templates.template_groups %}
</li>
{% endfor %}
</ul>
Expand Down
24 changes: 24 additions & 0 deletions pattern_library/templates/pattern_library/pattern_group.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ul class="list list--child">
{% for group_name, pattern_templates in groups.items %}
<li class="list__item">
<h3 class="list__item-heading list__item-heading--small list__item-heading--light js-toggle-pattern">
<svg class="list__item-icon list__item-icon--small" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 160">
<path d="M88 80l-48 48 16 16 64-64-64-64-16 16 48 48z" />
</svg>
{{ group_name }}
</h3>
{% if pattern_templates.template_groups %}
{% include "pattern_library/pattern_group.html" with groups=pattern_templates.template_groups %}
{% endif %}
<ul class="list list--grandchild">
{% for template in pattern_templates.templates_stored %}
<li class="list__item">
<a class="list__item-link" href="{% url 'pattern_library:display_pattern' template.origin.template_name %}" id="{{ template.origin.template_name }}">
{{ template.pattern_name }}
</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
12 changes: 5 additions & 7 deletions pattern_library/urls.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from django.conf.urls import url

from pattern_library import (
get_pattern_template_prefix, get_pattern_template_suffix, views
)
from pattern_library import get_pattern_template_suffix, views

app_name = 'pattern_library'
urlpatterns = [
# UI
url(r'^$', views.IndexView.as_view(), name='index'),
url(
r'^pattern/(?P<pattern_template_name>%s/[\w./-]+%s)$' % (
get_pattern_template_prefix(), get_pattern_template_suffix()
r'^pattern/(?P<pattern_template_name>[\w./-]+%s)$' % (
get_pattern_template_suffix()
),
views.IndexView.as_view(),
name='display_pattern'
),

# iframe rendering
url(
r'^render-pattern/(?P<pattern_template_name>%s/[\w./-]+%s)$' % (
get_pattern_template_prefix(), get_pattern_template_suffix()
r'^render-pattern/(?P<pattern_template_name>[\w./-]+%s)$' % (
get_pattern_template_suffix()
),
views.RenderPatternView.as_view(),
name='render_pattern'
Expand Down
Loading