Catalog PyPI
PACKAGE EXPLORERView in registry

abstra-sugar

PyPI

template language based on pug + coffeescript + stylus

Versions collected1
Direct dependencies0From release 0.2.0a1
Last observed20 Oct, 17:44 UTC

README

Version 0.2.0a1 documentation

Sugar

A template language that compiles to HTML, CSS, and JavaScript. Combines the best ideas from Pug, Stylus, and CoffeeScript into a single indentation-based syntax.

Install

pip install abstra-sugar

Usage

from abstra_sugar import sugar

# static
html = sugar(open("page.sugar").read())

# with data (templating)
html = sugar(open("page.sugar").read(), {"users": [...], "title": "Home"})

Example

html:
    head:
        style:
            .title:
                color: #333
                font-size: 24px
    body:
        h1.title: Hello World
        p: Welcome to Sugar
        ul:
            li: Simple
            li: Fast
            li: Clean
        script:
            greet(name):
                console.log(`Hello, ${name}!`)
            greet("World")

Compiles to:

<html>
    <head>
        <style>
            .title {
                color: #333;
                font-size: 24px;
            }
        </style>
    </head>
    <body>
        <h1 class="title">Hello World</h1>
        <p>Welcome to Sugar</p>
        <ul>
            <li>Simple</li>
            <li>Fast</li>
            <li>Clean</li>
        </ul>
        <script>
            function greet(name) {
                console.log(`Hello, ${name}!`);
            }
            greet("World");
        </script>
    </body>
</html>

Syntax Overview

FeatureSugarCompiles to
Elementdiv:<div></div>
Implicit div.foo:<div class="foo"></div>
ID shorthand#main:<div id="main"></div>
Combinedcanvas#game.full:<canvas id="game" class="full"></canvas>
Classdiv.foo.bar:<div class="foo bar"></div>
Attributea href=/about:<a href="/about"></a>
Texth1: Hello<h1>Hello</h1>
Interpolationli: {user.name}<li>Alice</li> (with data)
Inline elementtd: a href=#: Click<td><a href="#">Click</a></td>
Void elementhr:<hr>
Comment# ignored(removed)
Template forfor x of arr:repeats children (with data)
Template ifif cond:conditional render (with data)
Implicit childul: > : Item<ul><li>Item</li></ul>
CSS propertycolor: redcolor: red;
CSS selector.foo:.foo {
JS functiongreet(x):function greet(x) {
JS arrow(x):(x) => {
JS inline arrow(x): x * 2(x) => x * 2
JS for loopfor x of arr:for (let x of arr) {
JS ifif x > 0:if (x > 0) {
JS classclass Foo:class Foo {
JS objectindented key/values{key: value, ...}
html! literalhtml!: + sugar`<div>...</div>`
Component defcard = (title):(reusable template)
Component callcard("Users"):(expands template)
Slotslot:(replaced by call children)
CSS mixin defreset = ():(reusable properties)
CSS mixin call@reset()(expands properties)

Documentation

See the docs folder for the full language reference.

Architecture

sugar(string) → string

    scan(code)    →  List[Token]      # lexer.py
    parse(tokens) →  List[Node]       # parser.py
    compile(nodes) → string           # compiler.py

License

MIT — see LICENSE.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.0a121 Mar 20260

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
abstra-app/sugar

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 17:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:d1bda084edad1d7eaba405b981a8ae19cba5e8800232d50ff0b1be8161fe59cc