API reference

class lina.CBooleanFormatter

Bases: lina.Formatter

For booleans, write true or false to the output. Otherwise, the input is just passed through.

Format(value)
class lina.DefaultFormatter(value)

Bases: lina.Formatter

Emit the default if the value is None, otherwise the value itself.

Format(text)
class lina.EscapeNewlineFormatter

Bases: lina.Formatter

Escape embedded newlines.

Format(text)
class lina.Formatter(formatterType)

Bases: builtins.object

Base class for all formatters.

A formatter can be used to transform blocks/values during expansion.

Format(text)

Format a value or a complete block.

IsBlockFormatter()
IsValueFormatter()
OnBlockBegin(isFirst)

Called before a block is expanded.

Parameters:isFirstTrue if this is the first expansion of the block.
Returns:String or None. If a string is returned, it is prepended before the current block expansion.
OnBlockEnd(isLast)

Called after a block has been expanded.

Parameters:isLastTrue if this is the last expansion of the block.
Returns:String or None. If a string is returned, it is appended after the current block expansion.
class lina.FormatterType

Bases: enum.Enum

The formatter type, either Block or Value.

lina.GetFormatter(name, value=None, position=None)

Get a formatter.

If the formatter cannot be found, an exception is raised.

class lina.HexFormatter

Bases: lina.Formatter

Write an integer as a hex literal (0x133F).

Format(value)
class lina.IncludeHandler

Bases: builtins.object

Base interface for include handlers.

Get(name)
class lina.IndentFormatter(depth)

Bases: lina.Formatter

Indent a block using tabs.

Format(block)
OnBlockBegin(isFirst)
exception lina.InvalidBlock(message, position)

Bases: lina.TemplateException

exception lina.InvalidFormatter(message, position)

Bases: lina.TemplateException

exception lina.InvalidToken(message, position)

Bases: lina.TemplateException

exception lina.InvalidWhitespaceToken(message, position)

Bases: lina.TemplateException

class lina.ListSeparatorFormatter(value)

Bases: lina.Formatter

Separate block entries.

This formatter will insert a value between block expansions.

OnBlockEnd(isLast)
class lina.PrefixFormatter(prefix)

Bases: lina.Formatter

Add a prefix to a value.

Format(text)
class lina.SuffixFormatter(suffix)

Bases: lina.Formatter

Add a suffix to a value.

Format(text)
class lina.Template(template, includeHandler=None)

Bases: builtins.object

The main template class.

Render(context)

Render the template using the provided context.

RenderSimple(**items)

Simple rendering function.

This is just a convenience function which creates the context from the passed items and forwards them to Template.Render().

exception lina.TemplateException(message, position)

Bases: builtins.Exception

GetPosition()

Get the position where the exception occured.

Returns:An object with two fields, line and column.
class lina.TemplateRepository(templateDirectory, suffix='')

Bases: lina.IncludeHandler

A file template repository.

This template repository will load files from a specified folder.

Get(name)
class lina.TextStream(text)

Bases: builtins.object

A read-only text stream.

The text stream is used for input only and keeps track of the current read pointer position in terms of line/column numbers.

Get()

Get a character.

If the end of the stream has been reached, None is returned.

GetOffset()
GetPosition()
IsAtEnd()

Check if the end of the stream has been reached.

Peek()

Peek at the next character in the stream if possible. Returns None if the end of the stream has been reached.

Reset()
Skip(length)

Skip a number of characters starting from the current position.

Substring(start, end)
Unget()

Move one character back in the input stream.

class lina.Token(name, start, end, position)

Bases: builtins.object

Represents a single token.

Each token may contain an optional list of flags, separated by colons. The grammar implemented here is:

[prefix]?[^:}]+(:[^:})+, for example:
{{#Foo}} -> name = Foo, prefix = #
{{Bar:width=8}} -> name = Bar, prefix = None,
                                        flags = {width:8}
EvaluateWhiteSpaceToken(position)
GetEnd()
GetFormatters()
GetName()
GetPosition()
GetStart()
IsBlockClose()
IsBlockStart()
IsIncludeToken()
IsSelfReference()
IsValue()
IsWhiteSpaceToken()
class lina.UppercaseFormatter

Bases: lina.Formatter

Format a value as uppercase.

Format(text)
class lina.WidthFormatter(width)

Bases: lina.Formatter

Align the value to a particular width.

Negative values align to the left (i.e., the padding is added on the left: '  42'), positive values to the right ('42  ').

Format(text)
class lina.WrapStringFormatter

Bases: lina.Formatter

Wrap strings with quotation marks.

Format(text)