torchbox / torchbox/django-pattern-library
Unable to use forward slash in `SECTIONS` paths
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 423
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
Issue Summary
Using / in the paths of my PATTERN_LIBRARY.SECTIONS results in a PatternLibraryEmpty exception
Steps to Reproduce
My library settings are like so:
PATTERN_LIBRARY = {
# Groups of templates for the pattern library navigation. The keys
# are the group titles and the values are lists of template name prefixes that will
# be searched to populate the groups.
"SECTIONS": (
(
"Components",
[
"patterns/components",
],
),
("Forms", ["patterns/forms"]),
),
# Configure which files to detect as templates.
"TEMPLATE_SUFFIX": ".html",
# Set which template components should be rendered inside of,
# so they may use page-level component dependencies like CSS.
"PATTERN_BASE_TEMPLATE_NAME": r"patterns\base.html",
}
However, when I try to view a pattern, I get the following error: No templates found matching: '(('Components', ['patterns/components']), ('Forms', ['patterns/forms']))'.
To rectify, I have to change my sections to backslashes:
"SECTIONS": (
(
"Components",
[
r"patterns\components",
],
),
("Forms", [r"patterns\forms"]),
),
This is on Windows 11, with Django 4.2 & django-pattern-library v1.2.0.
Technical details
Something like this would resolve:
def section_for(template_folder):
paths = path_to_section()
for path in paths:
template_folder = str(template_folder).replace("/", "\\")
if template_folder.startswith(path.replace("/", "\\")):
return paths[path], path
return None, None
- Python version: Run
python --version. - Django version: Look in your requirements.txt, or run
pip show django | grep Version. - Browser version: You can use https://www.whatsmybrowser.org/ to find this out.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided PATTERN_LIBRARY configuration on Windows, then inspect the section_for and path_to_section entry points mentioned in the issue. The change is done when forward-slash SECTIONS paths work like backslash paths without raising PatternLibraryEmpty; verify this with the example configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100