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
A CTF leaderboard for the submission of flags during a CTF challenge. Built using Django.

🚩 CTF Leaderboard The goal of this project is to provide a simple web page to allow the participants of an CTF to enter their found flags. Also the l

Maurice Bauer 2 Jan 17, 2022
A Redis cache backend for django

Redis Django Cache Backend A Redis cache backend for Django Docs can be found at http://django-redis-cache.readthedocs.org/en/latest/. Changelog 3.0.0

Sean Bleier 1k Dec 15, 2022
Boilerplate Django Blog for production deployments!

CFE Django Blog THIS IS COMING SOON This is boilerplate code that you can use to learn how to bring Django into production. TLDR; This is definitely c

Coding For Entrepreneurs 26 Dec 09, 2022
Dynamic, database-driven Django forms

Django Dataforms django-dataforms is a wrapper for the Django forms API that lets you dynamically define forms in a database, rather than hard-coding

35 Dec 16, 2022
A set of high-level abstractions for Django forms

django-formtools Django's "formtools" is a set of high-level abstractions for Django forms. Currently for form previews and multi-step forms. This cod

Jazzband 621 Dec 30, 2022
A fresh approach to autocomplete implementations, specially for Django. Status: v3 stable, 2.x.x stable, 1.x.x deprecated. Please DO regularely ping us with your link at #yourlabs IRC channel

Features Python 2.7, 3.4, Django 2.0+ support (Django 1.11 (LTS), is supported until django-autocomplete-light-3.2.10), Django (multiple) choice suppo

YourLabs 1.7k Jan 01, 2023
Inject an ID into every log message from a Django request. ASGI compatible, integrates with Sentry, and works with Celery

Django GUID Now with ASGI support! Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request. In other words,

snok 300 Dec 29, 2022
GeoDjango provides geospatial extensions to the Django web dev framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. All documentation is in the "docs" directo

Paul Smith 20 Sep 20, 2022
A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Speech

ElhamBlog Cloud Computing Course first assignment. A simple Blog Using Django Framework and Used IBM Cloud Services for Text Analysis and Text to Spee

Elham Razi 5 Dec 06, 2022
Duckiter will Automatically dockerize your Django projects.

Duckiter Duckiter will Automatically dockerize your Django projects. Requirements : - python version : python version 3.6 or upper version - OS :

soroush safari 23 Sep 16, 2021
Djang Referral System

Djang Referral System About | Features | Technologies | Requirements | Starting | License | Author 🎯 About I created django referral system and I wan

Alex Kotov 5 Oct 25, 2022
Use Database URLs in your Django Application.

DJ-Database-URL This simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django appl

Jacob Kaplan-Moss 1.3k Dec 30, 2022
a little task queue for python

a lightweight alternative. huey is: a task queue (2019-04-01: version 2.0 released) written in python (2.7+, 3.4+) clean and simple API redis, sqlite,

Charles Leifer 4.3k Dec 29, 2022
💨 Fast, Async-ready, Openapi, type hints based framework for building APIs

Fast to learn, fast to code, fast to run Django Ninja - Fast Django REST Framework Django Ninja is a web framework for building APIs with Django and P

Vitaliy Kucheryaviy 3.8k Jan 01, 2023
A simple Django dev environment setup with docker for demo purposes for GalsenDev community

GalsenDEV Docker Demo This is a basic Django dev environment setup with docker and docker-compose for a GalsenDev Meetup. The main purposes was to mak

3 Jul 03, 2021
PicoStyle - Advance market place website written in django

Advance market place website written in django :) Online fashion store for whole

AminAli Mazarian 26 Sep 10, 2022
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 02, 2023
It takes time to start a Django Project and make it almost production-ready.

It takes time to start a Django Project and make it almost production-ready. A developer needs to spend a lot of time installing required libraries, setup a database, setup cache as well as hiding se

Khan Asfi Reza 1 Jan 01, 2022
simple project management tool for educational purposes

Taskcamp This software is used for educational and demonstrative purposes. It's a simple project management tool powered by Django Framework Install B

Ilia Dmitriev 6 Nov 08, 2022
A slick ORM cache with automatic granular event-driven invalidation.

Cacheops A slick app that supports automatic or manual queryset caching and automatic granular event-driven invalidation. It uses redis as backend for

Alexander Schepanovski 1.7k Jan 03, 2023