Skip to main content

template language based on pug + coffeescript + stylus

Project description

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

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

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

Feature Sugar Compiles to
Element div: <div></div>
Class div.foo.bar: <div class="foo bar"></div>
Attribute a href=/about: <a href="/about"></a>
Text h1: Hello <h1>Hello</h1>
Inline element td: a href=#: Click <td><a href="#">Click</a></td>
Void element hr: <hr>
Comment # ignored (removed)
CSS property color: red color: red;
CSS selector .foo: .foo {
Function greet(x): function greet(x) {
Arrow (x): (x) => {
Inline arrow (x): x * 2 (x) => x * 2
For loop for x of arr: for (let x of arr) {
If if x > 0: if (x > 0) {
Class class Foo: class Foo {
Object indented key/values {key: value, ...}

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.

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

abstra_sugar-0.1.0a1.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abstra_sugar-0.1.0a1-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file abstra_sugar-0.1.0a1.tar.gz.

File metadata

  • Download URL: abstra_sugar-0.1.0a1.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for abstra_sugar-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 9c6be147602a40ee4fc469177cf82594e7f022a1f66b3014e215a63856f73a56
MD5 5aef56227177d255dcfccca92636f345
BLAKE2b-256 96452697659aab8a24ea3f1abc195581b232a254935fd5242b0cb29918881611

See more details on using hashes here.

File details

Details for the file abstra_sugar-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: abstra_sugar-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for abstra_sugar-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 d14e41a88b302ea080cf9f3ea12fd9d6ccf5c4a5e753c413e908a53058439bf5
MD5 6761cb02f5017c6673002417ec11750e
BLAKE2b-256 a402ca23f3fe745e755fddd28f387ab447a69b222c9328af786cbe9498f19bff

See more details on using hashes here.

Supported by

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