gws.plugin.template.html

HTML template.

This module handles templates written in the Jump language. Apart from html, this template can generate pdf (for printing) and image outputs.

The arguments passed to a template can be accessed via the _ARGS object.

If a template explicitly returns a gws.Response object, the generated text is ignored and the object is returned as a render result. Otherwise, the result of the rendering will be a gws.ContentResponse object with the generated content.

This template supports the following extensions to Jump:

The @page command, which sets parameters for the printed page:

@page (
    width="<page width in mm>"
    height="<page height in mm>"
    margin="<page margins in mm>"
)

The @map command, which renders the current map:

@map (
    width="<width in mm>"
    height="<height in mm>"
    bbox="<optional, bounding box in projection units>"
    center="<optional, center coordinates in projection units>"
    scale="<optional, scale factor>"
    rotation="<optional, rotation in degrees>"

The @legend command, which renders the map legend:

@legend(
    layers="<optional, space separated list of layer UIDs>"
)

The @header and @footer block commands, which define headers and footers for multi-page printing:

@header
    content
@end header

@footer
    content
@end footer

Headers and footers are separate sub-templates, which receive the same arguments as the main template and two additional arguments:

  • numpages - the total number of pages in the document

  • page - the current page number

Source code: gws.plugin.template.html

Package Contents

class gws.plugin.template.html.Config(*args, **kwargs)

Bases: gws.base.template.Config

Object configuration.

path: gws.FilePath | None

path to a template file

text: str = ''

template content

class gws.plugin.template.html.Props(*args, **kwargs)

Bases: gws.base.template.Props

Object properties.

class gws.plugin.template.html.Object

Bases: gws.base.template.Object

Template object.

path: str
text: str
compiledTime: float = 0
compiledFn
configure()

Configuration hook.

render(tri)

Render the template and return the generated response.

compile(engine: Engine)
error_handler(exc, path, line, env)
render_map(tri: gws.TemplateRenderInput, width, height, index, bbox=None, center=None, scale=None, rotation=None)
render_legend(tri: gws.TemplateRenderInput, index, layers)
finalize(tri: gws.TemplateRenderInput, html: str, args: dict, main_engine: Engine)
finalize_pdf(tri: gws.TemplateRenderInput, html: str, args: dict, main_engine: Engine)
finalize_png(tri: gws.TemplateRenderInput, html: str, args: dict, main_engine: Engine)
decorate_html(html)
frame_template(header, footer, page_size)
class gws.plugin.template.html.Engine(template: Object, tri: gws.TemplateRenderInput | None = None)

Bases: gws.lib.vendor.jump.Engine

pageMargin: list[int] = []
pageSize: gws.UomSize = []
header: str = ''
footer: str = ''
def_page(**kw)
def_map(**kw)
def_legend(**kw)
mbox_header(text)