Skip to main content

Renderoo is a tiny html component library and html template writer for Python 3

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Renderoo-0.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

Renderoo-0.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file Renderoo-0.1.0.tar.gz.

File metadata

  • Download URL: Renderoo-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for Renderoo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1983a6cc1dd7345cf51527658758c4693990ebdb6ef8ca2d2ed2da545c6966b4
MD5 2b60b0fefca86e3d2230259f03b86538
BLAKE2b-256 984c8e1b267daf1a2ba8615a6f0802660e52c6faacc6aef178341150e5766172

See more details on using hashes here.

File details

Details for the file Renderoo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: Renderoo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for Renderoo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 884fdd8c59353d00f582405490a9879eadb60cf1da632d14d336e67d58cd97b3
MD5 faedd9dd5c08c6fc5f1a89f71664664f
BLAKE2b-256 e921076aea446ed7e6c1474d0d9571fb7fc20623826ef05f291338be40a8a68a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page