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
Reusable workflow library for Django

django-viewflow Viewflow is a lightweight reusable workflow library that helps to organize people collaboration business logic in django applications.

Viewflow 2.3k Jan 8, 2023
Reusable, generic mixins for Django

django-braces Mixins for Django's class-based views. Documentation Read The Docs Installation Install from PyPI with pip: pip install django-braces Bu

Brack3t 1.9k Jan 5, 2023
A reusable Django app that configures your project for deployment

django-simple-deploy This app gives you a management command that configures your project for an initial deployment. It targets Heroku at the moment,

Eric Matthes 205 Dec 26, 2022
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

sageteam 51 Sep 15, 2022
Django API without Django REST framework.

Django API without DRF This is a API project made with Django, and without Django REST framework. This project was done with: Python 3.9.8 Django 3.2.

Regis Santos 3 Jan 19, 2022
Django-static-site - A simple content site framework that harnesses the power of Django without the hassle

coltrane A simple content site framework that harnesses the power of Django with

Adam Hill 57 Dec 6, 2022
Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project

Django URL Shortener Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project Install this package to your Dja

Rishav Sinha 4 Nov 18, 2021
Forgot password functionality build in Python / Django Rest Framework

Password Recover Recover password functionality with e-mail sender usign Django Email Backend How to start project. Create a folder in your machine Cr

alexandre Lopes 1 Nov 3, 2021
A Django app that allows visitors to interact with your site as a guest user without requiring registration.

django-guest-user A Django app that allows visitors to interact with your site as a guest user without requiring registration. Largely inspired by dja

Julian Wachholz 21 Dec 17, 2022
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs 3.x docs are avai

null 1.2k Jan 5, 2023
Use webpack to generate your static bundles without django's staticfiles or opaque wrappers.

django-webpack-loader Use webpack to generate your static bundles without django's staticfiles or opaque wrappers. Django webpack loader consumes the

null 2.4k Dec 24, 2022
Coltrane - A simple content site framework that harnesses the power of Django without the hassle.

coltrane A simple content site framework that harnesses the power of Django without the hassle. Features Can be a standalone static site or added to I

Adam Hill 58 Jan 2, 2023
Realtime data read and write without page refresh using Ajax in Django.

Realtime read-write with AJAX Hey,this is the basic implementation type of ajax realtime read write from the database. where you can insert or view re

Mehedi Hasan 3 Dec 13, 2022
An API was build with Django to store and retrieve information about various musical instruments.

The project is meant to be a starting point, an experimentation or a basic example of a way to develop an API with Django. It is an exercise on using Django and various python technologies and design methodologies.

Kostas Ziovas 2 Dec 25, 2021
A modern looking portfolio build with Django.

Django Portfolio A portfolio template using html/css/js in the frontend and Django as the backend framework. Cool features: smooth scrolling responsiv

null 1 Jan 19, 2022
Ugly single sign-on for django projects only

django-usso Ugly single sign-on for django projects only. Do you have many django apps with different users? Do you want to use only one of those apps

Erwin Feser 1 Mar 1, 2022
Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in the browser cookies.

Django Persistent Filters Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in

Lorenzo Prodon 2 Aug 5, 2022
Meta package to combine turbo-django and stimulus-django

Hotwire + Django This repository aims to help you integrate Hotwire with Django ?? Inspiration might be taken from @hotwired/hotwire-rails. We are sti

Hotwire for Django 31 Aug 9, 2022
django-reversion is an extension to the Django web framework that provides version control for model instances.

django-reversion django-reversion is an extension to the Django web framework that provides version control for model instances. Requirements Python 3

Dave Hall 2.8k Jan 2, 2023