trim-template


Nametrim-template JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/opensourceame/trim-template
SummaryA templating engine inspired by Ruby's Slim template engine
upload_time2025-07-15 15:53:06
maintainerNone
docs_urlNone
authorDavid Kelly
requires_python>=3.12
licenseMIT
keywords template trim engine html
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Trim-Template

`trim-template` is an HTML templating engine for Python inspired by [Ruby's Slim template engine](https://github.com/slim-template/slim).
The objective behind Trim is to simplify template syntax to a minimal format that, like Python itself,
makes use of indentation to indicate how blocks of code should be interpreted.

#### Installation

`pip install trim-template`

#### Example Template


```slim
doctype strict

html
  head
    title My HTML title

    stylesheet src='/some.css'

    javascript:
      console.log('embedded JS inside the template');

  body
    css:
      .alert { color: 'red'; }

    .menu-bar
      - if user.logged_in
        img src={user.profile.image_path}
      - else
        a#login-button.btn.btn-primary href={login_path} Login

    .alert
      h1 {greeting}

    p.exciting This is the first ever Python Trim-Template

    h2#member-list Members

    form
      input type='checkbox' disabled=True checked=True

    p
      ul
        - for user in users
          li
            / code comment - show the user's names. This line will not render.
            span {user.first_name} {user.last_name}
    /! render the footer
    #footer Thanks for using Trim!
```

#### Rendered HTML

Trim-Template will render the above template into HTML, as below:

```html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
    <head>
        <title>My HTML title</title>

        <stylesheet src="/some.css"></stylesheet>

        <script type='javascript'>
            console.log('embedded JS inside the template');
        </script>
    </head>

    <body>
        <style>
          .alert { color: 'red'; }
        </style>

        <div class="menu-bar">
            <a class="btn btn-primary" href="/auth/login" id="login-button"/>Login</a>
        </div>

        <div class="alert">
            <h1>Hello World!</h1>
        </div>

        <p class="exciting">
            This is the first ever Python Trim-Template
        </p>

        <h2 id='member-list'>Members</h2>

        <form>
          <input type="checkbox" disabled="disabled" checked="checked"/>
        </form>

        <p>
            <ul>
                <li>
                    <span>Stephen Colber</span>
                </li>
                <li>
                    <span>Bob Marley</span>
                </li>
                <li>
                    <span>Charlie Chaplin</span>
                </li>
            </ul>
        </p>
        <!-- render the footer -->
        <div id='footer'>Thanks for using Trim!</div>
    </body>
</html>
```


### Using Trim


```
from trim_template.trim import TrimTemplate

tmpl = TrimTemplate("file.html.trim")
tmpl.set('login_path', '/auth/login')
tmpl.set('greeting', 'Hello World!')
tmpl.set('users', users)

output = tmpl.render()
print(output)
```

Where `file.html.trim` (also in the examples dir) contains the following.

## Options

| Option      | Values         | Description                                       |
|-------------|----------------|---------------------------------------------------|
| debug       | `all` / `tags` | debug output format when calling `tmpl.debug()`   |
| pretty      | True / False   | output pretty HTML                                |
| indentation | integer        | depth of indentation for debugging output         |

## Initialization parameters

`TrimTemplate` can be initialized with multiple parameters, the full set shown below:

```
tmpl = TrimTemplate('file.html.trim', pretty=True, debug='all', indent=4, vars={greeting: 'hello'})
```

### Syntax

See the [USAGE](USAGE.md) markdown file for details on trim syntax and other usage.

### Contributing

Contributions are welcome.  Fork the project and create a pull request.

### Authors

[David Kelly](https://github.com/opensourceame) created the project in Feb 2024

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/opensourceame/trim-template",
    "name": "trim-template",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "template, trim, engine, html",
    "author": "David Kelly",
    "author_email": "info@futuresbright.com",
    "download_url": "https://files.pythonhosted.org/packages/fb/a2/837bbaa2c46167acf0efedda96a91aaad3604dec1404fca5f2a5e5b198bf/trim_template-1.0.1.tar.gz",
    "platform": null,
    "description": "# Trim-Template\n\n`trim-template` is an HTML templating engine for Python inspired by [Ruby's Slim template engine](https://github.com/slim-template/slim).\nThe objective behind Trim is to simplify template syntax to a minimal format that, like Python itself,\nmakes use of indentation to indicate how blocks of code should be interpreted.\n\n#### Installation\n\n`pip install trim-template`\n\n#### Example Template\n\n\n```slim\ndoctype strict\n\nhtml\n  head\n    title My HTML title\n\n    stylesheet src='/some.css'\n\n    javascript:\n      console.log('embedded JS inside the template');\n\n  body\n    css:\n      .alert { color: 'red'; }\n\n    .menu-bar\n      - if user.logged_in\n        img src={user.profile.image_path}\n      - else\n        a#login-button.btn.btn-primary href={login_path} Login\n\n    .alert\n      h1 {greeting}\n\n    p.exciting This is the first ever Python Trim-Template\n\n    h2#member-list Members\n\n    form\n      input type='checkbox' disabled=True checked=True\n\n    p\n      ul\n        - for user in users\n          li\n            / code comment - show the user's names. This line will not render.\n            span {user.first_name} {user.last_name}\n    /! render the footer\n    #footer Thanks for using Trim!\n```\n\n#### Rendered HTML\n\nTrim-Template will render the above template into HTML, as below:\n\n```html\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n<html>\n    <head>\n        <title>My HTML title</title>\n\n        <stylesheet src=\"/some.css\"></stylesheet>\n\n        <script type='javascript'>\n            console.log('embedded JS inside the template');\n        </script>\n    </head>\n\n    <body>\n        <style>\n          .alert { color: 'red'; }\n        </style>\n\n        <div class=\"menu-bar\">\n            <a class=\"btn btn-primary\" href=\"/auth/login\" id=\"login-button\"/>Login</a>\n        </div>\n\n        <div class=\"alert\">\n            <h1>Hello World!</h1>\n        </div>\n\n        <p class=\"exciting\">\n            This is the first ever Python Trim-Template\n        </p>\n\n        <h2 id='member-list'>Members</h2>\n\n        <form>\n          <input type=\"checkbox\" disabled=\"disabled\" checked=\"checked\"/>\n        </form>\n\n        <p>\n            <ul>\n                <li>\n                    <span>Stephen Colber</span>\n                </li>\n                <li>\n                    <span>Bob Marley</span>\n                </li>\n                <li>\n                    <span>Charlie Chaplin</span>\n                </li>\n            </ul>\n        </p>\n        <!-- render the footer -->\n        <div id='footer'>Thanks for using Trim!</div>\n    </body>\n</html>\n```\n\n\n### Using Trim\n\n\n```\nfrom trim_template.trim import TrimTemplate\n\ntmpl = TrimTemplate(\"file.html.trim\")\ntmpl.set('login_path', '/auth/login')\ntmpl.set('greeting', 'Hello World!')\ntmpl.set('users', users)\n\noutput = tmpl.render()\nprint(output)\n```\n\nWhere `file.html.trim` (also in the examples dir) contains the following.\n\n## Options\n\n| Option      | Values         | Description                                       |\n|-------------|----------------|---------------------------------------------------|\n| debug       | `all` / `tags` | debug output format when calling `tmpl.debug()`   |\n| pretty      | True / False   | output pretty HTML                                |\n| indentation | integer        | depth of indentation for debugging output         |\n\n## Initialization parameters\n\n`TrimTemplate` can be initialized with multiple parameters, the full set shown below:\n\n```\ntmpl = TrimTemplate('file.html.trim', pretty=True, debug='all', indent=4, vars={greeting: 'hello'})\n```\n\n### Syntax\n\nSee the [USAGE](USAGE.md) markdown file for details on trim syntax and other usage.\n\n### Contributing\n\nContributions are welcome.  Fork the project and create a pull request.\n\n### Authors\n\n[David Kelly](https://github.com/opensourceame) created the project in Feb 2024\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A templating engine inspired by Ruby's Slim template engine",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/opensourceame/trim-template",
        "Issues": "https://github.com/opensourceame/trim-template/issues"
    },
    "split_keywords": [
        "template",
        " trim",
        " engine",
        " html"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eda1bc8c4201e68fcf5ba1ead874af8064247f518b0d1d8510ca24afd4584b8b",
                "md5": "1588bc822cdea9ac3149c1bc4df78380",
                "sha256": "005f686e0d47b9e1e6d9e537255bb20dbe657b41294ec3c00c630320f594cc25"
            },
            "downloads": -1,
            "filename": "trim_template-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1588bc822cdea9ac3149c1bc4df78380",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 7662,
            "upload_time": "2025-07-15T15:53:05",
            "upload_time_iso_8601": "2025-07-15T15:53:05.273904Z",
            "url": "https://files.pythonhosted.org/packages/ed/a1/bc8c4201e68fcf5ba1ead874af8064247f518b0d1d8510ca24afd4584b8b/trim_template-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fba2837bbaa2c46167acf0efedda96a91aaad3604dec1404fca5f2a5e5b198bf",
                "md5": "d5e6c0c5e7a43adc0e30e31131c239b6",
                "sha256": "cb78613dbbcb4b2a4f34019e50bb112f4532c80c7de48c9854900d3b7d8033ef"
            },
            "downloads": -1,
            "filename": "trim_template-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d5e6c0c5e7a43adc0e30e31131c239b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 6174,
            "upload_time": "2025-07-15T15:53:06",
            "upload_time_iso_8601": "2025-07-15T15:53:06.417434Z",
            "url": "https://files.pythonhosted.org/packages/fb/a2/837bbaa2c46167acf0efedda96a91aaad3604dec1404fca5f2a5e5b198bf/trim_template-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-15 15:53:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opensourceame",
    "github_project": "trim-template",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "trim-template"
}
        
Elapsed time: 1.11360s