pkglts.templating module

Set of functions to extend jinja2.

class pkglts.templating.Template[source]

Bases: object

Simple container that holds a list of blocks

The may objective is to represent a full templated file

add(block)[source]

Insert a new block in the overall template

Notes: will use block loc to position it.

Parameters:

block (TplBlock) – block with all fields filled

Returns:

None

parse(pth)[source]

Parse file and append all blocks into this template

Parameters:

pth (Path) – path to file to read

Returns:

None

render(cfg, tgt_pth)[source]

Render template into tgt_pth

Notes: keeps ‘preserved’ block structure

Parameters:
  • cfg (Config) – current package configuration

  • tgt_pth (Path) – path to potentially non existent yet target file

Returns:

key, cnt for preserved blocks

Return type:

(list of [str, str])

class pkglts.templating.TplBlock[source]

Bases: object

Simple container for template blocks.

pkglts_defined(bid, cnt)[source]

Create a block regenerated by pkglts.

Parameters:
  • bid (str) – id for this block (unique per file only)

  • cnt (str) – content

Returns:

None

user_defined(cnt)[source]

Make this block a user defined one.

Parameters:

cnt (str) – content

Returns:

None

pkglts.templating.parse_source(txt)[source]

Parse text to find preserved blocks

Parameters:

txt (str) – full text to parse

Returns:

ordered list of blocks:
  • block_id (or None if content is not preserved

  • line start before start for preserved content

  • content

  • line start before end for preserved content

Return type:

(list of [str, str, str, str])