Skip to main content

A simple static site generator based on Jinja2 with a CLI build using Click.

Project description

rost

A simple static site generator based on Jinja2 with a command line interface build using Click.

Installation

Use the following command to install rost:

$ python3 -m pip install rost

Living on the edge

If you want to work with the latest code before it’s released, install or update the code from the main branch:

$ python3 -m pip install -U git+https://github.com/Robert-96/rost.git

Quickstart

If you’re just looking to render simple data-less templates, you can get up and running with the command line:

$ rost build

This will recursively search ./templates for templates (any file whose name does not start with . or _) and build them to ./dist.

To monitor your source directory for changes, recompile files if they change, and start a webserver use watch:

$ rost watch

The build and watch each take these common options:

  • --searchpath: Sets the directory to look in for templates.
  • --outputpath: Sets the directory to place rendered files in.
  • --staticpath (is accepted multiple times): The directory (or directories) within searchpath where static files (such as CSS and JavaScript) are stored.

Getting help on version, available commands, arguments or option names:

$ rost --version
$ rost --help
$ rost build --help
$ rost watch --help

Advanced Usage

This part of the documentation covers some of rost’s more advanced features.

Using Custom Build Scripts

The command line shortcut is convenient, but sometimes your project needs something different than the defaults. To change them, you can use a build script.

A minimal build script looks something like this:

# build.py

from rost import build


if __name__ == "__main__":
    build(
        searchpath="templates",
        outputpath="dist",
        staticpaths=["static"]
    )

Finally, just save the script as build.py (or something similar) and run it with your Python3 interpreter.

$ python3 build.py

Loading Data

The simplest way to supply data to the template is to pass a mapping from variable names to their values (a “context”) as the context keyword argument to the build or watch functions.

# build.py

from rost import build


# A context that should be available all the time to all templates.
context = {
    "title": "Rost Example"
}


if __name__ == "__main__":
    build(
        searchpath="templates",
        outputpath="dist",
        staticpaths=["static"],
        context=context
    )

If you want to pass data to a specific template you can use the contexts keyword argument off the build and watch functions.

# build.py

from rost import build


# A context that should be available all the time to all templates.
context = {
    "title": "Rost Example"
}

# A list of "regex, context" pairs. Each context is either a dictionary or a
# function that takes either no argument or or the current template as its sole
# argument and returns a dictionary. The regex, if matched against a filename,
# will cause the context to be used.
contexts = [
    ("*.html", {}),
]


if __name__ == "__main__":
    build(
        searchpath="templates",
        outputpath="dist",
        staticpaths=["static"],
        context=context,
        contexts=contexts
    )

Custom Filters

Inside the templates variables can be modified by filters. All the standard Jinja2 filters are supported (you can found the full list here). To add your own filters, simply pass your as the filters keyword argument to the build and watch functions.

# build.py

from rost import build


filters = {
    "hello": lambda x: "Hello, {}!".format(x)
}


if __name__ == "__main__":
    build(
        searchpath="templates",
        outputpath="dist",
        staticpaths=["static"],
        filters=filters
    )

Then you can use them in your template as you would expect:

{{ 'World'|hello }}

License

This project is licensed under the MIT License.

Download files

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

Source Distribution

rost-0.1.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

rost-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rost-0.1.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0

File hashes

Hashes for rost-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f48ba06d3028452064d9d441c7cc9f9bdbd9b6753248f4f8d9208ba815beca54
MD5 149bbe11347bfa7ea6cfe12e19fd2417
BLAKE2b-256 061bd738ebbd6f0550c7d61dbd81b3ae2bd793f6ce9236d68eefdd636801b7aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rost-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0

File hashes

Hashes for rost-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e8749a5ada18721d893b7067c524b6454962934b2a096b3b9ed79ab715a56f6
MD5 877b2017c8b55a5e31d1c5ff5e39071f
BLAKE2b-256 6011152409fa6bc70abcf9ed2e8f40c49405b8d814c0e1911569f0c1b31498cd

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