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
Fast / fuzzy PostgreSQL counts for Django

Created by Stephen McDonald Introduction Up until PostgreSQL 9.2, COUNT queries generally required scanning every row in a database table. With millio

stephenmcd 85 Oct 25, 2021
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
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 01, 2022
scaffold django rest apis like a champion 🚀

dr_scaffold Scaffold django rest apis like a champion ⚡ . said no one before Overview This library will help you to scaffold full Restful API Resource

Abdenasser Elidrissi 133 Jan 05, 2023
Use minify-html, the extremely fast HTML + JS + CSS minifier, with Django.

django-minify-html Use minify-html, the extremely fast HTML + JS + CSS minifier, with Django. Requirements Python 3.8 to 3.10 supported. Django 2.2 to

Adam Johnson 60 Dec 28, 2022
Simple XML-RPC and JSON-RPC server for modern Django

django-modern-rpc Build an XML-RPC and/or JSON-RPC server as part of your Django project. Major Django and Python versions are supported Main features

Antoine Lorence 82 Dec 04, 2022
An example of Django project with basic user functionality and account activation.

Simple Django Login and Registration An example of Django project with basic user functionality. Screenshots Log In Create an account Authorized page

Hussein Sarea 3 Oct 19, 2022
Neighbourhood - A python-django web app to help the residence of a given neighborhood know their surrounding better

Neighbourhood A python-django web app to help the residence of a given neighborh

Levy Omolo 4 Aug 25, 2022
Modular search for Django

Haystack Author: Daniel Lindsley Date: 2013/07/28 Haystack provides modular search for Django. It features a unified, familiar API that allows you to

Haystack Search 3.4k Jan 08, 2023
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
Thumbnails for Django

Thumbnails for Django. Features at a glance Support for Django 2.2, 3.0 and 3.1 following the Django supported versions policy Python 3 support Storag

Jazzband 1.6k Jan 03, 2023
A small and lightweight imageboard written with Django

Yuu A small and lightweight imageboard written with Django. What are the requirements? Python 3.7.x PostgreSQL 14.x Redis 5.x FFmpeg 4.x Why? I don't

mint.lgbt 1 Oct 30, 2021
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
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
An opinionated Django CMS setup bundled as an Aldryn Addon

Aldryn CMS |PyPI Version| An opinionated django CMS setup bundled as an Aldryn Addon. This package will auto configure django CMS including some extra

Vladimir Bezrukov 1 Nov 12, 2021
🗂️ 🔍 Geospatial Data Management and Search API - Django Apps

Geospatial Data API in Django Resonant GeoData (RGD) is a series of Django applications well suited for cataloging and searching annotated geospatial

Resonant GeoData 53 Nov 01, 2022
Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB.

djangoProject Projeto onde podes inserir notícias, ver todas as notícias guardas e filtrar por tag. A base de dados usada é o mongoDB. packages utiliz

Sofia Rocha 1 Feb 22, 2022
A set of functions related with Django

django-extra-tools Table of contents Installation Quick start Template filters parse_datetime parse_date parse_time parse_duration Aggregation First L

Tomasz Jakub Rup 3 Mar 04, 2020
Notes-Django: an advanced project to save notes in Django. where users are able to Create, Read, Update and Delete their notes.

An advanced software to keep you notes. It allows users to perform CRUD operations on theirs Notes. Was implemented Authorization and Authentication

Edilson Pateguana 1 Feb 05, 2022
Wrap the Blockchain API in Django!

django-blockchain Wrap the Blockchain API in Django. Installation pip install django-blockchain Add app in your settings.py INSTALLED_APPS = [ "d

Dmitry Kalinin 2 Feb 04, 2022