Skip to main content

Renderoo

Renderoo is a small library to render HTML components into HTML templates using python.

The objective is to allow you to build a library of components as python code.

Note that this is not meant to render on the fly. Nor is it meant to be used for client side components.

The use case that promted the development of this library was how annoying it is to write HTML templates in Django.

The Django template engine is easy and simple to use.

But I wanted to reduce the amount of repetition when dealing with HTML.

Repeating HTML over and over opens up the door to errors and style bugs.

This is certainly inspired by JSX, except that I did not choose to create a new markup language for this. It did not make much sense.

Requirements

Renderoo requires Python 3 or newer releases.

I strongly suggest Python 3.6+ for to the availability of f-strings.

Install

To install Renderoo run pip install renderoo

Usage

Renderoo provides two functionalities:

  • a component class to subclass when defining your own components
  • an html template writer class to write your templates to file

Defining your own components

There are 4 ways you can define your components.

Stand alone component

A stand alone component does not accept any parameters and returns an html string.

class HelloWorldComponent(Component):
    def render(self):
        return "<p>Hello, world.</p>"

Nested components

A nested component is one component directly inside another.

class HelloWorldComponent(Component):
    def render(self):
        return "<p>Hello, world.</p>"


class NestedComponent(Component):
    def render(self):
        return f"<div>{HelloWorldComponent().render()}</div>"

Parametrized component

A parametrized component render method accepts a component as a parameter.

class ParametrizedComponent(Component):
    def render(self, component):
        return f'<div>{component}</div>'

Parent with child component

A parent with child component accepts a component as an argument.

class ParentWithChildComponent(Component):
    def __init__(self, child_component):
        self.child_component = child_component

    def render(self):
        return f"<div>{self.child_component}</div>"

Using the template writer

The template writer is simply a shortcut to writing your templates to file.

It accepts two parameters: html and template_name

html is the html being written.

Example: <p>Hello, world.</p>

template_name is the template name as a full path of where it's going to be written.

Example: /path/to/the/template.html

You can define your own template writers by subclassing the TemplateWriter class.

Issues and Bug reports

  • Open a ticket
  • Clearly explain the issue
  • Patiently wait for a response

Pull requests

Pull requests are welcome and may not be immeditely merged. Please open an issue to discuss the merits of your idea.

License

MIT

Release files for Renderoo 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Renderoo 0.1.0
File Size Uploaded
Renderoo-0.1.0.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Renderoo 0.1.0
File Interpreter ABI Platform
Renderoo-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / Renderoo-0.1.0.tar.gz

Download URL Renderoo-0.1.0.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1983a6cc1dd7345cf51527658758c4693990ebdb6ef8ca2d2ed2da545c6966b4
BLAKE2b-256 checksum
How to use checksums
984c8e1b267daf1a2ba8615a6f0802660e52c6faacc6aef178341150e5766172
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.0

Release files / Renderoo-0.1.0-py3-none-any.whl

Download URL Renderoo-0.1.0-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
884fdd8c59353d00f582405490a9879eadb60cf1da632d14d336e67d58cd97b3
BLAKE2b-256 checksum
How to use checksums
e921076aea446ed7e6c1474d0d9571fb7fc20623826ef05f291338be40a8a68a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page