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

Unable to use forward slash in SECTIONS paths #246

Open
ben-qr opened this issue Jun 10, 2024 · 0 comments
Open

Unable to use forward slash in SECTIONS paths #246

ben-qr opened this issue Jun 10, 2024 · 0 comments

Comments

@ben-qr
Copy link

ben-qr commented Jun 10, 2024

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant