Build reusable components in Django without writing a single line of Python.

Overview

Slippers


PyPI version PyPI Supported Python Versions PyPI Supported Django Versions GitHub Actions (Code quality and tests)

Build reusable components in Django without writing a single line of Python.

{% #quote %}
  {% quote_photo src="/project-hail-mary.jpg" %}

  {% #quote_text %}
    “I penetrated the outer cell membrane with a nanosyringe."
    "You poked it with a stick?"
    "No!" I said. "Well. Yes. But it was a scientific poke
    with a very scientific stick.”
  {% /quote_text %}

  {% #quote_attribution %}
    Andy Weir, Project Hail Mary
  {% /quote_attribution %}
{% /quote %}

What is Slippers?

The Django Template Language is awesome. It's fast, rich in features, and overall pretty great to work with.

Slippers aims to augment DTL, adding just enough functionality to make building interfaces just that bit more comfortable.

It includes additional template tags and filters, but its headline feature is reusable components.

{% #button variant="primary" %}See how it works{% /button %}

See how it works

Installation

pip install slippers

Add it to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'slippers',
    ...
]

Documentation

Full documentation can be found on the Slippers documentation site.

License

MIT

Comments
  • allow `{% attrs %}` to render hyphenated attributes ( `aria-label`, `data-script` etc)

    allow `{% attrs %}` to render hyphenated attributes ( `aria-label`, `data-script` etc)

    from htmx.org

    htmx gives you access to AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext

    htmx attributes are represented in templates tags like other attributes. potential caveat : they are defined with a hyphen hx-get , hx-target, hx-swap ...

    this enhancement could also increase compatibility with alpine, hyperscript and other frameworks that make use of custom HTML attributes, and attrs that are defined with hyphens such as aria-label

    Happy to contribute to implementation

    opened by lolrenx 5
  • `{% attrs %}` do not render attributes starting with a `@`

    `{% attrs %}` do not render attributes starting with a `@`

    Hi,

    Trying to marry Slippers with AlpineJS I found that attributes starting with @ do not render.

    Component definition:

    <button {% attrs type @click %}>{{ children }}</button>
    

    Usage:

    {% #button type="button" @click="open = true" %}Open something{% /button %}
    

    Render:

    <button>Open something</button>
    

    It's not even rendering the type attribute

    opened by jlopinto 3
  • Not compatible with Django 4.1

    Not compatible with Django 4.1

    Poetry will not accept to install Django 4.1 with slippers (any version).

    $ poetry lock
    Updating dependencies
    Resolving dependencies... (1.5s)
    
      SolverProblemError
    
      Because no versions of slippers match <0.1.0 || >0.1.0,<0.1.1 || >0.1.1,<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<0.1.4 || >0.1.4,<0.2.0 || >0.2.0,<0.3.0 || >0.3.0,<0.3.1 || >0.3.1
       and slippers (0.1.0) depends on Django (>=3.0,<4.0), slippers (<0.1.1 || >0.1.1,<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<0.1.4 || >0.1.4,<0.2.0 || >0.2.0,<0.3.0 || >0.3.0,<0.3.1 || >0.3.1) requires Django (>=3.0,<4.0).
      And because slippers (0.1.1) depends on Django (>=2.2,<4.0), slippers (<0.1.2 || >0.1.2,<0.1.3 || >0.1.3,<0.1.4 || >0.1.4,<0.2.0 || >0.2.0,<0.3.0 || >0.3.0,<0.3.1 || >0.3.1) requires Django (>=2.2,<4.0).
      And because slippers (0.1.2) depends on Django (>=2.2,<4.0)
       and slippers (0.1.3) depends on Django (>=2.2,<4.0), slippers (<0.1.4 || >0.1.4,<0.2.0 || >0.2.0,<0.3.0 || >0.3.0,<0.3.1 || >0.3.1) requires Django (>=2.2,<4.0).
      And because slippers (0.1.4) depends on Django (>=2.2,<4.0)
       and slippers (0.2.0) depends on Django (>=2.2,<4.0), slippers (<0.3.0 || >0.3.0,<0.3.1 || >0.3.1) requires Django (>=2.2,<4.0).
      And because slippers (0.3.0) depends on Django (>=2.2,<4.0)
       and slippers (0.3.1) depends on Django (>=2.2,<4.1), every version of slippers requires Django (>=2.2,<4.1).
      So, because mango depends on both Django (4.1.*) and slippers (*), version solving failed.
    
    opened by ddahan 3
  • Non-boolean {% attrs %} which appear after boolean attributes don't get parsed/rendered correctly

    Non-boolean {% attrs %} which appear after boolean attributes don't get parsed/rendered correctly

    This is with slippers 0.4.0.

    Consider the following simple component, named test_component:

    <input type="text" {% attrs required maxlength %}>
    

    If you use it in a template like this:

    {% test_component required maxlength=10 %}
    

    ...then it outputs this (note that the maxlength attribute is missing):

    <input type="text" required>
    

    But if you reverse the order of the attributes in the template:

    {% test_component maxlength=10 required %}
    

    Or if you pass an explicit value:

    {% test_component required=True maxlength=10 %}
    

    ...then it works as expected:

    <input type="text" required maxlength="10">
    
    opened by ocratravis 2
  • Question: Can I use a single fragment in multiple blocks?

    Question: Can I use a single fragment in multiple blocks?

    Firstly, thank you for your work on Slippers!

    I've looked through the documentation and can't find something directly answering this question.

    Assume I have a base template similar to the following:

    // base.html
    <div class="mobile-menu">{% block menu_mobile %}{% endblock %}</div>
    <div class="wrapper">
      <div class="desktop-menu">{% block menu_desktop %}{% endblock %}</div>
      <div class="content">{% block content %}{% endblock %}</div>
    </div>
    

    Note that since blocks must have unique names, I'm enable to directly repeat that content despite wanting the exact same markup.

    I would LOVE to be able to use fragments outside of a block, like so:

    // some-page.html
    {% extends 'base.html' %}
    {% fragment as menu %}
      <ul>
        <li><a href="#">My DRY Menu</a></li>
      </ul>
    {% endfragment %}
    {% block menu_mobile %}{{ menu }}{% endblock %}
    {% block menu_desktop %}{{ menu }}{% endblock %}
    {% block content %}
      My content here 
    {% endblock %}
    

    Unfortunately this isn't working in my experimentation. I'm guessing this is a scoping issue with block, but figured it was worth confirming whether this is possible.

    Thanks for your time.

    opened by AaronPresley 2
  • Update PyYAML to version 6.0.0 and black to 22.3.0

    Update PyYAML to version 6.0.0 and black to 22.3.0

    Slippers using PyYAML ^5.4.1 is causing dependency conflicts with other PyYAML-using packages in a project of mine. It appears that the only backwards-incompatible change from PyYAML 5 to 6 is dropping support for Python 2, so it is compatible with slippers.

    opened by keirwl 2
  • Recognise components.yml

    Recognise components.yml

    https://github.com/mixxorz/slippers/blob/2b0c9b42e6f78e9bad3903816c8becae870b26f4/slippers/apps.py#L43 Looks like this line could be updated to find either a yaml or yml file 😃.

    select_template https://docs.djangoproject.com/en/3.2/ref/templates/api/#django.template.Engine.select_template

    enhancement 
    opened by jafacakes2011 2
  • Components with N children

    Components with N children

    Hi

    I really liked this component approach that slippers does, an idea came to me for a component to have more than one child. Do you think this would have adoption in the lib? I can think of some ideas for that.

    opened by CleitonDeLima 1
  • Add support for short YAML file extension

    Add support for short YAML file extension

    When I tried out Slippers it didn't work initially because I had created a "components.yml" file instead of "components.yaml". I didn't see the system check message either because the log statements already moved it too far up the terminal.

    I'm not sure what suffix is more widely used but, for example, Docker Compose refers its config as "docker-compose.yml" while suporting both file endings:

    The Compose file is a YAML file defining services, networks and volumes. The default path for a Compose file is ./docker-compose.yml.

    Tip: You can use either a .yml or .yaml extension for this file. They both work.

    opened by jnns 1
  • Refactor prop type checking

    Refactor prop type checking

    Fixes issues where arbitrary props declared in front matter are type checked. Changed this behaviour so that only the values explicitly passed into the component via the component's template tag are evaluated.

    opened by mixxorz 0
  • Prop types, runtime type checking, and component code

    Prop types, runtime type checking, and component code

    This PR:

    • Adds a way to define prop types
    • Adds a way to define default values for props
    • Adds optional runtime type checking
    • Adds a way to add custom Python code to components

    Example component:

    ---
    props.types = {
        'required_string': str,
        'optional_number': Optional[int],
        'default_number': int,
    }
    props.defaults = {
        'default_number': 10,
    }
    
    # Arbitrary Python code that adds variables to the template context
    props['new_number'] = props['default_number'] * 2
    
    # props['default_number'] will return 10 if `default_number` is not passed to the component.
    ---
    
    The context contains:
    
    Required string: {{ required_string }}
    Optional number: {{ optional_number }}
    Default number: {{ default_number }}
    New number: {{ new_number }}
    
    opened by mixxorz 0
  • Prop errors refinement

    Prop errors refinement

    • Only display prop errors when runtime checking is enabled
    • Refactor how console errors are reported
    • Update padding on modal overlay
    • Remove shell error output target and rich dependency
    opened by mixxorz 0
  • Possibility of changing the opening/closing symbols for template tags

    Possibility of changing the opening/closing symbols for template tags

    Hello creator(s) of Slippers!

    I have heard about your project from this guy on YouTube, BugBytes: https://www.youtube.com/watch?v=oC1K8IKK3Vo

    I was excited to use it but was disappointed to see my IDE (IntelliJ) refusing to accept the newly created template tags.

    Prefixing any tag with a special character (besides underscores _ and dashes - ) throws out errors from the inspector.

    After days of trying, I haven't found a way to disable the inspector for that specific error. Nor could I register the symbol-containing tags by creating some kind of new rule. It just didn't work.

    I just lived with it, but after a couple of days of writing templates full of fake errors, I got so bugged out that I gave up and looked for an alternative.

    Then I found django-components, which did a similar job to Slippers, but in my opinion, is way too verbose and so I came back to slippers.

    Unfortunately, picking up another IDE is not an option after years of getting used to it. So this time, I tried to fix this issue by monkey-patching the code inside templatetags/slippers.py (really ran out of options).

    OPENING_SYMBOL = "__"
    CLOSING_SYMBOL = "___"
    
    
    # Copied from slippers source code
    #
    # Replaces opening / closing symbols for tags
    # #card and /card --> __card and ___card
    #
    # Fixes IntelliJ IDE template inspector throwing errors
    
    # Component tags
    def create_component_tag(template_path):
        def do_component(parser, token):
            tag_name, *remaining_bits = token.split_contents()
    
            # Block components start with OPENING_SYMBOL
            # Expect a closing tag
            if tag_name.startswith(OPENING_SYMBOL):
                nodelist = parser.parse((f"{CLOSING_SYMBOL}{tag_name[len(CLOSING_SYMBOL):]}",))
                parser.delete_first_token()
            else:
                nodelist = None
    

    For motives unbeknownst to me, the template tags won't be registered when applying this monkey patch, but I have not given up on this solution yet and would come up with a pull request once everything is working well.

    Any chance of adding the option to change the template tag prefixes (possibly using a settings.py variable)?

    Massive respect for creating this library, Chris, a slippers fan :)

    opened by scriptogre 0
  • Docs: attrs tag default value

    Docs: attrs tag default value

    I found that we can provide a default value to attrs tag values using the var tag I'm not sure if it was initially designed to work like that.

    This PR is about documenting that find.

    opened by jlopinto 0
  • Change suggested component name format to TitleCase

    Change suggested component name format to TitleCase

    This issue proposes changing the suggested name format of components to TitleCase from snake_case to improve readability by being distinct from normal template tags, keyword arguments, and variables.

    {% #Quote %}
      {% QuotePhoto src="/project-hail-mary.jpg" %}
    
      {% #QuoteText %}
        “I penetrated the outer cell membrane with a nanosyringe."
        "You poked it with a stick?"
        "No!" I said. "Well. Yes. But it was a scientific poke
        with a very scientific stick.”
      {% /QuoteText %}
    
      {% #QuoteAttribution %}
        Andy Weir, Project Hail Mary
      {% /QuoteAttribution %}
    {% /Quote %}
    

    Open to feedback on this.

    opened by mixxorz 1
  • Component autodiscovery

    Component autodiscovery

    Maintaining a yaml file of components is a little annoying. There should be a built-in way to auto-discover components.

    I have a few ideas but if you have suggestions, please share. 🙂

    opened by mixxorz 2
Releases(0.6.0-alpha.0)
  • 0.6.0-alpha.0(Dec 29, 2022)

    What's Changed

    Prop types, runtime type checking, and component code by @mixxorz in

    • https://github.com/mixxorz/slippers/pull/25
    • https://github.com/mixxorz/slippers/pull/28
    • https://github.com/mixxorz/slippers/pull/29

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.5.0...0.6.0-alpha.0

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(Nov 5, 2022)

    What's Changed

    • Add support for special characters in keyword arguments by @mixxorz in https://github.com/mixxorz/slippers/pull/23
    • Improve boolean handling by @mixxorz in https://github.com/mixxorz/slippers/pull/24

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.4.0...0.5.0

    Source code(tar.gz)
    Source code(zip)
  • 0.5.0-alpha.0(Oct 30, 2022)

    What's Changed

    • Add support for special characters in keyword arguments by @mixxorz in https://github.com/mixxorz/slippers/pull/23
    • Improve boolean handling by @mixxorz in https://github.com/mixxorz/slippers/pull/24

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.4.0...0.5.0-alpha.0

    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Aug 10, 2022)

    What's Changed

    • Automatically convert underscores to hyphens in attrs by @mixxorz in https://github.com/mixxorz/slippers/pull/17

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.3.2...0.4.0

    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Aug 4, 2022)

    What's Changed

    • Update PyYAML to version 6.0.0 and black to 22.3.0 by @keirwl in https://github.com/mixxorz/slippers/pull/11
    • Add support for Django 4.1 by @mixxorz in https://github.com/mixxorz/slippers/pull/15

    New Contributors

    • @keirwl made their first contribution in https://github.com/mixxorz/slippers/pull/11

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.3.1...0.3.2

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Dec 17, 2021)

    What's Changed

    • Add official support for Django 4.0 and Python 3.10 by @mixxorz in https://github.com/mixxorz/slippers/pull/9

    Full Changelog: https://github.com/mixxorz/slippers/compare/0.3.0...0.3.1

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Oct 24, 2021)

    What's Changed

    • Add support for short YAML file extension by @jnns in https://github.com/mixxorz/slippers/pull/8

    New Contributors

    • @jnns made their first contribution in https://github.com/mixxorz/slippers/pull/8

    Full Changelog: https://github.com/mixxorz/slippers/commits/0.3.0

    Source code(tar.gz)
    Source code(zip)
Owner
Mitchel Cabuloy
Python and Javascript. Senior Developer at @torchbox
Mitchel Cabuloy
Source code for Django for Beginners 3.2

The official source code for https://djangoforbeginners.com/. Available as an ebook or in Paperback. If you have the 3.1 version, please refer to this

William Vincent 10 Jan 03, 2023
xsendfile etc wrapper

Django Sendfile This is a wrapper around web-server specific methods for sending files to web clients. This is useful when Django needs to check permi

John Montgomery 476 Dec 01, 2022
Built from scratch to replicate some of the Django admin functionality and add some more, to serve as an introspective interface for Django and Mongo.

django-mongonaut Info: An introspective interface for Django and MongoDB. Version: 0.2.21 Maintainer: Jazzband (jazzband.co) This Project is Being Mov

Jazzband 238 Dec 26, 2022
Django Login Api With Python

How to run this project Download and extract this project Create an environment and install all the libraries from requiements.txt pip freeze -r requi

Vikash Kisku 1 Dec 10, 2021
Django CacheMiddleware has a multi-threading issue with pylibmc

django-pylibmc-bug Django CacheMiddleware has a multi-threading issue with pylibmc. CacheMiddleware shares a thread-unsafe cache object with many thre

Iuri de Silvio 1 Oct 19, 2022
wagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project.

wagtail-tenants wagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project. You are able to run a main Wagtail Site and f

<bbr> 11 Nov 20, 2022
Django-discord-bot - Framework for creating Discord bots using Django

django-discord-bot Framework for creating Discord bots using Django Uses ASGI fo

Jamie Bliss 1 Mar 04, 2022
Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10, and 1.11

django-compat Forward and backwards compatibility layer for Django 1.4 , 1.7 , 1.8, 1.9, 1.10 and 1.11 Consider django-compat as an experiment based o

arteria GmbH 106 Mar 28, 2022
A Django web application to receive, virus check and validate transfers of digital archival records, and allow archivists to appraise and accession those records.

Aurora Aurora is a Django web application that can receive, virus check and validate transfers of digital archival records, and allows archivists to a

Rockefeller Archive Center 20 Aug 30, 2022
Example project demonstrating using Django’s test runner with Coverage.py

Example project demonstrating using Django’s test runner with Coverage.py Set up with: python -m venv --prompt . venv source venv/bin/activate python

Adam Johnson 5 Nov 29, 2021
Django Starter is a simple Skeleton to start with a Django project.

Django Starter Template Description Django Starter is a simple Skeleton to start

Numan Ibn Mazid 1 Jan 10, 2022
Analytics services for Django projects

django-analytical The django-analytical application integrates analytics services into a Django project. Using an analytics service with a Django proj

Jazzband 1.1k Dec 31, 2022
This is a basic Todo Application API using Django Rest Framework

Todo Application This is a basic Todo Application API using Django Rest Framework. Todo Section - User can View his previously added todo items, creat

Atharva Parkhe 1 Aug 09, 2022
Simple yet powerful and really extendable application for managing a blog within your Django Web site.

Django Blog Zinnia Simple yet powerful and really extendable application for managing a blog within your Django Web site. Zinnia has been made for pub

Julien Fache 2.1k Dec 24, 2022
This a Django TODO app project and practiced how to deploy and publish the project to Heroku

ToDo App Demo | Project Table of Contents Overview Built With Features How to use Acknowledgements Contact Overview Built With HTML CSS JS Django How

Cetin OGUT 1 Nov 19, 2021
Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers.

Django Federated Login Django Federated Login provides an authentication bridge between Django projects and OpenID-enabled identity providers. The bri

Bouke Haarsma 18 Dec 29, 2020
Full-featured django project start tool.

django-start-tool Introduction django-start-tool is a full-featured replacement for django-admin startproject which provides cli for creating the same

Georgy Gnezdilov 0 Aug 30, 2022
Extensions for using Rich with Django.

django-rich Extensions for using Rich with Django. Requirements Python 3.6 to 3.10 supported. Django 2.2 to 4.0 supported. Are your tests slow? Check

Adam Johnson 88 Dec 26, 2022
Add infinite scroll to any django app.

django-infinite-scroll Add infinite scroll to any django app. Features - Allows to add infinite scroll to any page.

Gustavo Teixeira 1 Dec 26, 2021
Django-powered application about blockchain (bitcoin)

Django-powered application about blockchain (bitcoin)

Igor Izvekov 0 Jun 23, 2022