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
Bootstrap 3 integration with Django.

django-bootstrap3 Bootstrap 3 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 3. Want to use Bootstr

Zostera B.V. 2.3k Jan 02, 2023
Django datatables with htmx.

Django datatables with htmx.

Regis Santos 7 Oct 23, 2022
Учебное пособие по основам Django и сопутствующим технологиям

Учебный проект для закрепления основ Django Подробный разбор проекта здесь. Инструкция по запуску проекта на своей машине: Скачиваем репозиторий Устан

Stanislav Garanzha 12 Dec 30, 2022
TinyMCE integration for Django

django-tinymce django-tinymce is a Django application that contains a widget to render a form field as a TinyMCE editor. Quickstart Install django-tin

Jazzband 1.1k Dec 26, 2022
A small Django app to easily broadcast an announcement across a website.

django-site-broadcasts The site broadcast application allows users to define short messages and announcements that should be displayed across a site.

Ben Lopatin 12 Jan 21, 2020
Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app.

django-permissions-policy Set the draft security HTTP header Permissions-Policy (previously Feature-Policy) on your Django app. Requirements Python 3.

Adam Johnson 78 Jan 02, 2023
Django + NextJS + Tailwind Boilerplate

django + NextJS + Tailwind Boilerplate About A Django project boilerplate/templa

Shayan Debroy 3 Mar 11, 2022
Django StatusPage - App to display statuspage for your services

Django StatusPage - App to display statuspage for your services

Gorlik 1 Oct 27, 2021
Sampling profiler for Python programs

py-spy: Sampling profiler for Python programs py-spy is a sampling profiler for Python programs. It lets you visualize what your Python program is spe

Ben Frederickson 9.5k Jan 01, 2023
Helps working with singletons - things like global settings that you want to edit from the admin site.

Django Solo +---------------------------+ | | | | | \ | Django Solo helps

Sylvain Toé 726 Jan 08, 2023
Chatbot for ordering and tracking a Pizza.

Pizza Chatbot To start the app, follow the below steps: Clone the repo using the below command: git clone Shreya Shah 1 Jul 15, 2021

Django application and library for importing and exporting data with admin integration.

django-import-export django-import-export is a Django application and library for importing and exporting data with included admin integration. Featur

2.6k Dec 26, 2022
Store events and publish to Kafka

Create an event from Django ORM object model, store the event into the database and also publish it into Kafka cluster.

Diag 6 Nov 30, 2022
Strawberry-django-plus - Enhanced Strawberry GraphQL integration with Django

strawberry-django-plus Enhanced Strawberry integration with Django. Built on top

BLB Ventures 138 Dec 28, 2022
A simple page with paypal payment and confiramtion in django

django-paypal a simple page with paypal payment and confiramtion in django Youtube Video : Paypal Smart Button : https://developer.paypal.com/demo/che

Mahmoud Ahmed 5 Feb 19, 2022
Customize the behavior of django.contrib.auth permissions.

Customizando o comportamento do django.contrib.auth. O que queremos? Não criar as permissões padrões automaticamente (add, delete, view, read). Criar

Henrique Bastos 7 Nov 26, 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
Intellicards-backend - A Django project bootstrapped with django-admin startproject mysite

Intellicards-backend - A Django project bootstrapped with django-admin startproject mysite

Fabrizio Torrico 2 Jan 13, 2022
This website serves as an online database (hosted via SQLLite) for fictional businesses in the area to store contact information (name, email, phone number, etc.) for fictional customers.

Django-Online-Business-Database-Project this project is still in progress Overview of Website This website serves as an online database (hosted via SQ

1 Oct 30, 2021
Automatically reload your browser in development.

django-browser-reload Automatically reload your browser in development. Requirements Python 3.6 to 3.10 supported. Django 2.2 to 4.0 supported. Are yo

Adam Johnson 254 Jan 04, 2023