Giter VIP home page Giter VIP logo

strictdom's Introduction

Strictdom

Stictdom is a strictly typed wrapper over Dominate, a Python library for creating and manipulating HTML documents.

Compared to using Dominate directly, strictdom offers:

  • Type hints for code-completion / IntelliSense / IDE hints

  • Type hints and explicit arguments for HTML5 & ARIA conformance at runtime, or at compile-time with mypy.

Features:

  • Nothing new to learn - mostly the same interface as vanilla.

  • Stable versioned interface e.g. strictdom.tags_1 is a frozen view of the spec

  • Consistent handling of both boolean attributes and the weird "boolean-like" attributes like contenteditable or spellcheck.

Example: Vanilla vs Strict

"Vanilla" Dominate

import dominate.tags as dom

print(dom.button("Hello world",
    cls="hello",
    some_invalid_tag="hello",
    onclick="alert('Hello world');"
))

Strictdom

import strictdom.tags_1 as tags

print(tags.button("Hello world",
    class_="hello",
    # some_invalid_tag="hello",
    events=tags.Events(click="alert('Hello world');")
))

some_invalid_tag will raise a runtime error if not removed:

TypeError: __init__() got an unexpected keyword argument 'some_invalid_tag'

Usage

  • Install with sudo pip3 install strictdom --upgrade --no-cache-dir

  • Build from source with python3 make_1.py (requires html5spec) in a sibling directory and test with pytest.

TODO

  • Typechecked ARIA and Event Handlers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.